Im currently getting the no data error. Can someone please help me decipher the problem with my code?
//@version=5
strategy("My script",overlay=true)
ma60 = ta.sma(close,60)
price=close
_color = if ma60 > ma60[1]
color.green
else
color.red
plot(ma60,color = _color,linewidth = 2)
plot(ma200,color = color.orange, linewidth=3)
//long
if price>ma60 and price> ta.highest(20)
strategy.entry("longposition",strategy.long,comment="Long Entry")
if price<ma60
strategy.close("longposition",comment = "long Exit")
//short
if price<ma60 and price< ta.lowest(20)
strategy.entry("shortposition",strategy.short,comment="Long Entry")
if price<ma60
strategy.close("shortposition",comment = "long Exit")
//sl
strategy.exit("Exit long sl",from_entry = "longposition",stop=low )
strategy.exit("Exit short sl",from_entry = "shortposition",stop=high )
The strategy goes long when price crosses MA60 and close price was the highest price among the recent 20 bars and closes when price come back to MA60.`
ta.highest(20)
will count the current bar also and price> ta.highest(20)
can never be true
.
What you want to have is price> ta.highest(20)[1]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.