![](/img/trans.png)
[英]What is the cause of the “No Data” error when backtesting in Trading View a strategy written in Pine Script?
[英]What is the cause of the “No Data” error when backtesting in Trading View a strategy written in Pine Script? Using MA60
我目前收到無數據錯誤。 有人可以幫我破譯我的代碼的問題嗎?
//@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 )
該策略在價格穿越 MA60 且收盤價為最近 20 根柱線中的最高價時做多,並在價格回到 MA60 時收盤。
ta.highest(20)
也將計算當前柱線並且price> ta.highest(20)
永遠不可能為true
。
你想要的是price> ta.highest(20)[1]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.