how to use OnTick() on weekend and get return values for testing purpose

 

Hello Everyone

This post is somehow related to my previous topic at https://www.mql5.com/en/forum/456103 where in following suggestion was there from @William Roeder

  1. Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

I am now trying to synchronize and checkLoadHistory before running my calculations in OnTick().

The challenge is I am running it on weekend and since there is no tick, none of the PrintFormat() statement work and Class is terminated by return condition.

Is there a way to over come this and continue working with available bars in history? 

void CSessionVPBase::OnTick(void) {

                string vMethod = "[" + mSymbol + "," + TimeToString(TimeCurrent()) + "] " + __FUNCTION__;
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| checkLoadHisory() returns 0,1 or 2, if bars are synchronized with history, hence used >= 0
        //+---------------------------------------------------------------------------------------------------------------------------+
                datetime serverFirstDateM1  = (datetime)SeriesInfoInteger(mSymbol,PERIOD_M1,SERIES_SERVER_FIRSTDATE);
                int              resultM1                                 = cATS.checkLoadHistory(PERIOD_M1,serverFirstDateM1);
                datetime serverFirstDateH1  = (datetime)SeriesInfoInteger(mSymbol,PERIOD_H1,SERIES_SERVER_FIRSTDATE);
                int              resultH1                                 = cATS.checkLoadHistory(PERIOD_H1,serverFirstDateH1);
                datetime serverFirstDateSTF = (datetime)SeriesInfoInteger(mSymbol,mSessionTF,SERIES_SERVER_FIRSTDATE);
                int              resultSTF                                = cATS.checkLoadHistory(mSessionTF,serverFirstDateSTF);

                if(resultM1 < 0 || resultH1 < 0 || resultSTF < 0) {
                        PrintFormat("%s: Bars[%i] >= MaxBars[%i] TimeSeries Data not synchronized resultM1[%i] resultH1[%i] resultSTF[%i], try on next Tick",vMethod,Bars(mSymbol,PERIOD_M1),TerminalInfoInteger(TERMINAL_MAXBARS),resultM1,resultH1,resultSTF);
                        return;
                }
                PrintFormat("%s: Bars[%i] >= MaxBars[%i] TimeSeries Data synchronized resultM1[%i] resultH1[%i] resultSTF[%i]",vMethod,Bars(mSymbol,PERIOD_M1),TerminalInfoInteger(TERMINAL_MAXBARS),resultM1,resultH1,resultSTF);
}
iBars() does not work on weekends?
iBars() does not work on weekends?
  • 2023.10.21
  • www.mql5.com
Dear Members I am iBars() in a indicator Class and it was working perfectly fine even on Saturday (Weekend...
 
Anil Varma:

Hello Everyone

This post is somehow related to my previous topic at https://www.mql5.com/en/forum/456103 where in following suggestion was there from @William Roeder

  1. Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

I am now trying to synchronize and checkLoadHistory before running my calculations in OnTick().

The challenge is I am running it on weekend and since there is no tick, none of the PrintFormat() statement work and Class is terminated by return condition.

Is there a way to over come this and continue working with available bars in history? 

Use strategy tester.

 
Samuel Manoel De Souza #:

Use strategy tester.

Hi @Samuel Manoel De Souza

Wow such a simple solution, yeh it did worked in Strategy Tester.

Thanks a lot.