JozoParticipant
Junior
Hi Members, I am looking for Bollinger Bands with the shift (offset) feature. Any help will be much appreciated.
Jozo
What do you want to be shifted?
JozoParticipant
Junior
Hi
What I do need is the bollinger bands as follows Standard in brackets:
Periods: (20)
Shift/Offset days: ()
Standard Deviation: (2.0)
Then it offers me a chance to set it up as I wish with various day, sd and shift parameters.
Thanks
There you go:
//BBVal= 20 //20 periods BB
//BBdev= 2.0 //2.0 deviation BB
BBval = max(2,min(999,BBval)) //2 - 999
BBdev = max(1.0,min(99.9,BBdev)) //1.0 - 99.9
BBavg = average[BBval,1](close) //BB mean (middle line) - 1=ema
BollUp = BBavg + ((std[BBval](close)) * BBdev) //BB Upper Band
BollDn = BBavg - ((std[BBval](close)) * BBdev) //BB Lower Band
RETURN BBavg AS "Mean",BollUp AS "Top",BollDn AS "Bottom"
//BBVal = 20 //20 periods BB
//BBdev = 2.0 //2.0 deviation BB
//ShiftNum= 0 //0 numbers of shifted periods
BBval = max(2,min(999,BBval)) //2 - 999
BBdev = max(1.0,min(99.9,BBdev)) //1.0 - 99.9
ShiftNum = max(0,min(99,ShiftNum)) //0 - 99
BBavg = average[BBval,1](close[ShiftNum]) //BB mean (middle line) - 1=ema
BollUp = BBavg + ((std[BBval](close[ShiftNum])) * BBdev) //BB Upper Band
BollDn = BBavg - ((std[BBval](close[ShiftNum])) * BBdev) //BB Lower Band
RETURN BBavg AS "Mean",BollUp AS "Top",BollDn AS "Bottom"
you cam import attached ITF file(s).
I hope that’s what you wanted (0=no shifting, 1=shift 1 period, ……).
JozoParticipant
Junior
Hi Robertogozzi,
Thank you very much for your assistance. Perhaps I did not explain myself well. What I mean by shift is to be able to move the bands forward (+ number) or backward (- number). for example here is an example on MT4.
The indicator you have provided is not doing that as shown.
Thanks again.
JozoParticipant
Junior
Oh, may be it is working well as required. Sorry, because I didn’t see the extension ahead of price,I thought it was not. But seems you have coded it not to show. Is that correct?
JozoParticipant
Junior
I have now checked it with my MT4 comparison, it is working very well. Thank you so much. I am new to this platform.
@Jozo
Sorry for not replying to you. I missed it. Indeed only PRT can plot into the future (like Ichimoku), not us users!
Actually v11.x allows to plot objects into the future, but not returned data.
Thanks for the code. It shifts the indicator forward.
How can we shift an indicator backwards (to the left) ?
There you go:
//BBVal = 20 //20 periodi BB
//BBdev = 2.0 //2.0 deviazione BB
//ShiftNum= 0 //0 numbers of shifted periods o the LEFT
BBval = max(2,min(999,BBval)) //2 - 999
BBdev = max(1.0,min(99.9,BBdev)) //1.0 - 99.9
ShiftNum = max(0,min(99,ShiftNum)) //0 - 99
IF BarIndex > (BBval + ShiftNum) THEN
BBavg = average[BBval,1](close) //BB mean (middle line) - 1=ema
BollUp = BBavg + ((std[BBval](close)) * BBdev) //BB Upper Band
BollDn = BBavg - ((std[BBval](close)) * BBdev) //BB Lower Band
BarNum = BarIndex - ShiftNum
DRAWSEGMENT(BarNum[1],BBavg[1] ,BarNum,BBavg) coloured(255,0,0,255)
DRAWSEGMENT(BarNum[1],BollUp[1],BarNum,BollUp) coloured(0,0,255,255)
DRAWSEGMENT(BarNum[1],BollDn[1],BarNum,BollDn) coloured(0,0,255,255)
ENDIF
RETURN
since no data are RETURNed (it plots lines with a graphical instruction), the cursor cannot show any info about these bands.
In my screenshot the upper chart is shifted leftwards by 3 bars.