Advertisement
Guest User

Volatility-Based Trailing Stop [LazyBear]

a guest
Sep 16th, 2014
9,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //
  2. // @author LazyBear
  3. // List of all my indicators:
  4. // https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
  5. //
  6. study(title="Volatility-Based Trailing Stop [LazyBear]", shorttitle="VBTS_LB", overlay=true)
  7. mult = input (3.0, title="ATR Multiplier")
  8. length = input(10, title="ATR Period")
  9. type=input(1, title="Style? (0 => HighLow, 1 => Close)")
  10. ticksize=input(1)
  11. uu=type == 1 ? close : high
  12. ll=type == 1 ? close : low
  13. satr=atr(length)
  14. svs = low+ceil(mult*satr/ticksize)*ticksize
  15. lvs =high-ceil(mult*satr/ticksize)*ticksize
  16.  
  17. shortvs=na(shortvs[1]) ? svs : iff(uu>shortvs[1], svs , min(svs,shortvs[1]))
  18. longvs=na(longvs[1]) ? lvs : iff(ll<longvs[1], lvs, max(lvs,longvs[1]))
  19.  
  20. longswitch=iff (uu>=shortvs[1] and uu[1]<shortvs[1] , 1 , 0)
  21. shortswitch=iff (ll<=longvs[1] and ll[1]>longvs[1] , 1 , 0)
  22.  
  23. direction= iff(na(direction[1]), 0,
  24. iff (direction[1]<=0 and longswitch, 1,
  25. iff (direction[1]>=0 and shortswitch, -1, direction[1])))
  26. pc=direction>0?longvs:shortvs
  27. plot(pc, color=direction>0?maroon:green, style=circles, linewidth=3)
  28. plot(pc, color=gray, linewidth=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement