Jumping back in Timeseries? Is that possible?

 

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)

input bool training = true                    // Training or Livetrading
static bool filewritten;                      // is file already written in first trail, so that now we can train on it?


OnTick()
{
if(training = true && filewritten=false)
      {
      WriteFile();                    //write file

      if(iTime(...) == FinalDay)      // if all data written, stop writing...
            {
            filewritten = true;
            JumpBackToBeginnDate();        // <========== THIS is what I am looking for !!!
            }
      
      }

else if (training = true && filewritten = true)
      {
      TrainOnFile();                  // ... and start training
      }


else if (traininf = false)
  {TradingAlgorithm();}               //normal boring trade executions
}
 

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
Documentation on MQL5: Timeseries and Indicators Access / iBars
Documentation on MQL5: Timeseries and Indicators Access / iBars
  • www.mql5.com
The number of bars of a corresponding symbol and period, available in history, but no more than allowed by the "Max bars in chart" parameter in platform settings.
 
Marco vd Heijden:

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
to get that right: i collect data the data before even using OnTick() just by iterating over the Values with iBars as index?
 

That is correct.

You can do the training cycle in OnInit() Function.

Still make sure to check if the data is available before further processing.
 
Marco vd Heijden:

That 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);
  }
//+------------------------------------------------------------------+
 
Marco vd Heijden:

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,

Thank you :)
Reason: