OPEN-SOURCE SCRIPT

27 ALERT INFY EQ | Manual JSON Only

102
//version=6
indicator("27 ALERT INFY EQ | Manual JSON Only", overlay=true)

//────────────────────────────────────────────
// 🔧 USER INPUTS
//────────────────────────────────────────────
symbol_name = input.string("INFY", "Equity Symbol (for labels only)")
tradeMode = input.string("Intraday", "Trade Mode (for dashboard)", options=["Intraday","Delivery"])

// Paste your exact Dhan payloads below (must be single-line strings)
json_buy = input.string('{"secret":"hWMIU","alertType":"multi_leg_order","order_legs":[{"transactionType":"B","orderType":"MKT","quantity":"1","exchange":"NSE","symbol":"INFY","instrument":"EQ","productType":"I","sort_order":"1","price":"0"}]}', "BUY JSON Script")
json_sell = input.string('{"secret":"hWMIU","alertType":"multi_leg_order","order_legs":[{"transactionType":"S","orderType":"MKT","quantity":"1","exchange":"NSE","symbol":"INFY","instrument":"EQ","productType":"I","sort_order":"1","price":"0"}]}', "SELL JSON Script")

//────────────────────────────────────────────
// 📊 SIGNAL LOGIC (Heikin Ashi + MACD)
//────────────────────────────────────────────
ha_close = (open + high + low + close) / 4.0
var float ha_open = na
ha_open := na(ha_open[1]) ? (open + close)/2.0 : (ha_open[1] + ha_close[1])/2.0
isBull = ha_close > ha_open
isBear = ha_close < ha_open

[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
macdBull = macdLine > signalLine
macdBear = macdLine < signalLine

//────────────────────────────────────────────
// 🚀 ENTRY / EXIT (One-Candle Confirmation)
//────────────────────────────────────────────
var bool inTrade = false
var string lastEvent = "Waiting..."

buyCondition = isBull and macdBull and not inTrade
sellCondition = isBear and macdBear and inTrade

if buyCondition
inTrade := true
lastEvent := "BUY"
label.new(bar_index, low, "🟢 BUY " + symbol_name, style=label.style_label_up, color=color.new(color.green, 0))
alert(json_buy, alert.freq_once_per_bar_close)

if sellCondition
inTrade := false
lastEvent := "SELL"
label.new(bar_index, high, "🔴 SELL " + symbol_name, style=label.style_label_down, color=color.new(color.red, 0))
alert(json_sell, alert.freq_once_per_bar_close)

//────────────────────────────────────────────
// 🧭 DASHBOARD
//────────────────────────────────────────────
var table dash = table.new(position.top_right, 2, 6, border_width=1)
if barstate.isfirst
table.cell(dash, 0, 0, "📊 " + symbol_name + " EQ", bgcolor=color.new(color.black, 60), text_color=color.white)
table.cell(dash, 0, 1, "Symbol")
table.cell(dash, 0, 2, "Position")
table.cell(dash, 0, 3, "Trend")
table.cell(dash, 0, 4, "Mode")
table.cell(dash, 0, 5, "Alert Type")

trendTxt = isBull ? "BULLISH" : isBear ? "BEARISH" : "NEUTRAL"
if barstate.islast
table.cell(dash, 1, 1, symbol_name)
table.cell(dash, 1, 2, inTrade ? "LONG" : "FLAT")
table.cell(dash, 1, 3, trendTxt)
table.cell(dash, 1, 4, tradeMode)
table.cell(dash, 1, 5, "MANUAL JSON")

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.