Hello
I have an EA that is not calulating the bands correctly.
You can see on the attachment the difference in using the bands indicator in metatrader and the one in the EA, but the settings are the same.
Here is the code for the bands in the EA, the only thing I can think of is that the EA using ibands and the metatrader indicator is iMA.
Ps I am not an experienced coder.
Thank you
Antony
The middle line of the standard Bolling Bands indicator is a simple moving average. So your code looks just fine.
Hi
I meant to also attach a snapshot of the chart, but here is a link:
http://tributetothem.com/bands1.gif
You can see the problem with the bands reading incorrectly, the blue lines are the metatrader bands indicator which shows the true reading.
Perhaps for the lower and upper bands I should use iMA instead of ibands?
Thanks
Antony
Another point as well is, I think that its to do with the diviations as the middle band is correct but the outer bands are not and when I try to adjust the divations with a new input it does not respond.
Thanks
Antony
are you sure you have the mt4 bollinger bands set to the same periods, deviations and shift as your EA ?
Hi
Thanks for the reply.
The MT4 indicator is set:
period: 21
deviations: 1.8
shift: 0
The EA is set as above except for the shift, as I had a lot of help setting in it up from an experienced coder then I am slightly lost.
Thank you
Antony
Hi again
Right, I have found that the mt4 indicator is using iMA and my EA is using ibands.
How could I use iMA i the above coding rather than ibands, I have been trying to replace this but I get plenty of errors.
Can someone show me how it should be?
Thanks
Antony
Ibands is returning a deviation of one. Your indicator is set to 1.8
double hi = iBands(Symbol(),Period(),BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_UPPER,1); double md = iMA (Symbol(),Period(),BandsPeriod,0,MODE_SMA,PRICE_CLOSE,1); double std= hi - md, lo = md - 1.8 * std; hi = md + 1.8 * std;
Hi
Brilliant you got it exact now thank you.
I am just recoding the lower part now so that the EA uses your method and I believe I require some more advice.
This is what I have tried unsuccessfully:
double BB(string up_dn, int barback){int tf = 0; if(BandsSetArrow){ double hi = iBands(Symbol(),Period(),BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_UPPER,1); double md = iMA (Symbol(),Period(),BandsPeriod,0,0,PRICE_CLOSE,1); double std= hi - md, lo = md - 1.8 * std; hi = md + 1.8 * std; SetArrow(4,Teal,hi,"BB hi",Time[1]); SetArrow(4,Teal,md,"BB midle",Time[1]); SetArrow(4,Teal,lo,"BB lo",Time[1]); } if(up_dn == "up"){ hi = md + 1.8 * std; } if(up_dn == "dn"){ lo = md - 1.8 * std; } }
Can anyone show where I am going wrong?
Thank you
Antony
Hi
Looks like I got it worked out, can anyone confirm this is the correct way:
double BB(string up_dn, int barback){int tf = 0; if(BandsSetArrow){ double hi = iBands(Symbol(),Period(),BandsPeriod,BandsDeviation,0,PRICE_CLOSE,MODE_UPPER,1); double md = iMA (Symbol(),Period(),BandsPeriod,0,0,PRICE_CLOSE,1); double std= hi - md, lo = md - 1.8 * std; hi = md + 1.8 * std; SetArrow(4,Teal,hi,"BB hi",Time[1]); SetArrow(4,Teal,md,"BB midle",Time[1]); SetArrow(4,Teal,lo,"BB lo",Time[1]); } if(up_dn == "up"){ return(md + 1.8 * std); } if(up_dn == "dn"){ return(md - 1.8 * std); } }
Thanks
Antony

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
I have an EA that is not calulating the bands correctly.
You can see on the attachment the difference in using the bands indicator in metatrader and the one in the EA, but the settings are the same.
Here is the code for the bands in the EA, the only thing I can think of is that the EA using ibands and the metatrader indicator is iMA.
Ps I am not an experienced coder.
Thank you
Antony