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)

// Draggable input 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)
profitLineWidth = input.int(title="Profit Line Width", defval=1, minval=1, maxval=5)
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)
stopLossLineWidth = input.int(title="Stop Loss Line Width", defval=1, minval=1, maxval=5)
entryLineColor = input.color(title="Entry Line Color", defval=color.blue)
entryLineWidth = input.int(title="Entry Line Width", defval=1, minval=1, maxval=5)

// 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 + 1, y2=profitPrice, color=profitLineColor, width=profitLineWidth, style=profitStyle)
line.new(x1=bar_index - 1, y1=stopLossPrice, x2=bar_index + 1, y2=stopLossPrice, color=stopLossLineColor, width=stopLossLineWidth, style=stopLossStyle)
line.new(x1=bar_index - 1, y1=entryPrice, x2=bar_index + 1, y2=entryPrice, color=entryLineColor, width=entryLineWidth, 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)

// Add alerts for profit and stop loss levels
alertcondition(livePrice >= profitPrice, title="Profit Target Reached", message="The price has reached or exceeded the profit target.")
alertcondition(livePrice <= stopLossPrice, title="Stop Loss Triggered", message="The price has reached or dropped below the stop loss level.")
Bands and ChannelsCandlestick analysisChart patterns

Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?

Отказ от ответственности