Different timeframe values in execution and debug

 

Good morning

I have a problem that doesn't help me write my code.

Here is a test code which reproduces the problem on my side

it will just display in Comment() the choice of user

 input    ENUM_TIMEFRAMES   g_TimeFrameInp  = PERIOD_D1 ;

and display the current outstanding value selected on the terminal

It works well, no problem at this level. The result is on the terminal is code compliant.

What concerns me is when I am in test mode with the breakpoints to see the values in the debug.
Put a breakpoint right on the string below the input and look at the value

 input    ENUM_TIMEFRAMES   g_TimeFrameInp  = PERIOD_D1 ;
 string   g_timeframeStr;

One might expect to see in debug Period_D1
Knowing that in addition, the inputs are considered as constants.

well at home, whatever I can put in the input, I don't have D1, and if I have D1 and to test, I put something else, well the value in debug will remain in D1

Why does the value in test mode not take the value given in the input?

This strange behavior is not related to the test parameter selection.


Here is the code so you can test

 //+------------------------------------------------------------------+
 //|                                         Test Enum_Timeframes.mq5 |
 //|                                  Copyright 2023, MetaQuotes Ltd. |
 //|                                             https://www.mql5.com |
 //+------------------------------------------------------------------+
 #property copyright "Copyright 2023, MetaQuotes Ltd."
 #property link        "https://www.mql5.com"
 #property version    "1.00"
 #property indicator_chart_window

 input    ENUM_TIMEFRAMES   g_TimeFrameInp  = PERIOD_D1 ;
 string   g_timeframeStr;
 //+------------------------------------------------------------------+
 //| Custom indicator initialization function                         |
 //+------------------------------------------------------------------+
 int OnInit () {
 //--- indicator buffers mapping


 //--- 
   return ( INIT_SUCCEEDED );
}
 //+------------------------------------------------------------------+
 //| Custom indicator iteration function                              |
 //+------------------------------------------------------------------+
 int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[]) {
 //--- 




   string i_message = "" ;
  i_message += StringFormat ( "Value of g_TimeFrameInp: %s \n" ,  Test_EnumTimeToString( g_TimeFrameInp));
  i_message += StringFormat ( "Value of _Period: %s" ,            Test_UtInProgress( _Period ));
   Comment ( i_message);

 //--- return value of prev_calculated for next call 
   return (rates_total);
}


 //+------------------------------------------------------------------+
 //|   Test_EnumTimeToString                                          |
 //+------------------------------------------------------------------+
 string Test_EnumTimeToString( ENUM_TIMEFRAMES tf) {
   switch ( g_TimeFrameInp) {
   case PERIOD_M1 :
     return    "M1" ;
     break ;
   case PERIOD_M2 :
     return    "M2" ;
     break ;
   case PERIOD_M3 :
     return    "M3" ;
     break ;
   case PERIOD_M4 :
     return    "M4" ;
     break ;
   case PERIOD_M5 :
     return    "M5" ;
     break ;
   case PERIOD_M6 :
     return    "M6" ;
     break ;
   case PERIOD_M10 :
     return    "M10" ;
     break ;
   case PERIOD_M12 :
     return    "M12" ;
     break ;
   case PERIOD_M15 :
     return    "M15" ;
     break ;
   case PERIOD_M20 :
     return    "M20" ;
     break ;
   case PERIOD_M30 :
     return    "M30" ;
     break ;
   case PERIOD_H1 :
     return    "H1" ;
     break ;
   case PERIOD_H2 :
     return    "H2" ;
     break ;
   case PERIOD_H3 :
     return    "H3" ;
     break ;
   case PERIOD_H4 :
     return    "H4" ;
     break ;
   case PERIOD_H6 :
     return    "H6" ;
     break ;
   case PERIOD_H8 :
     return    "H8" ;
     break ;
   case PERIOD_H12 :
     return    "H12" ;
     break ;
   case PERIOD_D1 :
     return    "D1" ;
     break ;
   case PERIOD_W1 :
     return    "W1" ;
     break ;
   case PERIOD_MN1 :
     return    "MN1" ;
     break ;
   default :
     return    "Unknown" ;
  }
}
 //+------------------------------------------------------------------+
 //|   Test_UtInProgress                                              |
 //+------------------------------------------------------------------+
 string Test_UtInProgress( int tf) {
   switch (tf) {
   case 1 :
     return "M1" ;
   case 2 :
     return "M2" ;
   case 3 :
     return "M3" ;
   case 4 :
     return "M4" ;
   case 5 :
     return "M5" ;
   case 6 :
     return "M6" ;
   case 10 :
     return "M10" ;
   case 15 :
     return "M15" ;
   case 20 :
     return "M20" ;
   case 30 :
     return "M30" ;
   case 16385 :
     return "H1" ;
   case 16386 :
     return "H2" ;
   case 16387 :
     return "H3" ;
   case 16838 :
     return "H4" ;
   case 16390 :
     return "H6" ;
   case 16392 :
     return "H8" ;
   case 16396 :
     return "H12" ;
   case 16408 :
     return "D1" ;
   case 32769 :
     return "W1" ;
   case 49153 :
     return "MN" ;
   default :
     return "Unknown" ;
  }
}
 //+------------------------------------------------------------------+
 
damn I forgot
Here is my current version

 

I myself am still a bit confused about the settings of the input parameter of an EA, the debugger, strategy tester ...

The input parameters like yours:


are set in the Strategy Tester tab Input (no matter what is written in the EA):


That is why I often define parameters I am working on in OnInit() so that they are set by recompilation.

The timeframe and Symbol is taken from Editor -> Tools -> Options -> Debugger:


If the user chooses another timeframe than _Period you need to set the chart properties acc. to this in Oninit() but I don't know how the debugger and the Stra.-Tester are dealing with this.