This indicator formats a label and builds a sample JSON message after ATR is available. The signal is a confirmed close crossing above its EMA; the BUY/SELL input only labels the message and does not implement a short-entry rule. It places no orders. Create a TradingView alert for alert() calls, then inspect the received payload against your receiver schema before enabling any execution.
Pine Script v6: Dynamic string conversion and JSON payload builderpinescript
//@version=6
indicator("String Formatting & Webhook Builder [v6]", overlay = true)
// Inputs
float stopMultiplier = input.float(1.5, "Stop ATR Multiplier", minval = 0.5)
string actionType = input.string("BUY", "Order Action", options = ["BUY", "SELL"])
// Calculations
float atrVal = ta.atr(14)
float stopPrice = actionType == "BUY" ? close - (atrVal * stopMultiplier) : close + (atrVal * stopMultiplier)
// Format numbers with tick precision
string priceStr = str.tostring(close, format.mintick)
string stopStr = str.tostring(stopPrice, format.mintick)
string timeStr = str.format_time(time, "yyyy-MM-dd HH:mm", "UTC")
// Construct multi-line on-chart dashboard text using str.format
string displayText = str.format(
"Status: {0}\nPrice: {1}\nStop: {2}\nTime: {3}",
actionType, priceStr, stopStr, timeStr)
// Render on-chart label on current bar
var label statusLabel = na
if barstate.islast
label.delete(statusLabel)
statusLabel := label.new(
bar_index, high, displayText,
color = color.navy, textcolor = color.white,
style = label.style_label_down)
// Escape the two JSON string metacharacters that can occur in a symbol.
string symbolJson = str.replace_all(str.replace_all(syminfo.tickerid, "\\", "\\\\"), '"', '\\"')
string jsonPayload = '{"action":"' + actionType + '","symbol":"' + symbolJson + '","price":' + priceStr + ',"stop":' + stopStr + ',"timestamp":"' + timeStr + '"}'
// A sample close-confirmed alert, not a complete trading system.
float ema20 = ta.ema(close, 20)
bool signal = ta.crossover(close, ema20)
if signal and barstate.isconfirmed and not na(atrVal)
alert(jsonPayload, alert.freq_once_per_bar_close)