Advertisement
JustUncleL

BB Script

Oct 22nd, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. //@version=3
  2. study("BB Script", overlay=true)
  3.  
  4. // Bollinger Bands Inputs
  5. AnchorTF = input(0, minval=0, title="Alternate Bollinger Time Frame in mins (0=currentTF, 1440=D, 7200=W)")
  6. BBlen = input(20, minval=0, title="Bollinger Length")
  7. BBmult = input(2.0, title="StdDev Multiplier", minval=0.5, maxval=10, step=0.1)
  8. BBsource = input(close, title="Bollinger Source")
  9.  
  10. // function to caculate multiplier from anchor time frame (TF is in mins)
  11. multAnchor(anchor) =>
  12. mult = 1
  13. if isintraday
  14. mult := anchor>0 ? (interval<=0 ? 1 : interval>=anchor? 1 : round(anchor/interval)) : 1
  15. else
  16. mult := anchor>0 ? isdaily ? (anchor<=1440 ? 1 : round(anchor/1440)) :
  17. isweekly ? (anchor<=7200 ? 1 : round(anchor/7200)) :
  18. ismonthly ? (anchor<=30240 ? 1 : round(anchor/30240)) : 1 : 1
  19. //end if
  20. mult
  21.  
  22. // get multipliers for each time frame
  23. mult = multAnchor(AnchorTF)
  24.  
  25. // Centre of Bollinger
  26. BBbase = sma(BBsource, BBlen*mult)
  27.  
  28. // Deviation
  29. BBdev = stdev(BBsource, BBlen*mult)
  30.  
  31. // Upper bands
  32. BBupper = BBbase + BBmult * BBdev
  33. BBlower = BBbase - BBmult * BBdev
  34.  
  35. plot(BBbase)
  36. plot(BBupper)
  37. plot(BBlower)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement