_Period not work in MQL5

 

Hello friends

It seems new version of MQL5 have problem to get the value of Period, I have tried both " Period()  ,  _Period "  But the out come is wrong

I write this simple code, and change time frame to check the result, But the out come is Wrong !!!

I use MQL5 version 3030


int OnInit()
  {

    Print(" result period : ",Period());

   return(INIT_SUCCEEDED);
  }
Documentation on MQL5: Integration / MetaTrader for Python / order_calc_margin
Documentation on MQL5: Integration / MetaTrader for Python / order_calc_margin
  • www.mql5.com
order_calc_margin - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Seyed Hadi Ghoreishimedyseh :

Hello friends

It seems new version of MQL5 have problem to get the value of Period, I have tried both " Period()  ,  _Period "  But the out come is wrong

I write this simple code, and change time frame to check the result, But the out come is Wrong !!!

I use MQL5 version 3030

That's right, there are no mistakes. ENUM_TIMEFRAMES is an enumeration.

Example:

//+------------------------------------------------------------------+
//|                                              ENUM_TIMEFRAMES.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.002"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ENUM_TIMEFRAMES timeframes_array[22]=
     {
      PERIOD_CURRENT,
      PERIOD_M1,PERIOD_M2,PERIOD_M3,
      PERIOD_M4,PERIOD_M5,PERIOD_M6,
      PERIOD_M10,PERIOD_M12,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
     };
   string descriptions_array[22]=
     {
      "Current timeframe",
      "1 minute","2 minutes","3 minutes",
      "4 minutes","5 minutes","6 minutes",
      "10 minutes","12 minutes","15 minutes",
      "20 minutes","30 minutes","1 hour",
      "2 hours","3 hours","4 hours",
      "6 hours","8 hours","12 hours",
      "1 day","1 week","1 month"
     };
   int size=ArraySize(timeframes_array);
   for(int i=0; i<size; i++)
      Print(i,": \"",EnumToString(timeframes_array[i]),"\" '",timeframes_array[i],"' \"",descriptions_array[i],"\"");
  }
//+------------------------------------------------------------------+
Files:
 
Vladimir Karputov #:

That's right, there are no mistakes. ENUM_TIMEFRAMES is an enumeration.

Example:

Thanks Vladimir.

But I want to get current chart Time frame value . The only way is Period(). But it do not show correct result. how can I get Current chart Time frame value ?
 
Seyed Hadi Ghoreishimedyseh # :
Thanks  Vladimir.

But I want to get current chart Time frame value . The only way is Period(). But it do not show correct result. how can I get Current chart Time frame value ?

Period () shows exactly the current timeframe. There are no digits '1', '2' ... instead there are ENTRY ITEMS: 'PERIOD_M1', 'PERIOD_M2', 'PERIOD_M3' ...

 

Read the help: ENUM_TIMEFRAMES enumeration

ENUM_TIMEFRAMES

ID

Description

PERIOD_CURRENT

Current timeframe

PERIOD_M1

1 minute

PERIOD_M2

2 minutes

PERIOD_M3

3 minutes

PERIOD_M4

4 minutes

PERIOD_M5

5 minutes

PERIOD_M6

6 minutes

PERIOD_M10

10 minutes

PERIOD_M12

12 minutes

PERIOD_M15

15 minutes

PERIOD_M20

20 minutes

PERIOD_M30

30 minutes

PERIOD_H1

1 hour

PERIOD_H2

2 hours

PERIOD_H3

3 hours

PERIOD_H4

4 hours

PERIOD_H6

6 hours

PERIOD_H8

8 hours

PERIOD_H12

12 hours

PERIOD_D1

1 day

PERIOD_W1

1 week

PERIOD_MN1

1 month


Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Chart Timeframes - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. Seyed Hadi Ghoreishimedyseh #: But I want to get current chart Time frame value . The only way is Period(). But it do not show correct result. how can I get Current chart Time frame value ?
    ENUM_TIMEFRAMES tf = ENUM_TIMEFRAMES(_Period);
  2. Seyed Hadi Ghoreishimedyseh:   But the out come is wrong
    It does not “come out wrong.” It is not a “wrong value.” It is an enumeration; its value is irrelevant. Its value is not in minutes; use PeriodSeconds(tf)/60 if you want that.
 
Seyed Hadi Ghoreishimedyseh #:
Thanks Vladimir.

But I want to get current chart Time frame value . The only way is Period(). But it do not show correct result. how can I get Current chart Time frame value ?

Just create your own function like:

int eTF2minTF( const ENUM_TIMEFRAMES tf ) {
   switch(tf) {
      case PERIOD_CURRENT: return(0);
      case PERIOD_M1:  return(1);
      case PERIOD_M2:  return(2);
      case PERIOD_M3:  return(3);
      case PERIOD_M4:  return(4);      
      case PERIOD_M5:  return(5);
      case PERIOD_M6:  return(6);
      case PERIOD_M10: return(10);
      case PERIOD_M12: return(12);
      case PERIOD_M15: return(15);
      case PERIOD_M20: return(20);
      case PERIOD_M30: return(30);
      case PERIOD_H1:  return(60);
      case PERIOD_H2:  return(120);
      case PERIOD_H3:  return(180);
      case PERIOD_H4:  return(240);
      case PERIOD_H6:  return(360);
      case PERIOD_H8:  return(480);
      case PERIOD_H12: return(720);
      case PERIOD_D1:  return(1440);
      case PERIOD_W1:  return(10080);
      case PERIOD_MN1: return(43200);
   }
   return(-1);
}
int min = eTF2minTF(_Period);
 
Carl Schreiber #: Just create your own function like:

No need, use #define eTF2minTF(p) (PeriodSeconds(p)/60)

 

Sir,

is it possible to use higher TF for calculating in a specific timeframe?

for example : use M15 data on M1 TF.

Something Like This :

input ENUM_TIMEFRAMES    tf1             = 15;              // Time Frame (15)
ENUM_TIMEFRAMES(_Period) = tf1;

Thnaks

 
p4rnak #:

Sir,

is it possible to use higher TF for calculating in a specific timeframe?

for example : use M15 data on M1 TF.

Something Like This :

Thnaks

I Think I Should Use Barshift.

Right?