Modified Bollinger Bands

 

Hello everyone,


I am new to metatrader and new to this forum as well. However I am very much looking forward to gaining new knowledge on MQL4 and MetaTrader.


I was wondering if there is an indicator on the software of a rather modified bollinger band.


We all know that the bands are calculated using the standard deviation. However, the original stddev formula uses the absolute value of the deviations. I was wondering if it would be possible to separate the positive values of deviation from the negative values of deviation.

Something like a semi standard deviation, if this term is correct. Resulting in a Gain Standard Deviation for the positive values of deviation and a Loss Standard Deviation for the negative deviations.


Once with this data, I was thinking of implementing the Gain Standard Deviation for the upper bollinger band and the Loss Standard Deviation for the lower band.


This could give us visually the volatility and some of it's direction.. if it is pulling it up or pulling it down.


Is this possible with metatrader?


I hope I made myself clear, and would be very happy if someone with more expirience helped me out here.


Thank you in advance,

Carlos

 

Interesting concept. I tried to implement it by modifying standard Bands indicator.

I attached the two versions of my codes Bands2 and Bands3. However I am not sure if is is working according to your concept.

I made the following changes:

  • Added a new parameter MAPeriod, so you could individually set periods for calculating moving average and for calculating standard deviation.
  • In bands2 I changed method of calculating standard deviation it normalize values to moving average.
  • Separated negative and positive deviation into 2 sets and calculated standard deviation for upper and lower band. If there are no data in one of the sets deviation is set to 0.
Files:
bands3.mq4  4 kb
bands2.mq4  4 kb
 

Hello scalony,


First of all, thank you for your reply. However, I don't think your code is working accordingly to the concept i was trying to obtain.


Perhaps it would be easier to treat the bands separately.. as in two different indicators.


Indicator1 would draw a moving avarage over the prices. Then it would collect only the values above the moving avarage and calculate the deviation on them. This way we could have a Northbound standard Deviation.

It would then trace another line, this time with the moving avarage PLUS X times the deviation. (X being a parameter of the number of deviations.)


Indicator2 would also draw a moving avarage over the prices. Then it would collect only the values below the moving avarage and calculate the deviation on them. This way we could have a Southbound standard Deviation.

It would then trace another line, this time with the moving avarage MINUS X times the deviation. (X being a parameter of the number of deviations.)


It would be interesting to take into consideration the data from (High+Low+Close)/3 instead of only the close as well.


Once again.. thank you very much for your reply and sorry to bother again. It is that I am still learning the programing language and it is turning out to be a bit more difficult than what I had hoped for.

 

Can anyone show me an indicator that calculates the semi standard deviation?


Something follwing this formula:

http://datalab.morningstar.com/knowledgebase/aspx/Article.aspx?ID=281


And then drawing a line below the prices...


Can anyone help me out here?

 

That is helpful. I found one mistake I have made in my previous code.


And made new version of semi standard deviation bands.

I hope this one will be more suitable.


As in previous version I implemented two ways of calculating deviation. However now it is one indicator with switch (MovingDeviation).

Setting this swith for false calculates Deviation in the same way as in standard Bolinger Bands

However Setting it to true changes deviation calculation - to cach amplitude of waves.


Have many profitable trades,

And let me know how well this indicator is working for you.

Files:
Reason: