Strategy Tester anomaly

 

Hi

Any help or explanation much appreciated 

This is some EA OnInit() code

int OnInit()
   {
      datetime CurrentDate = ( iTime(NULL,PERIOD_D1,0)) ;
      Print (CurrentDate);
   }

When I run the strategy tester its prints the date once as expected when the EA starts 

If I add one or two or a few more days on to the dates I'm testing (** leaving the same start date but just days added on)

Then just run the tester it returns the 1970.01.01 date 

See attached .....

if I recompile the EA , it prints the the correct day every time (UNTILL I add another few days)

Any help much appreciated 

PS .. there is no more code in the EA - that's it above  

(I'm using TICKDATA suite)

Kind Regards

Files:
Example1.jpg  187 kb
 

Don't double post! You already had a thread open. Why did you not simply continue there? I will remove the other thread.

Forum on trading, automated trading systems and testing trading strategies

iTime Date function

CharlieDenver, 2023.04.14 21:10

Hello

I wondered if anyone could help me with a query 

int OnInit()
   {
      datetime CurrentDate = ( iTime(NULL,PERIOD_D1,0)) ;
      Print (CurrentDate);
   }

Forum on trading, automated trading systems and testing trading strategies

iTime Date function

Fernando Carreiro, 2023.04.14 21:15

Don't access symbol data from within the OnInit() event handler. The connection to the trader server and data synchronisation may not have occurred yet. Instead, do it in OnTick().

As for your query, it is unclear. You have not explained what it is you want to know.

 

As I was trying to explain I posted it by mistake 

I wish I was perfect 

 

Please don't post randomly in any section. Your question is not related to the section you posted.

MT4/mql4 has it's own section on the forum.

I will move your topic to the correct section later, please don't create another topic.

 

As for my query

it's the same if I put the code in ontick()

same issue 

 
CharlieDenver #: As for my query. it's the same if I put the code in ontick().same issue 

I don't have enough experience with TDS, only TickStory, but based on that experience when using the such 3rd party tools, the generated FXT files for the tester, don't have enough "history" data before the starting date, as would happen if you were using the plain vanilla original testing environment.

When using the normal environment you would have an initial history of 1000 bars before the starting date.

However, discussing 3rd party tools like TDS or TickStory is against forum policy.

You will have to discuss the issue on the 3rd party's forum instead.

 

I've put it in OnTick() as below  and the results are then same as in the example.jpg

(Sorry I got the posting all wrong)    


#property copyright ""
#property link      ""
#property version   ""
#property strict

#property tester_everytick_calculate

#define ENABLE_TEST_INDICATORS false

static    bool FirstEATick       = true   ;
static    bool NewDay            = false  ;
static    datetime CurrentDate   = 0      ;

//*********************************************************************************
//*********************************************************************************

int OnInit()
   {
      int Num = 0 ;
      if ( Num != 0) 
      {
         return (INIT_PARAMETERS_INCORRECT) ;
      }
      TesterHideIndicators(!ENABLE_TEST_INDICATORS);
      return(INIT_SUCCEEDED);
   }

//**************************************************************************************
//**************************************************************************************

void OnDeinit(const int reason)
   {
//    Comment ("");
   }

//**************************************************************************************
//**************************************************************************************

void OnTick()    
   {
   
   if (FirstEATick) // Default = true
       {
         NewDay      = true ;
         CurrentDate = ( iTime(Symbol(),PERIOD_D1,0)) ;
       }

   if (!FirstEATick)
       {
         NewDay      = false ;
         if (iTime(Symbol(),PERIOD_D1,0) != CurrentDate )
            {
               CurrentDate = ( iTime(Symbol(),PERIOD_D1,0)) ;
               NewDay      = true ;
            }   
       }

      if ( NewDay ) 
         {
            Print (CurrentDate);
         }


     FirstEATick  = false ;
     NewDay       = false ;
 
  }  
 
CharlieDenver #: I've put it in OnTick() as below  and the results are then same as in the example.jpg (Sorry I got the posting all wrong)    

I am going to assume that the test is not running on the daily chart as you have explicitly referenced PERIOD_D1.

If that is the case, then you have not synchronised your data, especially in this case where using a 3rd party tool like TDS does not guarantee that the HST data files have the same valid information as the tick data and current timeframe simulated by TDS.

There are certain specifics that need to be taken into account when using TDS and other such tools that inject code into MetaTrader and alter its functionality.

I will also repeat, that this discussion cannot continue because discussing these 3rd party tools here is against forum policy.

So, please take it up on their forum instead.

 

OK - thanks for that

I wasn't sure if it was coding issue or a data issue

Especially as I'm adding data onto the end and I know the data is there

Hey Ho - I'll get round it 

Just thought I'd ask 

Thank you 

 

Data aside then - 

All I'm actually trying to do is get a reliable method of defining a new day so I can populate my array's

but, I'm hitting this issue above when I move the dates on  

I'm using 1 minute charts but not controlling bar open so using tick data 

 
  1. static    bool FirstEATick       = true   ;
    static    bool NewDay            = false  ;
    static    datetime CurrentDate   = 0      ;
    Global variables are always static.
  2.    if (FirstEATick) // Default = true
           {
             NewDay      = true ;
             CurrentDate = ( iTime(Symbol(),PERIOD_D1,0)) ;
           }
    
       if (!FirstEATick)
    Why do you test for both? Either it is or it is not. An “if .. else” is more logical.
  3. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

    On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
              Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020)
              Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019)
              Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum #2 (2018)
              SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019)

  4. You don't need the D1 chart, get read the current date.
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)