Hi Syam, Pls help with this Log, why is this 1st and 4 row blank alert has been fired?
Also, pls take a look at entry,exit, sl and trailing sl triggers.
| Alert ID |
Ticker |
Name |
Description |
Time |
| 2517406004 |
NSE:NIFTY, 5m |
|
|
2025-06-24T08:00:06Z |
| 2517406004 |
NSE:NIFTY, 5m |
|
{“secret”:“sUmtC”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:“B”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“NIFTY”,“instrument”:“OPT”,“productType”:“I”,“sort_order”:“1”,“price”:“0”,“option_type”:“PE”,“strike_price”:“25100.0”,“expiry_date”:“2025-06-26”}]} |
2025-06-24T08:00:03Z |
| 2517406004 |
NSE:NIFTY, 5m |
|
{“secret”:“sUmtC”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:“S”,“orderType”:“MKT”,“quantity”:“1”,“exchange”:“NSE”,“symbol”:“NIFTY”,“instrument”:“OPT”,“productType”:“I”,“sort_order”:“1”,“price”:“0”,“option_type”:“CE”,“strike_price”:“25100.0”,“expiry_date”:“2025-06-26”}]} |
2025-06-24T08:00:03Z |
| 2517406004 |
NSE:NIFTY, 5m |
|
|
2025-06-24T08:00:03Z |
Here is my code
//@version=6
strategy(“s12 1 min 24June EMA Crossover Strategy with Dhan Webhook + Toggle”, overlay=true, default_qty_type=strategy.cash, default_qty_value=100000)
// === GLOBAL TOGGLE ===
enableWebhook = input.bool(true, “Enable Webhook Alerts”, inline=“tog”, group=“Automation”)
// === Date Range ===
groupDate = “Date Range”
fromDate = input.time(timestamp(“2025-06-24 09:15 +0530”), “From Date”, group=groupDate)
toDate = input.time(timestamp(“2025-12-31 15:30 +0530”), “To Date”, group=groupDate)
inDateRange = time >= fromDate and time <= toDate
// === EMA 1m ===
group1m = “EMA Crossover (1m)”
ema1_tf = input.timeframe(“1”, “Timeframe”, group=group1m)
ema1_fast_len = input.int(3, “Fast EMA Length”, group=group1m)
ema1_slow_len = input.int(21, “Slow EMA Length”, group=group1m)
src1 = input.source(open, “Source”, group=group1m)
ema1_fast = request.security(syminfo.tickerid, ema1_tf, ta.ema(src1, ema1_fast_len))
ema1_slow = request.security(syminfo.tickerid, ema1_tf, ta.ema(src1, ema1_slow_len))
// === EMA 5m ===
group5m = “EMA Crossover (5m)”
ema5_tf = input.timeframe(“5”, “Timeframe”, group=group5m)
ema5_fast_len = input.int(3, “Fast EMA Length”, group=group5m)
ema5_slow_len = input.int(21, “Slow EMA Length”, group=group5m)
src5 = input.source(open, “Source”, group=group5m)
ema5_fast = request.security(syminfo.tickerid, ema5_tf, ta.ema(src5, ema5_fast_len))
ema5_slow = request.security(syminfo.tickerid, ema5_tf, ta.ema(src5, ema5_slow_len))
// === SL/TP ===
groupSLTP = “Exit / SL / TP Controls”
use_ema_exit = input.bool(true, “Use EMA Exit (else TP Exit)”, group=groupSLTP)
sl_pts = input.float(7.0, “Stop Loss (Pts)”, group=groupSLTP)
tp_pts = input.float(150.0, “Target Profit (Pts)”, group=groupSLTP)
trail_sl = input.float(9.0, “Trailing Stop (Pts)”, group=groupSLTP)
trail_offset = input.float(3.0, “Trailing Threshold (Pts)”, group=groupSLTP)
// === Entry/Exit Logic ===
long_entry = ema5_fast > ema5_slow and ema1_fast > ema1_slow
short_entry = ema5_fast < ema5_slow and ema1_fast < ema1_slow
long_exit = ema1_fast < ema1_slow
short_exit = ema1_fast > ema1_slow
// === Strike Offset ===
Strike_offset = input.float(-100, step=100, title=“Strike Offset”, group=group5m)
// === Strike Calculation ===
round_strike(x) => math.floor(x / 100) * 100
ce_strike = round_strike(close) - Strike_offset
pe_strike = round_strike(close) + Strike_offset
// === Weekly Expiry Auto-Detect ===
get_expiry_date() =>
d = dayofweek
curr = timestamp(“GMT+5:30”, year, month, dayofmonth, 0, 0)
exp_day = d <= dayofweek.wednesday ? curr + (dayofweek.thursday - d) * 86400000 : curr + (7 - d + dayofweek.thursday) * 86400000
year_str = str.tostring(year(exp_day))
month_str = str.tostring(month(exp_day), “00”)
day_str = str.tostring(dayofmonth(exp_day), “00”)
year_str + “-” + month_str + “-” + day_str
expiry_dt = get_expiry_date()
// === Quantity & Dhan JSON ===
lot_size = 1
qty = lot_size
dhan_json(tx, symbol, qty, opt_type, strike, expiry) =>
‘{“secret”:“sUmtC”,“alertType”:“multi_leg_order”,“order_legs”:[{“transactionType”:"’ + (tx == “BUY” ? “B” : “S”) + ‘“,“orderType”:“MKT”,“quantity”:”’ + str.tostring(qty) + ‘“,“exchange”:“NSE”,“symbol”:”’ + symbol + ‘“,“instrument”:“OPT”,“productType”:“I”,“sort_order”:“1”,“price”:“0”,“option_type”:”’ + opt_type + ‘“,“strike_price”:”’ + str.tostring(strike, “#.0”) + ‘“,“expiry_date”:”’ + expiry + ‘"}]}’
send_alert(tx, opt_type, strike) =>
if enableWebhook
alert(dhan_json(tx, “NIFTY”, qty, opt_type, strike, expiry_dt), alert.freq_once_per_bar)
// === Strategy & Alerts ===
if long_entry and inDateRange
strategy.entry(“Long”, strategy.long)
send_alert(“BUY”, “CE”, ce_strike)
if short_entry and inDateRange
strategy.entry(“Short”, strategy.short)
send_alert(“BUY”, “PE”, pe_strike)
if use_ema_exit and inDateRange
if long_exit
strategy.close(“Long”, comment=“EMA Exit”)
send_alert(“SELL”, “CE”, ce_strike)
if short_exit
strategy.close(“Short”, comment=“EMA Exit”)
send_alert(“SELL”, “PE”, pe_strike)
if not use_ema_exit and inDateRange
tp_long = strategy.position_avg_price + tp_pts
tp_short = strategy.position_avg_price - tp_pts
strategy.exit(“TP Long”, from_entry=“Long”, limit=tp_long)
strategy.exit(“TP Short”, from_entry=“Short”, limit=tp_short)
if close >= tp_long
send_alert(“SELL”, “CE”, ce_strike)
if close <= tp_short
send_alert(“SELL”, “PE”, pe_strike)
if inDateRange
sl_long = strategy.position_avg_price - sl_pts
sl_short = strategy.position_avg_price + sl_pts
strategy.exit(“SL/Trail Long”, from_entry=“Long”, stop=sl_long, trail_points=trail_sl, trail_offset=trail_offset)
strategy.exit(“SL/Trail Short”, from_entry=“Short”, stop=sl_short, trail_points=trail_sl, trail_offset=trail_offset)
if close <= sl_long
send_alert(“SELL”, “CE”, ce_strike)
if close >= sl_short
send_alert(“SELL”, “PE”, pe_strike)