Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //created by gamazama. send me a shout if u find this usefull.
- //usage: tradingview->pine editor->paste->add to chart
- // %BB: The price's position in the boilinger band is converted to a range from 0-1. The midpoint is at 0.5
- // Description of parameters
- // "BB:Window Length" is the standard BB size of 20 candles.
- // The indicator plots 7 different %BB's on different timescales
- // they are calculated independantly of the timescale if you are viewing eg 12h,3d, 30m the output will be the same
- // You can enter 7 timescales, eg. if you want to plot a range of bbands of the 12h up to 3d graphs, enter values between 0.5 and 3
- // take note if you double the main multiplier to 40, it is the same as doubling all your timescales
- // You can turn the transparency of the 7x%BB's to 100 to hide them, their average is plotted as a thick cyan line
- // the default values are optimized for a bear market
- //
- // "Variance" is a measure of how much the 7 BB's agree, and changes colour based on the thresholds used for the strategy
- //
- // Then there is a few standard settings:
- // "Source Smoothing Amount" applies a basic small sma on the price.
- // It should be turned down when viewing candles with less information, like 1D or more
- // Standard BBands use an SMA, here there is an option to use ALMA or VWMA or SMA
- // Standard Alma settings for when ALMA is checked
- // Volume Weight settings for when ALMA is unchecked, the same as SMA at 0, and the same as VWMA at 1
- // BB^2 is a bband drawn around the average %BB. Adjust the multiplier to change its window length
- // The BB^2 changes color when price moves up or down
- // Now its time to look at the parameters which affect the buy/sell signals
- // turn on "show signal range" - you see some red lines
- // buy and sell each have 3 settings
- // max variance will affect the brigtness of the signal range
- // range adjust will move the range up/down
- // mix BB^2 blends between a straight line (0) and BB^2's top or bottom (1)
- // a threshold of "variance" and "h/l points" is available for weaker signals.
- // these thresholds can be increased to show more weak signals
- // the 'signal-only' version of the indicator plots buy & sell signals on the price chart
- // it has 3 extra options
- // "show signal range" converts the signal range (red lines) to be relative to the price chart
- // "show middle band" fills a colour between 0.5 & the mid BB^2 and converts relative to the price chart
- // display width controls how much these lines diverge from the price
- // enjoy, I hope that is easy enough to understand, haha.
- //This file uses %BB code created by yield
- //If you find them useful please consider making him donation, thank you.
- //Bitcoin: 3F636VrPCdnbfrdP5kS4C6fHWVBffXNKCu
- study(title="%BB x7", precision=2, overlay=false)
- //inputs
- bblen = input(20.0, step=1, title="**BB: window length, use as main multiplier")
- plot1_t = input(3.57, title="Plot 1 - timescale(days)")
- plot2_t = input(2.21, title="Plot 2 - timescale")
- plot3_t = input(1.36, title="Plot 3 - timescale")
- plot4_t = input(0.85, title="Plot 4 - timescale")
- plot5_t = input(0.51, title="Plot 5 - timescale")
- plot6_t = input(0.34, title="Plot 6 - timescale")
- plot7_t = input(0.17, title="Plot 7 - timescale")
- bBandsTransparency=input(95, title="Transparency of %BB lines")
- showVariance = input(false,title="Show Variance between timescales?")
- srcSmooth = input(4, title=".. Source Smoothing Amount",minval=1)
- bbma = input(false, type=bool, title=".. Use ALMA for BB?(or VW-SMA)")
- offset = input(0.55, step=0.05, minval=0.05, maxval=1.0, title=".. Alma: Offset")
- sigma = input(2, step=1, minval=1, title=".. Alma: Sigma")
- volWeightAmt = input(0.7,step=0.1,minval=0,maxval=1, title=".. VW-SMA: Volume Weight (0-1)")
- bobLen = input(1.0, step=0.05, title=".. BB^2: Window length (multiplier)")*bblen
- getVWMA(_src,_len) =>
- (vwma(_src,_len) * volWeightAmt) + (sma(_src,_len) * (1-volWeightAmt))
- src = sma(close,srcSmooth)
- //get intervals to stick regardless of timeframe
- multIntra() => (isintraday ? 1.0 : (isdaily ? 1440.0 : isweekly ? 10080.0 : 43320.0))
- multDaily() => multIntra() / 1440.0
- getLengthMultiplier(_amt, _useDaily) => (_amt / (_useDaily ? multDaily() : multIntra())) / interval
- getLength(len, amountOf, useDaysNotMinutes) => round(len * getLengthMultiplier(amountOf, useDaysNotMinutes))
- getPBB(len) =>
- bb_mid = bbma ? alma(src, len, offset, sigma) : getVWMA(src, len)
- dev = 2.0 * stdev(src, len)
- bb_top = bb_mid + dev
- bb_low = bb_mid - dev
- resultPBB = (src - bb_low) / (bb_top - bb_low)
- //resultBBW = (bb_top - bb_low)/bb_mid
- resultPBB
- getFullBB(_src, _len) =>
- bb_mid = bbma ? alma(_src, _len, offset, sigma) : getVWMA(_src, _len)
- dev = 2.0 * stdev(_src, _len)
- bb_top = bb_mid + dev
- bb_low = bb_mid - dev
- //resultPBB = (_src - bb_low) / (bb_top - bb_low)
- //resultBBW = (bb_top - bb_low)/bb_mid
- [bb_top,bb_low,bb_mid]
- //input(true,title="use days?")
- plot1_d = true
- plot2_d = true
- plot3_d = true
- plot4_d = true
- plot5_d = true
- plot6_d = true
- plot7_d = true
- pbb1 = getPBB(getLength(bblen, plot1_t, plot1_d))
- pbb2 = getPBB(getLength(bblen, plot2_t, plot2_d))
- pbb3 = getPBB(getLength(bblen, plot3_t, plot3_d))
- pbb4 = getPBB(getLength(bblen, plot4_t, plot4_d))
- pbb5 = getPBB(getLength(bblen, plot5_t, plot5_d))
- pbb6 = getPBB(getLength(bblen, plot6_t, plot6_d))
- pbb7 = getPBB(getLength(bblen, plot7_t, plot7_d))
- pbbAvg = (pbb1 + pbb2 + pbb3 + pbb4 + pbb5 + pbb6 + pbb7) / 7
- pbbcolor = white
- hline(0, 'Zero', linestyle=dashed, linewidth=1, color=#7B68EE, editable=false)
- hline(.5, 'Half', linestyle=dashed, linewidth=1, color=#7B68EE, editable=false)
- hline(1, 'One', linestyle=dashed, linewidth=1, color=#7B68EE, editable=false)
- plot(pbb1, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB1")
- plot(pbb2, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB2")
- plot(pbb3, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB3")
- plot(pbb4, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB4")
- plot(pbb5, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB5")
- plot(pbb6, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB6")
- plot(pbb7, linewidth=1, transp=bBandsTransparency, style=line, editable=false, color=pbbcolor, title="% BB7")
- plot(pbbAvg, linewidth=2, transp=20, style=line, editable=true, color=#51edef, title="% BB AVG")
- bbLenAvg = (plot7_t+plot6_t+plot5_t+plot4_t+plot3_t+plot2_t+plot1_t)/7
- [bobTop,bobLow,bobMid] = getFullBB(pbbAvg, getLength(bobLen,bbLenAvg,true))
- plotBobTop = plot(bobTop, linewidth=1, transp=100, style=line, editable=false, title="bb^2 Top")
- plotBobLow = plot(bobLow, linewidth=1, transp=100, style=line, editable=false, title="bb^2 Low")
- plotBobMid = plot(bobMid, linewidth=1, transp=49, style=line, editable=false, title="bb^2 sma", color=blue)
- bobCol = round(bobMid *1000) == round(bobMid[1] *1000) ? #058480 : bobMid > bobMid[1] ? #01ff96:#043f81
- fill(plotBobTop,plotBobLow,transp=79,color=bobCol,title="bb^2")
- bbsMax = max(pbb1,max(pbb2,max(pbb3,max(pbb4,max(pbb5,max(pbb6,pbb7))))))
- bbsMin = min(pbb1,min(pbb2,min(pbb3,min(pbb4,min(pbb5,min(pbb6,pbb7))))))
- bbsVariance = bbsMax-bbsMin
- //strategy params
- showRange = input(false, "--Show Signal Range")
- bbsCloseVariancePointLow = input(0.35, title="--Max Variance for Buy Signal", step=0.05)
- buyRangeAdjust = input(0.05, title="--Buy range adjust:", step=0.025)
- buyMixBB = input(0.15, title="--Mix BB^2 into Buy Range (0-1)", step=0.1,minval=0,maxval=1)
- bbsCloseVariancePointHigh = input(0.50, title="--Max Variance for Sell Signal ", step=0.05)
- sellRangeAdjust = input(0.10, title="--Sell range adjust:", step=0.025)
- sellMixBB = input(0.85, title="--Mix BB^2 into Sell Range (0-1)", step=0.1,minval=0,maxval=1)
- buyRange = ( buyMixBB * bobLow ) + buyRangeAdjust
- sellRange = ( sellMixBB * bobTop ) - sellRangeAdjust + (1 - sellMixBB)
- buySignal = bbsVariance < bbsCloseVariancePointLow and pbbAvg < buyRange
- sellSignal = bbsVariance < bbsCloseVariancePointHigh and pbbAvg > sellRange
- weakVariance = input(0.1, title="--Threshold of Variance for weaker signals", step=0.05, minval=0)
- weakInput = input(0.075, title="--Threshold of H/L Point for weaker signals", step=0.025, minval=0)
- weakBuySignal1 = bbsVariance < bbsCloseVariancePointLow + weakVariance and pbbAvg < buyRange + weakInput
- weakSellSignal1 = bbsVariance < bbsCloseVariancePointHigh + weakVariance and pbbAvg > sellRange - weakInput
- weakBuySignal2 = bbsVariance < bbsCloseVariancePointLow + (weakVariance/2) and pbbAvg < buyRange + (weakInput / 2)
- weakSellSignal2 = bbsVariance < bbsCloseVariancePointHigh + (weakVariance/2) and pbbAvg > sellRange - (weakInput / 2)
- sRangeCol = bbsVariance < bbsCloseVariancePointHigh ? #FF0000 : bbsVariance < bbsCloseVariancePointHigh + weakVariance ? #550000 : #350000
- sr1 = plot(showRange ? sellRange : na, color=sRangeCol,editable=false)
- sr2 = plot(showRange ? sellRange - weakInput : na, transp=90,editable=false)
- bRangeCol = bbsVariance < bbsCloseVariancePointLow ? #FF0000 : bbsVariance < bbsCloseVariancePointLow + weakVariance ? #550000 : #350000
- br1 = plot(showRange ? buyRange : na, color=bRangeCol,editable=false)
- br2 = plot(showRange ? buyRange + weakInput : na, transp=90,editable=false)
- fill(sr1,sr2,color=sRangeCol,transp=90,editable=false)
- fill(br1,br2,color=bRangeCol,transp=90,editable=false)
- plotshape(buySignal, title="Dot mark Up", style=shape.arrowup, location=location.bottom, color=#01ff96, transp=0, size=size.normal, editable=false)
- plotshape(sellSignal, title="Dot mark Down", style=shape.arrowdown, location=location.top, color=#054e92, transp=0, size=size.normal, editable=false)
- plotshape(weakBuySignal1, title="Dot mark Up 1", style=shape.arrowup, location=location.bottom, color=#01ff96, transp=99, size=size.tiny, editable=false)
- plotshape(weakSellSignal1, title="Dot mark Down 1", style=shape.arrowdown, location=location.top, color=#054e92, transp=99, size=size.tiny, editable=false)
- plotshape(weakBuySignal2, title="Dot mark Up 2", style=shape.arrowup, location=location.bottom, color=#01ff96, transp=92, size=size.small, editable=false)
- plotshape(weakSellSignal2, title="Dot mark Down 2", style=shape.arrowdown, location=location.top, color=#054e92, transp=92, size=size.small, editable=false)
- //variance graph
- varianceGraphTop = bobMid+(bbsVariance/4)
- varianceGraphLow = bobMid-(bbsVariance/4)
- vgt = plot(showVariance ? varianceGraphTop : na, transp=100, editable=false, title="Variance Top")
- vgb = plot(showVariance ? varianceGraphLow : na, transp=100, editable=false, title="Variance Bottom")
- vgc = bbsVariance<min(bbsCloseVariancePointLow,bbsCloseVariancePointHigh)? white : bbsVariance<max(bbsCloseVariancePointLow,bbsCloseVariancePointHigh)? #56A4D8 : #285774
- fill(vgt,vgb,color=vgc,transp=80)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement