If the bar does not exist in history then iTime will return a zero so in theory you could loop back over all bars until you hit a zero and that will be your starting point.
But if a bar is missing somewhere for whatever reason then it would represent a false starter so you can also use iBars() to Return the number of bars of a corresponding symbol and period, available in history.
https://www.mql5.com/en/docs/series/ibars- www.mql5.com
If the bar does not exist in history then iTime will return a zero so in theory you could loop back over all bars until you hit a zero and that will be your starting point.
But if a bar is missing somewhere for whatever reason then it would represent a false starter so you can also use iBars() to Return the number of bars of a corresponding symbol and period, available in history.
https://www.mql5.com/en/docs/series/ibarsThat is correct.
You can do the training cycle in OnInit() Function.
Still make sure to check if the data is available before further processing.so if some bars are missing im still on the safe side with iBars() istead of iTime(). (or else how could i make it work?)
another question is how to adress a value by that bar ( for example iMA and a shifted iClose())
iBars() tells you the number of iterations in your loop, the return value of iTime() or iOpen...iHigh..iLow..iClose tell you if the data is available.
If it returns a zero or some unrealistic value then you simply omit that bar from your calculations.
So before proceeding you check both ends of the spectrum to see if the data fits within the nominal bandwidth.
iMa and iClose and the others also take the bar index value.
Here is a small example,
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- int bars=iBars(Symbol(),PERIOD_M1); Print(" Bars: "+(string)bars+" Found"); datetime time; double open,high,low,close; for(int i=bars;i>0;i--) { time=iTime(Symbol(),PERIOD_M1,i); open=iOpen(Symbol(),PERIOD_M1,i); high=iHigh(Symbol(),PERIOD_M1,i); low=iLow(Symbol(),PERIOD_M1,i); close=iClose(Symbol(),PERIOD_M1,i); //--- check if(time!=0) { Comment("Bar Index: "+(string)i+ " Time: "+TimeToStr(time)+ " Open: "+DoubleToStr(open)+ " High: "+DoubleToStr(high)+ " Low: "+DoubleToStr(low)+ " Close: "+DoubleToStr(close)); Sleep(25); } } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+
iBars() tells you the number of iterations in your loop, the return value of iTime() or iOpen...iHigh..iLow..iClose tell you if the data is available.
If it returns a zero or some unrealistic value then you simply omit that bar from your calculations.
So before proceeding you check both ends of the spectrum to see if the data fits within the nominal bandwidth.
iMa and iClose and the others also take the bar index value.
Here is a small example,
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey,
I need to train my Neural Network,
but before A File with all the Inputs has to be written.
I want to make it possible with just one EA initialisation, like in the following PseudoCode: (is that possible)