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
- //signal only version. read the instructions on the main version
- study(title="%BB x7 Signals", precision=2, overlay=true)
- //inputs
- bblen = input(20.0, step=1, title="**BB: window length, use as main multiplier")
- bbStdDev = input(2.0, step=0.05, title="BB: Standard Deviations")
- bobLen = input(1.0, step=0.05, title="BB^2: Window length (multiplier of ^)")*bblen
- 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")
- //showVariance = input(false, title="Show Variance between timescales?")
- //bBandsTransparency=input(95, title="Transparency of %BB lines")
- srcSmooth = input(4, title="Source Smoothing Amount")
- //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)")
- getVWMA(_src,_len) =>
- (vwma(_src,_len) * volWeightAmt) + (sma(_src,_len) * (1-volWeightAmt))
- src = sma(close,srcSmooth)
- //get intervals to stick regardless of timeframe [TWITCHY]
- 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))
- getFullBB(_src, _len) =>
- //bb_mid = bbma ? alma(_src, _len, offset, sigma) : getVWMA(_src, _len)
- bb_mid = getVWMA(_src, _len)
- dev = bbStdDev * stdev(_src, _len)
- bb_top = bb_mid + dev
- bb_low = bb_mid - dev
- [bb_top,bb_low,bb_mid]
- getPBB(len) =>
- [bb_top,bb_low,bb_mid] = getFullBB(src,len)
- resultPBB = (src - bb_low) / (bb_top - bb_low)
- resultPBB
- useDays = input(true,title="Timeframe in days?(or minutes)")
- pbb1 = getPBB(getLength(bblen, plot1_t, useDays))
- pbb2 = getPBB(getLength(bblen, plot2_t, useDays))
- pbb3 = getPBB(getLength(bblen, plot3_t, useDays))
- pbb4 = getPBB(getLength(bblen, plot4_t, useDays))
- pbb5 = getPBB(getLength(bblen, plot5_t, useDays))
- pbb6 = getPBB(getLength(bblen, plot6_t, useDays))
- pbb7 = getPBB(getLength(bblen, plot7_t, useDays))
- pbbAvg = (pbb1 + pbb2 + pbb3 + pbb4 + pbb5 + pbb6 + pbb7) / 7
- bbLenAvg = (plot7_t+plot6_t+plot5_t+plot4_t+plot3_t+plot2_t+plot1_t) / 7
- [bobTop,bobLow,bobMid] = getFullBB(pbbAvg, getLength(bobLen,bbLenAvg,useDays))
- 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
- showSignals = input(true, "--Show Buy/Sell Signal")
- showRange = input(false, "--Show Signal Range")
- showMiddle = input(false, "--Show Middle Band")
- dispWidth = input(10.00, "-----Display Width")
- 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 bottom 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 top into Sell Range (0-1)", step=0.1,minval=0,maxval=1)
- buyRange = ( buyMixBB * bobLow ) + buyRangeAdjust
- sellRange = ( sellMixBB * bobTop ) - sellRangeAdjust + (1 - sellMixBB)
- weakVariance = input(0.10, 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)
- buySignal = bbsVariance < bbsCloseVariancePointLow and pbbAvg < buyRange
- weakBuySignal1 = bbsVariance < bbsCloseVariancePointLow + (weakVariance/2) and pbbAvg < buyRange + (weakInput / 2)
- weakBuySignal2 = bbsVariance < bbsCloseVariancePointLow + weakVariance and pbbAvg < buyRange + weakInput
- sellSignal = bbsVariance < bbsCloseVariancePointHigh and pbbAvg > sellRange
- weakSellSignal1 = bbsVariance < bbsCloseVariancePointHigh + (weakVariance/2) and pbbAvg > sellRange - (weakInput / 2)
- weakSellSignal2 = bbsVariance < bbsCloseVariancePointHigh + weakVariance and pbbAvg > sellRange - weakInput
- showSell = pbbAvg>bobMid
- [bbT,bbL,bbM] = getFullBB(src, getLength(dispWidth,bbLenAvg,true))
- pPrice = pbbAvg * (bbT-bbL) + bbL
- pAdjust = src/pPrice
- convertToPrice(_input) => (_input * (bbT-bbL) + bbL) * pAdjust
- sellRangePrice = convertToPrice(sellRange)
- sellRangePrice1 = convertToPrice(sellRange - weakInput)
- buyRangePrice = convertToPrice(buyRange)
- buyRangePrice1 = convertToPrice(buyRange + weakInput)
- bobCol = round(bobMid *1000) == round(bobMid[1] *1000) ? #858400 : bobMid > bobMid[1] ? #22ff00:#FF2200
- midLine1 = plot(showMiddle?convertToPrice(0.5):na, transp=100,editable=false)
- plotBobMid = plot(convertToPrice(bobMid), transp=100, editable=false, title="bb^2 sma")
- fill(midLine1,plotBobMid, transp=70,color=#22ff00)
- //fill(plotBobTop,plotBobLow,transp=95,color=bobCol,title="bb^2")
- sRangeCol = showSell ? bbsVariance < bbsCloseVariancePointHigh ? color(#FF2222, 50) : bbsVariance < bbsCloseVariancePointHigh + weakVariance ? color(#FF2222, 67) : color(#FF2222, 71) : color(#FF2222, 85)
- bRangeCol = not showSell ? bbsVariance < bbsCloseVariancePointLow ? color(#FF2222, 50) : bbsVariance < bbsCloseVariancePointLow + weakVariance ? color(#FF2222, 67) : color(#FF2222, 71) : color(#FF2222, 85)
- sr1 = plot(showRange ? sellRangePrice : na, color=sRangeCol,editable=false)
- sr2 = plot(showRange ? sellRangePrice1 : na, transp=100,editable=false)
- br1 = plot(showRange ? buyRangePrice : na, color=bRangeCol,editable=false)
- br2 = plot(showRange ? buyRangePrice1 : na, transp=100,editable=false)
- fill(sr1,sr2,color=sRangeCol,transp=70,editable=false)
- fill(br1,br2,color=bRangeCol,transp=70,editable=false )
- plotshape(showSignals?buySignal:na, title="Buy", style=shape.arrowup, location=location.belowbar, color=#01ff96, transp=0, size=size.normal, editable=true)
- plotshape(showSignals?weakBuySignal1:na, title="Weak Buy", style=shape.arrowup, location=location.belowbar, color=#01ff96, transp=80, size=size.tiny, editable=true)
- plotshape(showSignals?weakBuySignal2:na, title="Weaker Buy", style=shape.arrowup, location=location.belowbar, color=#01ff96, transp=50, size=size.small, editable=true)
- plotshape(showSignals?sellSignal:na, title="Sell", style=shape.arrowdown, location=location.abovebar, color=#054e92, transp=0, size=size.normal, editable=true)
- plotshape(showSignals?weakSellSignal1:na, title="Weak Sell", style=shape.arrowdown, location=location.abovebar, color=#054e92, transp=80, size=size.tiny, editable=true)
- plotshape(showSignals?weakSellSignal2:na, title="Weaker Sell", style=shape.arrowdown, location=location.abovebar, color=#054e92, transp=50, size=size.small, editable=true)
- //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