novacisko

Test Strategie

Sep 3rd, 2018
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. //@version=3
  2. study("Test strategie")
  3. src=input(type=source,title="Zdroj dat",defval=close)
  4. chint=input(type=integer,title="Zmena za (0=vyp)", defval=0,minval=0)
  5. ofs=input(type=float, title="Posun 0 na ose Y", defval=0)
  6. neg=input(type=bool, title="Negovat", defval=false)
  7. avgint=input(type=integer,title="interval mereni", defval=84,minval=1)
  8. fees=input(type=float,title="Poplatky na burze v %", defval=0.08, step=0.02)
  9. hyst=input(type=float,title="hystereze", defval=0)
  10. delay=input(type=integer,title="zpozdeni (0=vidi budoucnost)", defval=1, minval=0)
  11. dir=input(title="Směr", options=["long+short","short","long"], defval="long+short")
  12. size=input(title="Velikost pozice", type=float, defval=1, minval=0)
  13. vcurrency=input(title="Velikost v currency", type=bool, defval=false)
  14. close0=input(type=bool, title="Zavrit na nule", defval=false)
  15. accumhyst=input(type=bool, title="Akumulovat prirusty pri hysterezi",defval=false)
  16. plot_alltime=input(type=bool, title="Kresli alltime vynos a fee", defval=false)
  17. plot_alltime_abs=input(type=bool, title="Kresli alltime absol. vynos", defval=false)
  18.  
  19. pos=0.0
  20. accv=0.0
  21. mult=(neg?-1:1)
  22. plong = dir == "short"?0:size/(vcurrency?open[0]:1)
  23. pshort = dir == "long"?0:-size/(vcurrency?open[0]:1)
  24. chint2=chint==0?1:chint
  25. ost=(chint==0?src[delay]:change(src[delay],chint2))*mult-ofs
  26. accv:=accumhyst and ((ost < 0 and pos[1] >= 0) or (ost > 0 and pos[1] <= 0)) and (abs(nz(accv[1]))<abs(hyst))?(nz(accv[1])+ost):ost
  27. pos:=(crossover(accv, hyst)?plong:crossunder(accv,-hyst)?pshort:close0?((cross(ost,0) or ost == 0)?0:nz(pos[1])):nz(pos[1]))
  28. bgcolor(title="position", color=pos<0?#FF0000:pos>0?#00FF00:#808080,transp=85)
  29.  
  30. vynosy=(close[0]-close[1])*pos
  31. vol=abs(pos[0]-pos[1])*open
  32. avgpl=sma(vynosy,avgint)
  33. avgvol=sma(vol,avgint)
  34. plot(avgpl,title="Prumerny vynos", color=blue, linewidth=2)
  35. plot(avgvol*fees/100,title="Prumerne poplatky", color=blue, style=area, transp=80)
  36.  
  37. atsum=0.0
  38. atcnt=0
  39. atvol=0.0
  40. atsum:=nz(atsum[1])+vynosy
  41. atcnt:=plot_alltime?(nz(atcnt[1])+1):na
  42. atvol:=nz(atvol[1])+vol
  43.  
  44. plot(atsum/atcnt,title="Celkovy prumerny vynos", color=#804000,linewidth=2)
  45. plot(atvol/atcnt*fees/100,title="Celkovy prumerny fee", color=#804000, style=area, transp=80)
  46. plot(plot_alltime_abs?atsum-atvol*fees/100:na,title="absolutni vynos", color=black)
  47.  
  48. alertcondition(pos!=pos[1],"Position changed")
  49. alertcondition(pos>0 and pos[1]!=pos,"Buy signal")
  50. alertcondition(pos<0 and pos[1]!=pos,"Sell signal")
  51. alertcondition(pos==0 and pos[1]!=pos,"Close signal")
Advertisement
Add Comment
Please, Sign In to add comment