Reputation: 65
I am trying to develop a strategy based on comparison between closing price difference between last two bars and Average True Range value of second last bar. My coding is as follows -
//@version=5
strategy(title="ATR Strategy", overlay=true, margin_long=100, margin_short=100)
atr = ta.atr(14)
v = atr[1]
a = close - close[1]
b = close[1] - close
longCondition = (close > close[1])
if (longCondition)
strategy.entry("LE", strategy.long, when = a > v)
shortCondition = (close < close[1])
if (shortCondition)
strategy.entry("SE", strategy.short, when = b > v)
But I am experiencing false entry points, mainly on 15 minute chart, particularly on short side. If there is a way to fix the issue, please let me know. Thanks for your time. Regards.
Upvotes: 0
Views: 90
Reputation: 1961
You can simplify your if
/when
statements and debug long/short condition by adding bgcolor:
//@version=5
strategy(title="ATR Strategy", overlay=true, margin_long=100, margin_short=100)
atr = ta.atr(14)
v = atr[1]
a = close - close[1]
b = close[1] - close
longCondition = (close > close[1]) and (a > v)
if (longCondition)
strategy.entry("LE", strategy.long)
shortCondition = (close < close[1]) and (b > v)
if (shortCondition)
strategy.entry("SE", strategy.short)
bgcolor(longCondition ? color.new(color.green, 80) : shortCondition ? color.new(color.red, 80) : na)
Upvotes: 1