簡體   English   中英

在 Trading View 中回測用 Pine Script 編寫的策略時出現“無數據”錯誤的原因是什么? 使用 MA60

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM