novacisko

Kondiciogram 1.3

Aug 27th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. //@version=3
  2. study("Kondiciogram")
  3. src = input(type=source, defval=close,title="Source")
  4. l = input(type=integer, minval=1, defval=160, step=10, title="Long interval")
  5. s = input(type=integer, minval=1, defval=16, title="Short interval")
  6. ofs=input(type=integer,defval=0, title="Prediction(+)/Delay(-}")
  7. dfs=0//input(type=integer,defval=0, title="Draw offset")
  8. tt = time
  9. td = change(tt,1)
  10. terr =0.0
  11. terr := nz(terr[1])+nz(change(td,l)/l-change(td,1))
  12. pred = ofs>0?ofs:0
  13. dly = ofs<0?-ofs:0
  14.  
  15. x = linreg(src, l-pred,0)+linreg(src,(l-pred)/2,0)+linreg(src,(l-pred)/4,0)
  16.  
  17. x0 = (pred>=0?linreg(x,s,-ofs):x[dly])/x
  18. a = (x0 - x[s-ofs]/x) * 100
  19. b = (x0 - 2*x[s-ofs]/x + x[2*s-ofs]/x) * 100
  20. c = (x0 - 3*x[s-ofs]/x + 3*x[2*s-ofs]/x - x[3*s-ofs]/x) * 100
  21. mid = c+b
  22.  
  23.  
  24. revers = (mid>0 and crossunder(mid[0],mid[1])) or (mid<0 and crossover(mid[0],mid[1]))
  25. 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
  26.  
  27. ldir = change(mid,1)
  28. curpl = (close[0] - close[1]) * (ldir[1]<0?-1:1)
  29.  
  30.  
  31.  
  32. plot(a, color=green, style=line, title="trend")
  33. plot(b, color=blue, style=stepline, linewidth=2, title="trend change")
  34. p1=plot(c, color=purple, style=stepline, linewidth=2, title="trend cycle")
  35. p2=plot(0, editable=false, transp=0)
  36. plot(ldir, color=black, style=area, title="local direction")
  37. plot(sma(curpl,l), color=#804000, title="average p&l")
  38. fill(p1,p2, color=col, transp=50)
  39. bgcolor(abs(terr)>1?orange:white, title="Time shift ERROR!",transp=50)
  40.  
  41. alertcondition(revers,title="Reversal!")
Advertisement
Add Comment
Please, Sign In to add comment