OPEN-SOURCE SCRIPT

Entry Price % Difference

ที่อัปเดต:
//version=5
indicator("Entry Price % Difference", overlay=true)

// User input for entry price
entryPrice = input.float(title="Entry Price", defval=100.0, step=0.1)

// User inputs for profit and stop loss levels
profitLevel = input.float(title="Profit Level (%)", defval=10.0, step=0.1)
stopLossLevel = input.float(title="Stop Loss Level (%)", defval=-10.0, step=0.1)

// User input for USDT amount in the trade
usdtAmount = input.float(title="USDT Amount", defval=1000.0, step=1.0)

// User input for trade type (Long or Short)
tradeType = input.string(title="Trade Type", defval="Long", options=["Long", "Short"])

// User input for line styles and colors
profitLineStyle = input.string(title="Profit Line Style", defval="Dotted", options=["Solid", "Dotted", "Dashed"])
profitLineColor = input.color(title="Profit Line Color", defval=color.green)
stopLossLineStyle = input.string(title="Stop Loss Line Style", defval="Dotted", options=["Solid", "Dotted", "Dashed"])
stopLossLineColor = input.color(title="Stop Loss Line Color", defval=color.red)

// User input for fee percentage
feePercentage = input.float(title="Fee Percentage (%)", defval=0.1, step=0.01)

// Map line styles
profitStyle = profitLineStyle == "Solid" ? line.style_solid : profitLineStyle == "Dotted" ? line.style_dotted : line.style_dashed
stopLossStyle = stopLossLineStyle == "Solid" ? line.style_solid : stopLossLineStyle == "Dotted" ? line.style_dotted : line.style_dashed

// Calculate percentage difference
livePrice = close
percentDifference = tradeType == "Long" ? ((livePrice - entryPrice) / entryPrice) * 100 : ((entryPrice - livePrice) / entryPrice) * 100

// Calculate profit or loss
profitOrLoss = usdtAmount * (percentDifference / 100)

// Calculate fees and net profit or loss
feeAmount = usdtAmount * (feePercentage / 100)
netProfitOrLoss = profitOrLoss - feeAmount

// Display percentage difference, profit/loss, and fees as a single label following the current price
if bar_index == last_bar_index
labelColor = percentDifference >= 0 ? color.new(color.green, 80) : color.new(color.red, 80)
var label plLabel = na
if na(plLabel)
plLabel := label.new(bar_index + 1, livePrice + (livePrice * 0.005), str.tostring(percentDifference, "0.00") + "%\n" + "P/L: " + str.tostring(netProfitOrLoss, "0.00") + " USDT (Fee: " + str.tostring(feeAmount, "0.00") + ")",
style=label.style_label_down, color=labelColor, textcolor=color.white)
else
label.set_xy(plLabel, bar_index + 1, livePrice + (livePrice * 0.005))
label.set_text(plLabel, str.tostring(percentDifference, "0.00") + "%\n" + "P/L: " + str.tostring(netProfitOrLoss, "0.00") + " USDT (Fee: " + str.tostring(feeAmount, "0.00") + ")")
label.set_color(plLabel, labelColor)

// Calculate profit and stop loss levels
profitPrice = entryPrice * (1 + profitLevel / 100)
stopLossPrice = entryPrice * (1 + stopLossLevel / 100)

// Plot profit, stop loss, and entry price lines
line.new(x1=bar_index[1], y1=profitPrice, x2=bar_index, y2=profitPrice, color=profitLineColor, width=1, style=profitStyle)
line.new(x1=bar_index[1], y1=stopLossPrice, x2=bar_index, y2=stopLossPrice, color=stopLossLineColor, width=1, style=stopLossStyle)
line.new(x1=bar_index[1], y1=entryPrice, x2=bar_index, y2=entryPrice, color=color.blue, width=1, style=line.style_solid)

// Show percentage difference in the price scale
plot(percentDifference, title="% Difference on Price Scale", color=color.new(color.blue, 0), linewidth=0, display=display.price_scale)
เอกสารเผยแพร่
//version=5
indicator("Entry Price % Difference", overlay=true)

// User input for entry price
entryPrice = input.float(title="Entry Price", defval=100.0, step=0.1)

// User inputs for profit and stop loss levels
profitLevel = input.float(title="Profit Level (%)", defval=10.0, step=0.1)
stopLossLevel = input.float(title="Stop Loss Level (%)", defval=-10.0, step=0.1)

// User input for USDT amount in the trade
usdtAmount = input.float(title="USDT Amount", defval=1000.0, step=1.0)

// User input for trade type (Long or Short)
tradeType = input.string(title="Trade Type", defval="Long", options=["Long", "Short"])

// User input for line styles and colors
profitLineStyle = input.string(title="Profit Line Style", defval="Dotted", options=["Solid", "Dotted", "Dashed"])
profitLineColor = input.color(title="Profit Line Color", defval=color.green)
stopLossLineStyle = input.string(title="Stop Loss Line Style", defval="Dotted", options=["Solid", "Dotted", "Dashed"])
stopLossLineColor = input.color(title="Stop Loss Line Color", defval=color.red)

// User input for fee percentage
feePercentage = input.float(title="Fee Percentage (%)", defval=0.1, step=0.01)

// Map line styles
profitStyle = profitLineStyle == "Solid" ? line.style_solid : profitLineStyle == "Dotted" ? line.style_dotted : line.style_dashed
stopLossStyle = stopLossLineStyle == "Solid" ? line.style_solid : stopLossLineStyle == "Dotted" ? line.style_dotted : line.style_dashed

// Calculate percentage difference
livePrice = close
percentDifference = tradeType == "Long" ? ((livePrice - entryPrice) / entryPrice) * 100 : ((entryPrice - livePrice) / entryPrice) * 100

// Calculate profit or loss
profitOrLoss = usdtAmount * (percentDifference / 100)

// Calculate fees and net profit or loss
feeAmount = usdtAmount * (feePercentage / 100)
netProfitOrLoss = profitOrLoss - feeAmount

// Display percentage difference, profit/loss, and fees as a single label following the current price
if bar_index == last_bar_index
labelColor = percentDifference >= 0 ? color.new(color.green, 80) : color.new(color.red, 80)
var label plLabel = na
if na(plLabel)
plLabel := label.new(bar_index + 1, livePrice + (livePrice * 0.005), str.tostring(percentDifference, "0.00") + "%\n" + "P/L: " + str.tostring(netProfitOrLoss, "0.00") + " USDT (Fee: " + str.tostring(feeAmount, "0.00") + ")",
style=label.style_label_down, color=labelColor, textcolor=color.white)
else
label.set_xy(plLabel, bar_index + 1, livePrice + (livePrice * 0.005))
label.set_text(plLabel, str.tostring(percentDifference, "0.00") + "%\n" + "P/L: " + str.tostring(netProfitOrLoss, "0.00") + " USDT (Fee: " + str.tostring(feeAmount, "0.00") + ")")
label.set_color(plLabel, labelColor)

// Calculate profit and stop loss levels based on trade type
profitPrice = tradeType == "Long" ? entryPrice * (1 + profitLevel / 100) : entryPrice * (1 - profitLevel / 100)
stopLossPrice = tradeType == "Long" ? entryPrice * (1 + stopLossLevel / 100) : entryPrice * (1 - stopLossLevel / 100)

// Plot profit, stop loss, and entry price lines
line.new(x1=bar_index[1], y1=profitPrice, x2=bar_index, y2=profitPrice, color=profitLineColor, width=1, style=profitStyle)
line.new(x1=bar_index[1], y1=stopLossPrice, x2=bar_index, y2=stopLossPrice, color=stopLossLineColor, width=1, style=stopLossStyle)
line.new(x1=bar_index[1], y1=entryPrice, x2=bar_index, y2=entryPrice, color=color.blue, width=1, style=line.style_solid)

// Show percentage difference in the price scale
plot(percentDifference, title="% Difference on Price Scale", color=color.new(color.blue, 0), linewidth=0, display=display.price_scale)
Bands and ChannelsChart patternsCycles

สคริปต์โอเพนซอร์ซ

ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถเข้าใจและตรวจสอบได้ ต้องขอบคุณผู้เขียน! ที่ให้คุณใช้ได้ฟรี แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?

คำจำกัดสิทธิ์ความรับผิดชอบ