Excluding PERIOD_M12 from mq5 Testing.

 
Hello fellow programmers, first of all thanks for reading.

I have a dilemma, the thing is that I use the "Only Open Prices" modeling in the strategy tester and in the optimizer for more speed. The issue is that since I can only use temporalities that are non-multiple timeframes as it says in this section...

  • In the tested Expert Advisor, you cannot access data of the timeframe lower than that used for testing/optimization. For example, if you run testing/optimization on the H1 period, you can access data of H2, H3, H4 etc., but not M30, M20, M10 etc. In addition, the higher timeframes that are accessed must be multiple of the testing timeframe. For example, if you run testing in M20, you cannot access data of M30, but it is possible to access H1. These limitations are connected with the impossibility to obtain data of lower or non-multiple timeframes out of the bars generated during testing/optimization.
  • Limitations on accessing data of other timeframes also apply to other symbols whose data are used by the Expert Advisor. In this case the limitation for each symbol depends on the first timeframe accessed during testing/optimization. Suppose, during testing on EURUSD H1, an Expert Advisor accesses data of GBPUSD M20. In this case the Expert Advisor will be able to further use data of EURUSD H1, H2, etc., as well as GBPUSD M20, H1, H2 etc.

So, when I use different timeframes not allowed in the strategy tester or in the optimizer I get the error...but if I use the allowed temporalities if it works.

The problem comes when I optimize, it specifically uses the PERIOD_M12, so the tests give an error and the optimization ends in 1 minute due to the errors of the use of this temporality not allowed by "Only Open Prices".

so I've tried different ways to remove the PERIOD_M12 from my optimizations without success.

One of my attempts was to check if the periods used by the optimizer were all but PERIOD_M12 by using it in the OnInit() It works but as the "init" returns error several times the optimization ends without further ado., attached code:

//input ENUM_TIMEFRAMES Period_AC           = PERIOD_M5; // AC Timeframe
//---
bool checkTimeframePeriods()
  {
   int allowedPeriods[] = {PERIOD_M5, PERIOD_M10, PERIOD_M15, PERIOD_M20, PERIOD_M30,
                           PERIOD_H1, PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6,
                           PERIOD_H8, PERIOD_H12, PERIOD_D1, PERIOD_W1, PERIOD_MN1
                          };

   int periodsToCheck[] = {Period_AC, Period_AD, etc,//...many period variables.
                          };

   int allowedPeriodsSize = ArraySize(allowedPeriods);
   int periodsToCheckSize = ArraySize(periodsToCheck);

   for(int i = 0; i < periodsToCheckSize; i++)
     {
      bool isInAllowedPeriods = false;

      for(int j = 0; j < allowedPeriodsSize; j++)
        {
         if(periodsToCheck[i] == allowedPeriods[j])
           {
            isInAllowedPeriods = true;
            break;
           }
        }

      if(!isInAllowedPeriods)
        {
         return false;
        }
     }

   return true;
  }
//---

int OnInit()
  {
//---
   if(checkTimeframePeriods() == false)
     {
      return(INIT_FAILED);
      //return(INIT_PARAMETERS_INCORRECT);
      ExpertRemove();
     }
//---
  }

Another attempt was to create my own enum_timeframes but without success....

//---
enum ENUM_MY_TIMEFRAMES
  {
   MY_TIMEFRAME_M5 = 0,
   MY_TIMEFRAME_M10 = 1,
   MY_TIMEFRAME_M15 = 2,
   MY_TIMEFRAME_M20 = 3,
   MY_TIMEFRAME_M30 = 4,
   MY_TIMEFRAME_H1 = 5,
   MY_TIMEFRAME_H2 = 6,
   MY_TIMEFRAME_H3 = 7,
   MY_TIMEFRAME_H4 = 8,
   MY_TIMEFRAME_H6 = 9,
   MY_TIMEFRAME_H8 = 10,
   MY_TIMEFRAME_H12 = 11,
   MY_TIMEFRAME_D1 = 12,
   MY_TIMEFRAME_W1 = 13,
   MY_TIMEFRAME_MN1 = 14,
  };

input  ENUM_MY_TIMEFRAMES     settimeframe     = MY_TIMEFRAME_M5;

ENUM_TIMEFRAMES GetTimeframe()
  {
   switch(settimeframe)
     {
      case MY_TIMEFRAME_M5:
         return PERIOD_M5;
         break;
      case MY_TIMEFRAME_M10:
         return PERIOD_M10;
         break;
      case MY_TIMEFRAME_M15:
         return PERIOD_M15;
         break;
      case MY_TIMEFRAME_M20:
         return PERIOD_M20;
         break;
      case MY_TIMEFRAME_M30:
         return PERIOD_M30;
         break;
      case MY_TIMEFRAME_H1:
         return PERIOD_H1;
         break;
      case MY_TIMEFRAME_H2:
         return PERIOD_H2;
         break;
      case MY_TIMEFRAME_H3:
         return PERIOD_H3;
         break;
      case MY_TIMEFRAME_H4:
         return PERIOD_H4;
         break;
      case MY_TIMEFRAME_H6:
         return PERIOD_H6;
         break;
      case MY_TIMEFRAME_H8:
         return PERIOD_H8;
         break;
      case MY_TIMEFRAME_H12:
         return PERIOD_H12;
         break;
      case MY_TIMEFRAME_D1:
         return PERIOD_D1;
         break;
      case MY_TIMEFRAME_W1:
         return PERIOD_W1;
         break;
      case MY_TIMEFRAME_MN1:
         return PERIOD_MN1;
         break;
     }
   return 0;
  }
//---

Thank you for reading. I would like help on how to avoid optimization with PERIOD_M12.

 
Hello, i use this format to filter out time frames:
//time frame enumeration 
enum en_TF
  {
   M1,
   M5,
   M15,
   M30,
   H1
  };
// converting the enum values to Time frame variables function 
ENUM_TIMEFRAMES ConvertTF(en_TF ptimeFrame)
  {
   switch(ptimeFrame)
     {
      case M1:
         return PERIOD_M1;
      case M5:
         return PERIOD_M5;
      case M15:
         return PERIOD_M15;
      case M30:
         return PERIOD_M30;
      case H1:
         return PERIOD_H1;
      default:
         return PERIOD_M15;
     }
  }
It's similar to what you did but i code it in a function that takes in an enum variable as a parameter. It worked in my code feel free to give a try.
 
Manuel Arturo Gonzales Espinosa:
Hello fellow programmers, first of all thanks for reading.

I have a dilemma, the thing is that I use the "Only Open Prices" modeling in the strategy tester and in the optimizer for more speed. The issue is that since I can only use temporalities that are non-multiple timeframes as it says in this section...

  • In the tested Expert Advisor, you cannot access data of the timeframe lower than that used for testing/optimization. For example, if you run testing/optimization on the H1 period, you can access data of H2, H3, H4 etc., but not M30, M20, M10 etc. In addition, the higher timeframes that are accessed must be multiple of the testing timeframe. For example, if you run testing in M20, you cannot access data of M30, but it is possible to access H1. These limitations are connected with the impossibility to obtain data of lower or non-multiple timeframes out of the bars generated during testing/optimization.
  • Limitations on accessing data of other timeframes also apply to other symbols whose data are used by the Expert Advisor. In this case the limitation for each symbol depends on the first timeframe accessed during testing/optimization. Suppose, during testing on EURUSD H1, an Expert Advisor accesses data of GBPUSD M20. In this case the Expert Advisor will be able to further use data of EURUSD H1, H2, etc., as well as GBPUSD M20, H1, H2 etc.

So, when I use different timeframes not allowed in the strategy tester or in the optimizer I get the error...but if I use the allowed temporalities if it works.

The problem comes when I optimize, it specifically uses the PERIOD_M12, so the tests give an error and the optimization ends in 1 minute due to the errors of the use of this temporality not allowed by "Only Open Prices".

so I've tried different ways to remove the PERIOD_M12 from my optimizations without success.

One of my attempts was to check if the periods used by the optimizer were all but PERIOD_M12 by using it in the OnInit() It works but as the "init" returns error several times the optimization ends without further ado., attached code:

Another attempt was to create my own enum_timeframes but without success....

Thank you for reading. I would like help on how to avoid optimization with PERIOD_M12.

It may not be what you want! But try OHLC 1min. It is fast and accurate.

 
  1. Saad Janah #: i use this format to filter out time frames:
    Your code
    simplified
    //time frame enumeration 
    enum en_TF
      {
       M1   = PERIOD_M1,  // 1 Minute
       M5   = PERIOD_M5,  // 5 Minute
       M15  = PERIOD_M15, // 15 Minute
       M30  = PERIOD_M30, // 30 Minute
       H1   = PERIOD_H1   // 1 Hour
      };
    // converting the enum values to Time frame variables function 
    ENUM_TIMEFRAMES ConvertTF(en_TF ptimeFrame){ return ENUM_TIMEFRAMES(ptimeFrame); }
    
  2. See also

    Because the enumerations are not sequential, you can not increment/decrement them to get the next larger/smaller one.
              Why are MT5 ENUM_TIMEFRAMES strange? - General - MQL5 programming forum - Page 2 #11 (2020)