Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study("BB Script", overlay=true)
- // Bollinger Bands Inputs
- AnchorTF = input(0, minval=0, title="Alternate Bollinger Time Frame in mins (0=currentTF, 1440=D, 7200=W)")
- BBlen = input(20, minval=0, title="Bollinger Length")
- BBmult = input(2.0, title="StdDev Multiplier", minval=0.5, maxval=10, step=0.1)
- BBsource = input(close, title="Bollinger Source")
- // function to caculate multiplier from anchor time frame (TF is in mins)
- multAnchor(anchor) =>
- mult = 1
- if isintraday
- mult := anchor>0 ? (interval<=0 ? 1 : interval>=anchor? 1 : round(anchor/interval)) : 1
- else
- mult := anchor>0 ? isdaily ? (anchor<=1440 ? 1 : round(anchor/1440)) :
- isweekly ? (anchor<=7200 ? 1 : round(anchor/7200)) :
- ismonthly ? (anchor<=30240 ? 1 : round(anchor/30240)) : 1 : 1
- //end if
- mult
- // get multipliers for each time frame
- mult = multAnchor(AnchorTF)
- // Centre of Bollinger
- BBbase = sma(BBsource, BBlen*mult)
- // Deviation
- BBdev = stdev(BBsource, BBlen*mult)
- // Upper bands
- BBupper = BBbase + BBmult * BBdev
- BBlower = BBbase - BBmult * BBdev
- plot(BBbase)
- plot(BBupper)
- plot(BBlower)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement