微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

v2 到 v4,heikin ashi ema

如何解决v2 到 v4,heikin ashi ema

我正在尝试将此 v2 脚本转换为 v4,以便我可以添加更多内容,但我似乎无法像 v2 脚本那样复制移动的 heikin ashi 行。我做的一切都一样,所以我不确定问题是什么。

我尝试更改班次并查看参考资料,但我无法弄清楚我做错了什么。请帮忙

v2 代码

//@version=2
//Heikin Ashi F1

strategy("Heikin Ashi F1",shorttitle="HAS F1",overlay=true,default_qty_value=50,initial_capital=100,currency=currency.USD)
res = input(title="Heikin Ashi Candle Time Frame",type=resolution,defval="5")
hshift = input(2,title="Heikin Ashi Candle Time Frame Shift")
res1 = input(title="Heikin Ashi EMA Time Frame",defval="45")
mhshift = input(0,title="Heikin Ashi EMA Time Frame Shift")
fama = input(1,"Heikin Ashi EMA Period")
test = input(0,"Heikin Ashi EMA Shift")
sloma = input(40,"Slow EMA Period")
slomas = input(0,"Slow EMA Shift")
macdf = input(false,title="With MACD filter")
res2 = input(title="MACD Time Frame",defval="15")
macds = input(0,title="MACD Shift")




//Heikin Ashi Open/Close Price
ha_t = heikinashi(tickerid)
ha_open = security(ha_t,res,open[hshift])
ha_close = security(ha_t,close[hshift])
mha_close = security(ha_t,res1,close[mhshift])

//macd
[macdLine,signalLine,histLine] = macd(close,12,26,9)
macdl = security(ha_t,res2,macdLine[macds])
macdsl= security(ha_t,signalLine[macds])

//Moving Average
//THE PROBLEM IS FMA
fma = ema(mha_close[test],fama)
sma = ema(ha_close[slomas],sloma)
plot(fma,title="MA",color=lime,linewidth=2,style=line)
plot(sma,title="SMA",color=red,style=line)



//Strategy
Golong =  crossover(fma,sma) and (macdl > macdsl or macdf == false )
goshort =   crossunder(fma,sma) and (macdl < macdsl or macdf == false )

strategy.entry("Buy",strategy.long,when = Golong)
strategy.entry("Sell",strategy.short,when = goshort)
// strategy.exit("ExitLong","Buy",limit = close+atr)
// strategy.exit("ExitShort","Sell",limit = close - at)

v4 代码

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © zainali282000

//@version=4
strategy("HAF1v4",currency=currency.USD,default_qty_type = strategy.percent_of_equity,default_qty_value = 25,commission_type = strategy.commission.percent,commission_value = 0.04,margin_long = 4,margin_short = 4)

//Get Heikin Ashi Data
res = input(title="Heikin Ashi Candle Time Frame",type=input.resolution,defval="")
hshift = input(2,title="MACD Shift")

//Heikin Ashi Open/Close Price
ha_t = heikinashi(syminfo.tickerid)
ha_open = security(ha_t,close[mhshift])

//Moving Average
//THE PROBLEM IS FMA
fma = ema(mha_close[test],color=color.blue,linewidth=2)
plot(sma,color=color.black,linewidth=2)

//strategy
Golong =  crossover(fma,sma)
goshort =   crossunder(fma,sma)

strategy.entry("Buy",when = goshort)

解决方法

security 调用中的问题。对于 v2 security(ha_t,res,open[hshift]),v4 的等效项是 security(ha_t,open[hshift],lookahead=barmerge.lookahead_on)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。