簡體   English   中英

PineScript v2 到 v4

[英]PineScript v2 to v4

幾年前我編寫了這個 pinescript 代碼,對代碼知之甚少,我仍然沒有太多編碼知識,而且事情似乎已經更新,想知道是否有人可以幫助我將我的腳本更新到 pine 腳本版本的版本 4 或 5 . 提前致謝。

strategy("Heikin Strategy",shorttitle="HeikStrat",overlay=true,max_bars_back=50,default_qty_type=strategy.cash,initial_capital=100,currency=currency.USD)
res1 = input(title="Heikin Ashi EMA Time Frame", type=resolution, defval="D")
test = input(1,"Heikin Ashi EMA Shift")
sloma = input(20,"Slow EMA Period")

// MA (Kaufman)
Length = input(5, minval=1)
xPrice = input(hlc3)
xvnoise = abs(xPrice - xPrice[1])
Fastend = input(2.5,step=.5)
Slowend = input(20)
nfastend = 2/(Fastend + 1)
nslowend = 2/(Slowend + 1)
nsignal = abs(xPrice - xPrice[Length])
nnoise = sum(xvnoise, Length)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2) 
nAMA = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))

//Heikin Ashi Open and Close Price
ha_t = heikinashi(tickerid)
ha_close = security(ha_t, period, nAMA)
mha_close = security(ha_t, res1, hlc3)

//Moving Average
fma = ema(mha_close[test],1)
sma = ema(ha_close,sloma)
plot(fma,title="MA",color=yellow,linewidth=2,style=line)
plot(sma,title="SMA",color=red,linewidth=2,style=line)

//Strategy longs
golong =  crossover(fma,sma) 
longexit =   crossunder(fma,sma)

goshort = crossunder(fma,sma)
shortexit  = crossover(fma,sma)

strategy.entry("Buy",strategy.long,when = golong)
strategy.close("Buy",when = longexit)

strategy.entry("Sell", strategy.short, when = goshort)
strategy.close("Sell",when = shortexit)

在 Pine Script v4 中,不再可能在聲明時創建具有未知數據類型的變量。 您必須手動更改它。

您可以在此處閱讀轉換指南

所以如果v3是這樣的

nAMA = nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))

在 v4 中應該是這樣的

nAMA = 1.0
nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))

並注意在非標准圖表上進行回測(Heikin Ashi)

這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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