Please don't post randomly in any section. Your question is not related to the section you posted.
MT4/mql4 has it's own section on the forum.
Your thread has been moved, so please don't create another duplicate topic.
We cannot read your mind nor see your computer. We have no ideia how you came up with those numbers.
If you want to discuss them, then please show the code that generates them as well as the test conditions in which the code ran to produce those numbers.
Hi,
well here i wrote one simple code which gives me the same results.
Create an indicator named "testM1bars":
#property strict #property indicator_chart_window extern int param = 1; //param int randomNumber = MathRand(); int OnInit() { return(INIT_SUCCEEDED); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { Print("random=", randomNumber, ", m1Bars=", iBars(NULL, PERIOD_M1), ", param=", param); return(rates_total); }
With this simple template called "Tester.tpl" :
<chart> id=133186389516586264 symbol=EURUSD period=60 leftpos=1099 digits=5 scale=32 graph=0 fore=0 grid=1 volume=0 scroll=1 shift=0 ohlc=1 one_click=0 one_click_btn=1 askline=0 days=1 descriptions=0 shift_size=20 fixed_pos=0 window_left=0 window_top=0 window_right=534 window_bottom=732 window_type=3 background_color=0 foreground_color=16777215 barup_color=65280 bardown_color=65280 bullcandle_color=0 bearcandle_color=16777215 chartline_color=65280 volumes_color=3329330 grid_color=10061943 askline_color=255 stops_color=255 <window> height=69 fixed_height=0 <indicator> name=main </indicator> <indicator> name=Custom Indicator <expert> name=testM1bars flags=339 window_num=0 <inputs> param=1 </inputs> </expert> shift_0=0 draw_0=0 color_0=0 style_0=0 weight_0=0 period_flags=0 show_data=1 </indicator> </window> </chart>
Launch the StrategyTester on testM1bars.mq4 with param=2.
Here's an extract of what's logged where there's a minute change:
2023.04.17 13:54:46.373 2021.01.11 05:01:02 testM1bars EURUSD,M5: random=25889, m1Bars=7926662, param=1 2023.04.17 13:54:46.373 2021.01.11 05:01:00 testM1bars EURUSD,M5: random=26451, m1Bars=1294, param=2 2023.04.17 13:54:46.373 2021.01.11 05:01:00 testM1bars EURUSD,M5: random=25889, m1Bars=7926662, param=1 2023.04.17 13:54:46.373 2021.01.11 05:00:48 testM1bars EURUSD,M5: random=26451, m1Bars=1293, param=2 2023.04.17 13:54:46.373 2021.01.11 05:00:48 testM1bars EURUSD,M5: random=25889, m1Bars=7926662, param=1 2023.04.17 13:54:46.373 2021.01.11 05:00:47 testM1bars EURUSD,M5: random=26451, m1Bars=1293, param=2
You see the testM1bars with param=2 which is launch in the StrategyTester has an increase in m1 bars.
But the testM1bars with param=1 which is loaded through the template Tester.tpl has a number of bars wrong, pretty high and is not increased on the minute change.
Thanks
You are reading/printing garbage.
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)
Here's the code:
#property strict #property indicator_chart_window extern int param = 1; //param int OnInit() { return(INIT_SUCCEEDED); } bool download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){ return download_history(_Symbol, period); } bool download_history(string symbol, ENUM_TIMEFRAMES period=PERIOD_CURRENT){ if(period == PERIOD_CURRENT) period = (ENUM_TIMEFRAMES)_Period; ResetLastError(); datetime other = iTime(symbol, period, 0); if(_LastError == 0 && other != 0) return true; if(_LastError != ERR_HISTORY_WILL_UPDATED && _LastError != ERR_NO_HISTORY_DATA) PrintFormat("iTime(%s,%i) Failed: %i", symbol, period, _LastError); return false; } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { while(!download_history(PERIOD_M1) && !_StopFlag ){ Print( "BAD download of history. ",_LastError); Sleep(500); RefreshRates(); } Print("m1Bars=", iBars(NULL, PERIOD_M1), ", close=", iClose(NULL,PERIOD_M1,0), ", param=", param); return(rates_total); }
Results:
2023.04.19 16:49:55.217 2021.01.11 00:04:00 testM1bars EURUSD,M5: m1Bars=1004, close=1.2214, param=2 2023.04.19 16:49:55.217 2021.01.11 00:04:00 testM1bars EURUSD,M5: m1Bars=7926662, close=1.22116, param=1 2023.04.19 16:49:55.123 2021.01.11 00:03:59 testM1bars EURUSD,M5: m1Bars=1003, close=1.22133, param=2 2023.04.19 16:49:55.123 2021.01.11 00:03:59 testM1bars EURUSD,M5: m1Bars=7926662, close=1.22116, param=1
And i installed another new MT4 platform:
2023.04.19 17:10:58.407 2022.01.03 00:06:00 testM1bars EURUSD,M5: m1Bars=1003, close=1.13689, param=2 2023.04.19 17:10:58.407 2022.01.03 00:06:00 testM1bars EURUSD,M5: m1Bars=8292623, close=1.13693, param=1 2023.04.19 17:10:58.314 2022.01.03 00:05:10 testM1bars EURUSD,M5: m1Bars=1002, close=1.13688, param=2 2023.04.19 17:10:58.314 2022.01.03 00:05:10 testM1bars EURUSD,M5: m1Bars=8292623, close=1.13693, param=1
It never once logged "BAD download of history. " on neither platform.
Do you have any insights?
Thanks
int OnCalculate(…){ while(!download_history(PERIOD_M1) && !_StopFlag ){ Print( "BAD download of history. ",_LastError); Sleep(500); RefreshRates(); }
Indicators can not sleep. Indicators can not delay. Return and wait for a new tick.
Indicators can not sleep. Indicators can not delay. Return and wait for a new tick.
Thanks for that information but it doesn't correct the problem.
The number of M1 bars is anormally high and is not increasing on new M1 bars.
To me it seems to be a MT4 platform bug. Maybe trying the same thing with the MT5 platform would confirm that.
Result on MT5:
2023.04.25 09:52:23.469 2023.01.02 17:59:59 m1Bars=373485, close=1.06603, param=1 2023.04.25 09:52:23.469 2023.01.02 17:59:59 m1Bars=373485, close=1.06603, param=2 2023.04.25 09:52:23.469 2023.01.02 18:00:00 m1Bars=373486, close=1.06602, param=1 2023.04.25 09:52:23.469 2023.01.02 18:00:00 m1Bars=373486, close=1.06602, param=2
The number of bars is the same and is increased...
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
Here's the scenario:
i use the tester to test my indicator (A). The indicator uses M1 bars but is running in M5.
I create a template Tester and add the same indicator with a different parameter (B).
So, while executing the tester, (A) is updated just fine but (B) always stay the same.
So, i dug by printing info.
At initialization, the indicator generate a MathRand to deferentiate (A) from (B).
I log iBars of M1.
Here's the result:
2023.04.17 11:10:49.850 2021.01.11 02:51:00 Indic EURUSD,M5: r=20845, m1Bars=1164
2023.04.17 11:10:49.850 2021.01.11 02:51:00 Indic EURUSD,M5: r=20183, m1Bars=7926662
2023.04.17 11:10:49.850 2021.01.11 02:50:54 Indic EURUSD,M5: r=20845, m1Bars=1163
2023.04.17 11:10:49.850 2021.01.11 02:50:54 Indic EURUSD,M5: r=20183, m1Bars=7926662
Since (A) changes visually while the Tester is running, we can say the (A) has the random value 20845 because a new M1 bars appears to become 1164 bars.
And (B) always stay the same since the bars stays at 7926662.
My questions are:
- Why aren't the bars the same ? 7926662 versus 1164
- Why does (B) has a value so high ?
- Why does (B) doesn't get a new bar ?
In this test, i'm using the data of MT4, no TickStory or TickDataSuite.
I tried it on another computer where i have TickDataSuite and it's the same result.
Thanks for the help
Ben