Code:
//@version=5
strategy("BTCTEST", overlay=true)
len = input(7)
nATRs = input(0.4)
atr = ta.sma(ta.tr, len)*nATRs
if (not na(close[len]))
strategy.entry("Long", strategy.long, stop=close+atr, comment = "Long")
strategy.entry("Short", strategy.short, stop=close-atr, comment = "Short")
This is my modify
//@version=5
indicator("BTCTEST", overlay=true)
len = input(7)
nATRs = input(0.4)
atr = ta.sma(ta.tr, len)*nATRs
//if (not na(close[len]))
//strategy.entry("Long", strategy.long, stop=close+atr, comment = "Long")
//strategy.entry("Short", strategy.short, stop=close-atr, comment = "Short")
ebuy = ???
esell = ???
plotshape(ebuy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)
plotshape(esell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)
alertcondition(ebuy, title='BUY', message='e=bitmex s=xbtusd delay=1 b=buy t=market q=100% d=1')
alertcondition(esell, title='SELL', message='e=bitmex s=xbtusd delay=1 b=sell t=market q=100% d=1')
i don't understand stop=close+atr
and stop=close-atr
, if (not na(close[len]))
How should I check long and short? I spent many hours for this. I hope someone can help me.