Bollinger Band 2 - Yearly Chart

Firstly, I know very little to do with Scripting so I'd appreciate your input to get me started. I would like to produce a script for a Bollinger Band (Bars 2) on a Yearly Chart where the Bollinger Bands come within 5, 10,or 15% between the upper plot and the lower plot. From this I could have Two separate scripts.....one with either 5%, one with 10% and one with 15% on Quarterly & Yearly charts but the highest time frame in the Yearly chart is the strongest. I hope you can help me and I'll attach examples where strong moves are produced after the squeeze. Thinking out loud - Can a script be written so that it analyses Both Time Frames at once?.....or separately? Thanks in advance.

Hi Leon,

The best place to start is with the Introduction to Scripting video series, which you can watch by signing in here. The language has been designed for non-programmers, so once you understand the logic you should be able to pick it up.

In your example, the difference between the upper and lower Bollinger Bands can be displayed in a tool called Bollinger Bandwidth. This basically takes the distance between the upper and lower bands and divides by the middle band.

Here’s your GE one year example showing both the 2 year Bollinger Bands and the Bandwidth tool: (38.05 - 18.10) / 28.08 = 0.71 (or 71%)

Capture

So for scripts for 5%, 10% and 15% you could add different coloured Show Bars for each value, using the BBW() function for the bandwidth.

Red (less then 5%) = BBW(BARS=2) < 0.05

Blue (between 5% and 10%) = BBW(BARS=2) > 0.05 and BBW(BARS=2) < 0.1

Green (between 10% and 15%) = BBW(BARS=2) > 0.1 and BBW(BARS=2) < 0.15

Capture

 

Note that these conditions will be calculated on the timeframe of the chart, so switching between quarterly and annual charts will automatically recalculate the Show Bar results.

If you wanted to create conditions for both timeframes it is possible to create formulas, such as this for both yearly and quarterly below 15%:

BBW(Year(PERIODAMOUNT=1), BARS=2) < 0.15 and BBW(Month(PERIODAMOUNT=3), BARS=2) < 0.15

Let me know what you think.

 

 

Hi Darren,

 

Thanks very much for your input. I did sign up to the Scripting video series and tried to work the correct formula to use without success but what you have done here has been of great help. I'll do some work on it and see how it goes. Thanks again.

 

Leon