Discussion of article "Deep neural network with Stacked RBM. Self-training, self-control" - page 8

 

To whom it may concern

Strategy Tester:

As the code (SAE) is constructed today, the NN goes into training upon the 1st occurrence of the OnTick() Event. Depending on complexity and PC-Power this can take several decades of seconds. During this time, the tester keeps on sending OnTick() Events, which are not processed, because RTERM is still busy, learning. Like this, several thousands ticks are not processed. In case that the code is modified to synchronous execution of RTERM, the problem remains. Now upon the 1st OnTick() Event, the network goes learning and execution is NOT returned to the EA, however the tester still keeps running and accumulating ticks, like in real life, where ticks are processed by MT4, regardless if the EA OnTick() handler returns, or not. If not, ticks are accumulated and processed, when the EA is ready to execute the OnTick() Handler for the next time. I summarize: In case of async execution of RTERM, thousands of ticks (hundreds of complete candles) are not processed. In case of sync'd execution, between the 1st Tick and the 2nd tick, the tester has accumulated thousands of ticks and candles.

The solution of the problem is to move the learning phase into the OnInit() handler. During OnInit(), the tester has already created a new chart with a history of 1002 candles. The 1002 cannot be changed. Hence, during OnInit(), all history information is available and the NN can start learning. Other than during the OnTick() event, the tester WAITS until the EA has finished his OnInit() handler. Using sync'd execution of RTERM forces the OnInit() handler and subsequently the tester to wait, until learning is finished and RTERM has returned. Herafter, the 1st Tick can then be processed normally.

In my setup, the PC takes ~20 sec for learning. In an 1H Chart, in average 800-900 ticks are created for one 1H candle. I observe a gap of several days between the 1st and 2nd tick, if learning happens within the OnTick() Handler.

int OnInit()
{
   EventSetTimer(2);

   if (Bars < limit) lim = Bars-5;
   else lim = limit;  
   
      ArrayResize(o, lim);
      ArrayResize(hi, lim);

...


   Ri("Dig", 1);
   Rd("Kmin", Kmin);
//-------CheckWorkR----------------------------------------
   if(!RIsRunning(hR)){
       Alert("Rterm crash!(init)");
       return(1);
   }
     // Fill the array with new data
      for(int i = 0; i < lim; i++)
        {
         o[i]  = Open[i+1];
         hi[i] = High[i+1];
         lo[i] = Low[i+1];
         clo[i]= Close[i+1];
        }
      //--------Send data to Rterm for learning--------------------------------------
      Rv("Open",o);
      Rv("High",hi);
      Rv("Low",lo);
      Rv("Close",clo);
      SetLabelText("learn", "learning", cvet, 50, 30, 3, 12);
      RExecute(hR, RUN);      // Synchronous execution; wait until finished learning
      Print("return from learning");
      ObjectDelete(NULL,"learn");

   return(INIT_SUCCEEDED);

Rgds

hk