On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)
I don't realty know the reason why you are having the issue with the update, but you should not be hard-coding values. Use the enumerations instead.
The following script illustrates an example as well as demonstrate that the iBands is returning a valid value on MT4 Build 1370 (11th January 2023).
#property strict #property script_show_inputs input ENUM_TIMEFRAMES i_eTimeFrame = PERIOD_M5; // Timeframe for Bands void OnStart( void ) { double dbUpperBand = iBands( _Symbol, i_eTimeFrame, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, 1 ); PrintFormat( "%s: %d, Upper Band: %s", EnumToString( i_eTimeFrame ), (int) i_eTimeFrame, DoubleToString( dbUpperBand, _Digits ) ); };
2023.02.15 18:59:30.950 Script (Test)\test EURUSD,H1: loaded successfully 2023.02.15 18:59:32.741 test EURUSD,H1 inputs: i_eTimeFrame=5; 2023.02.15 18:59:32.757 test EURUSD,H1: initialized 2023.02.15 18:59:32.757 test EURUSD,H1: PERIOD_M5: 5, Upper Band: 1.06766 2023.02.15 18:59:32.757 test EURUSD,H1: uninit reason 0 2023.02.15 18:59:32.757 Script test EURUSD,H1: removed
Just noticed that you mention that it works on a live chart but not on the Strategy Tester.
Are you perhaps using a 3rd party tool like TickStory or Tick Data Suite?
If so, then there could be two possible reasons that do not really have to do with the update.
- When testing with the same date range as the generated FXT, then you will not have the previous 1000 bars that would normally be available with normal tests, so your iBands for the previous bar would fail on the first bar of the test.
- You will also need to generate HST files for all the required time-frames and not just the FXT file.
Just noticed that you mention that it works on a live chart but not on the Strategy Tester.
Are you perhaps using a 3rd party tool like TickStory or Tick Data Suite?
If so, then there could be two possible reasons that do not really have to do with the update.
- When testing with the same date range as the generated FXT, then you will not have the previous 1000 bars that would normally be available with normal tests, so your iBands for the previous bar would fail on the first bar of the test.
- You will also need to generate HST files for all the required time-frames and not just the FXT file.
Thank you for the reply and the ideas,
I was using tick Data Suite and deleted it to see if that caused the problem (I also had an issue that after every backtest my Strategy tester would crash and instantly close Mt4, which I also suspect could be something to do with the update because it also worked fine for years until a couple of weeks ago).
For these testings I am now using normal Mt4 data. I also re-installed Mt4 to check if anything was corrupt. But no luck.
//Bollinger bands double LowerBand = iBands(Symbol(), PERIOD_M5, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 1); if(Ask < LowerBand && LowerBand != 0) return true; else if(LowerBand == 0) Print("BB Loading error "); //Even after coding the ENUM_TIMEFRAME method I get the BB to 0. //In my tester I downloaded data from 4 months ago, and backtested from only 1 month to see if it had to do with it not loading the previous bars, but this also didnt fix the issue
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
For years, I was reading out BB into a double and worked perfectly fine using a hard coded timeframe (i.e Not using Period() as an argument), this gave me the chance to change timeframes without changing my strategy:
Now in the strategy tester, iBands always returns 0 when testing on all timeframes, except if I run the backtest on the m5 timeframe. It seems like it is not loading the BB data from another timeframe.
I could not get my head around why this (which again, I have been using for years) suddenly failed, my only logical answer would be if maybe Mt4 did an update, and indeed it did:
I saw in their website they just released a new update on January 16th: https://www.metatrader4.com/en/releasenotes
Is anyone else experiecing this? Kind of scary if Mt4 suddenly changes a functionality and a strategy running for years suddenly doesn't work anymore.