Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study("Kondiciogram")
- src = input(type=source, defval=close,title="Source")
- l = input(type=integer, minval=1, defval=160, step=10, title="Long interval")
- s = input(type=integer, minval=1, defval=16, title="Short interval")
- ofs=input(type=integer,defval=0, title="Prediction(+)/Delay(-}")
- dfs=0//input(type=integer,defval=0, title="Draw offset")
- tt = time
- td = change(tt,1)
- terr =0.0
- terr := nz(terr[1])+nz(change(td,l)/l-change(td,1))
- pred = ofs>0?ofs:0
- dly = ofs<0?-ofs:0
- x = linreg(src, l-pred,0)+linreg(src,(l-pred)/2,0)+linreg(src,(l-pred)/4,0)
- x0 = (pred>=0?linreg(x,s,-ofs):x[dly])/x
- a = (x0 - x[s-ofs]/x) * 100
- b = (x0 - 2*x[s-ofs]/x + x[2*s-ofs]/x) * 100
- c = (x0 - 3*x[s-ofs]/x + 3*x[2*s-ofs]/x - x[3*s-ofs]/x) * 100
- mid = c+b
- revers = (mid>0 and crossunder(mid[0],mid[1])) or (mid<0 and crossover(mid[0],mid[1]))
- col=revers?black:(change(mid,1)>0 and c < b and c < 0)?green:(change(c,1) < 0 and c > b and c > 0)?red:white
- ldir = change(mid,1)
- curpl = (close[0] - close[1]) * (ldir[1]<0?-1:1)
- plot(a, color=green, style=line, title="trend")
- plot(b, color=blue, style=stepline, linewidth=2, title="trend change")
- p1=plot(c, color=purple, style=stepline, linewidth=2, title="trend cycle")
- p2=plot(0, editable=false, transp=0)
- plot(ldir, color=black, style=area, title="local direction")
- plot(sma(curpl,l), color=#804000, title="average p&l")
- fill(p1,p2, color=col, transp=50)
- bgcolor(abs(terr)>1?orange:white, title="Time shift ERROR!",transp=50)
- alertcondition(revers,title="Reversal!")
Advertisement
Add Comment
Please, Sign In to add comment