简体   繁体   中英

Strategy to study

I want to change a strategy to study to have the alert of the 2 last line. It's a buy and sell "signal".

Don't works. I don't know what i can remove without problem

study("Heikin Ashi Strategy [Krypt]", shorttitle="HA Strategy [Krypt]", overlay=true)

res = input(title="Heikin Ashi Candle Time Frame", type=resolution, defval="60")
hshift = input(1,title="Heikin Ashi Candle Time Frame Shift")
res1 = input(title="Heikin Ashi EMA Time Frame", type=resolution, defval="180")
mhshift = input(0,title="Heikin Ashi EMA Time Frame Shift")
fama = input(1,"Heikin Ashi EMA Period")
test = input(1,"Heikin Ashi EMA Shift")
sloma = input(30,"Slow EMA Period")
slomas = input(1,"Slow EMA Shift")
logtransform = input(false, "Log Transform")
stoploss = input(true, "Stop Loss")
showplots = input(true, "Show Plots")

ha_t = heikinashi(tickerid)
ha_close = security(ha_t, res, logtransform ? log(close[hshift]) : close[hshift])
mha_close = security(ha_t, res1, logtransform ? log(close[mhshift]) : close[mhshift])

fma = ema(mha_close[test], fama)
sma = ema(ha_close[slomas], sloma)

plot(showplots ? (logtransform ? exp(fma) : fma) : na, title="MA", color=#0094ff, linewidth=2, style=line)
plot(showplots ? (logtransform ? exp(sma) : sma) : na, title="SMA", color=#ff6a00, linewidth=2, style=line)

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

plot("Buy", strategy.long, when=golong, stop=(stoploss ? high+syminfo.mintick : na))
plot("Sell", strategy.short, when=goshort, stop=(stoploss ? low-syminfo.mintick : na))

Thanks for your help.

You can add alertcondition function on golong and goshort to get the alerts.

//@version=3
study("Heikin Ashi Strategy [Krypt]", shorttitle="HA Strategy [Krypt]", overlay=true)

res = input(title="Heikin Ashi Candle Time Frame", type=resolution, defval="60")
hshift = input(1,title="Heikin Ashi Candle Time Frame Shift")
res1 = input(title="Heikin Ashi EMA Time Frame", type=resolution, defval="180")
mhshift = input(0,title="Heikin Ashi EMA Time Frame Shift")
fama = input(1,"Heikin Ashi EMA Period")
test = input(1,"Heikin Ashi EMA Shift")
sloma = input(30,"Slow EMA Period")
slomas = input(1,"Slow EMA Shift")
logtransform = input(false, "Log Transform")
stoploss = input(true, "Stop Loss")
showplots = input(true, "Show Plots")

ha_t = heikinashi(tickerid)
ha_close = security(ha_t, res, logtransform ? log(close[hshift]) : close[hshift])
mha_close = security(ha_t, res1, logtransform ? log(close[mhshift]) : close[mhshift])

fma = ema(mha_close[test], fama)
sma = ema(ha_close[slomas], sloma)

plot(showplots ? (logtransform ? exp(fma) : fma) : na, title="MA", color=#0094ff, linewidth=2, style=line)
plot(showplots ? (logtransform ? exp(sma) : sma) : na, title="SMA", color=#ff6a00, linewidth=2, style=line)

golong = crossover(fma, sma)
goshort = crossunder(fma, sma)
plotshape(golong,style=shape.arrowup,location=location.belowbar,color=green,size=size.large)
plotshape(goshort,style=shape.arrowdown,location=location.abovebar,color=red,size=size.large)
alertcondition(golong,"Long","FMA SMA Crossover")
alertcondition(goshort,"Short","FMA SMA Crossunder")

Thanks for your help. There is a problem.

The long arrow come from your code and the small one with buy or sell is from the "original code"

I don't know why it's a difference like this.

信号差异 ?

Here the original code.

strategy("Heikin Ashi Strategy [Krypt]", shorttitle="HA Strategy [Krypt]", overlay=true)

res = input(title="Heikin Ashi Candle Time Frame", type=resolution, defval="60")
hshift = input(1,title="Heikin Ashi Candle Time Frame Shift")
res1 = input(title="Heikin Ashi EMA Time Frame", type=resolution, defval="180")
mhshift = input(0,title="Heikin Ashi EMA Time Frame Shift")
fama = input(1,"Heikin Ashi EMA Period")
test = input(1,"Heikin Ashi EMA Shift")
sloma = input(30,"Slow EMA Period")
slomas = input(1,"Slow EMA Shift")
logtransform = input(false, "Log Transform")
stoploss = input(true, "Stop Loss")
showplots = input(true, "Show Plots")

ha_t = heikinashi(tickerid)
ha_close = security(ha_t, res, logtransform ? log(close[hshift]) : close[hshift])
mha_close = security(ha_t, res1, logtransform ? log(close[mhshift]) : close[mhshift])

fma = ema(mha_close[test], fama)
sma = ema(ha_close[slomas], sloma)

plot(showplots ? (logtransform ? exp(fma) : fma) : na, title="MA", color=#0094ff, linewidth=2, style=line)
plot(showplots ? (logtransform ? exp(sma) : sma) : na, title="SMA", color=#ff6a00, linewidth=2, style=line)

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

strategy.entry("Buy", strategy.long, when=golong, stop=(stoploss ? high+syminfo.mintick : na))
strategy.entry("Sell", strategy.short, when=goshort, stop=(stoploss ? low-syminfo.mintick : na))

The strange think. The original code don't print the same signal (arrow and text) on the same chandel in 2 differents browser with the same crypto pair.

Thanks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM