//@version=5
strategy("Supertrend Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
var bool tradeCompleted = false
atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)
[st, direction] = ta.supertrend(factor, atrPeriod)
buy = ta.change(direction) < 0
sell = ta.change(direction) > 0
short = sell
cover = buy
buyjson ='{"secret":"8IVNO","alertType":"multi_leg_order","order_legs":[{"transactionType":"B","orderType":"MKT","quantity":"1","exchange":"MCX","symbol":"GOLDPETAL1!","instrument":"FUT","productType":"M","sort_order":"1","price":"0"}]}'
shortjson ='{"secret":"8IVNO","alertType":"multi_leg_order","order_legs":[{"transactionType":"S","orderType":"MKT","quantity":"1","exchange":"MCX","symbol":"GOLDPETAL1!","instrument":"FUT","productType":"M","sort_order":"1","price":"0"}]}'
if (not tradeCompleted)
if (strategy.position_size == 0)
if (buy)
strategy.order("buy", strategy.long, alert_message = buyjson)
if (short)
strategy.order("short", strategy.short, alert_message = shortjson)
if (strategy.position_size > 0)
if (sell)
strategy.order("sell", strategy.short, alert_message = shortjson)
tradeCompleted := true
if (buy)
strategy.order("cover", strategy.long, alert_message = buyjson)
tradeCompleted := true
plot(st, color = direction == -1 ? color.green : color.red)
@t7support
Sir I have modified the code for one time execution
var bool tradeCompleted = false
entering the trade when
if (not tradeCompleted)
just before exit making it true
I will check on live trading day
Is it Okey Sir ?