1. Documentation recommended for study: Timeseries and Indicators Access
2. Always check the result of all functions (in this case you didn't check the result of ' iTime ')
- www.mql5.com
1. Documentation recommended for study: Timeseries and Indicators Access
2. Always check the result of all functions (in this case you didn't check the result of ' iTime ')
Hi,
the result of iTime is correct:
The problem is the result of iBarShift (-1 the two first times).
Thank you.
Hi,
the result of iTime is correct:
The problem is the result of iBarShift (-1 the two first times).
Thank you.
Forum on trading, automated trading systems and testing trading strategies
Error getting iBarShift when opening MT5
Vladimir Karputov, 2022.06.02 15:09
1. Documentation recommended for study: Timeseries and Indicators Access
2. Always check the result of all functions (in this case you didn't check the result of ' iTime ')
//+------------------------------------------------------------------+ //| Temp Indicator.mq5 | //| Copyright 2022, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.000" #property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0 //--- input parameters //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { datetime i_time_current=iTime(Symbol(),PERIOD_CURRENT,0); int i_bar_shift_D1=iBarShift(Symbol(),PERIOD_D1,i_time_current,true); Print("OnCalculate: ",TimeToString(i_time_current,TIME_DATE|TIME_MINUTES)," - ",i_bar_shift_D1); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Item 1. Documentation recommended for study: Timeseries and Indicators Access is required reading and study.
And now an example: I closed the terminal and deleted the history and ticks for the 'EURUSD' symbol. Terminal launch result:
2022.06.02 16:30:38.868 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - -1 2022.06.02 16:30:39.015 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - -1 2022.06.02 16:30:39.016 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - -1 2022.06.02 16:30:39.219 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - -1 2022.06.02 16:30:39.220 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - -1 2022.06.02 16:30:39.276 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - 0 2022.06.02 16:30:39.377 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - 0 2022.06.02 16:30:39.874 Temp Indicator (EURUSD,H1) OnCalculate: 2022.06.02 16:00 - 0
That is, someone else's timeframe was built in five ticks. In general, the advice is the same: read and study the documentation: Timeseries and Indicators Access
- www.mql5.com
Hi,
the first time the indicator is executed when opening MT5, it fails to get iBarShift function, the second or third time the event OnCalculate is executed, it works OK
Thank
If(dayIndex <0) return 0;
- 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,
the first time the indicator is executed when opening MT5, it fails to get iBarShift function, the second or third time the event OnCalculate is executed, it works OK
Thank you