Untitled

 avatar
unknown
plain_text
3 years ago
1.6 kB
12
Indexable
//@version=2
//Heikin/Kaufman

strategy("HLC3/Kaufman Strategy ",shorttitle="HLC3/KAU",overlay=true,max_bars_back=500,default_qty_value=1000,initial_capital=100000,currency=currency.EUR)
res1 = input(title="Hlc3 Time Frame", type=resolution, defval="D")
test = input(1,"Hlc3 Shift")
sloma = input(20,"Slow EMA Period")

//Kaufman MA
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/Close Price
//ha_t = heikinashi(tickerid)
//ha_close = security(ha_t, period, nAMA)
//mha_close = security(ha_t, res1, hlc3)
bha_close = security(tickerid, period, nAMA)
bmha_close = security(tickerid, res1, hlc3)

//Moving Average
//fma = ema(mha_close[test],1)
//sma = ema(ha_close,sloma)
//plot(fma,title="MA",color=black,linewidth=2,style=line)
//plot(sma,title="SMA",color=red,linewidth=2,style=line)
bfma = ema(bmha_close[test],1)
bsma = ema(bha_close,sloma)
plot(bfma,title="MA",color=black,linewidth=2,style=line)
plot(bsma,title="SMA",color=red,linewidth=2,style=line)
//Strategy
//golong =  crossover(fma,sma) 
//goshort =   crossunder(fma,sma)
golong =  crossover(bfma,bsma) 
goshort =   crossunder(bfma,bsma)
strategy.entry("Buy",strategy.long,when = golong)
strategy.entry("Sell",strategy.short,when = goshort)
Editor is loading...