Timeframes Function - Need help

 

Hi programmers! I'm a newbie to MQL 5 language and I need help with using the  " ENUM_TIMEFRAMES  Period();" function.

My objective : I need to write a simple script to determine the current chart timeframe using the  ENUM_TIMEFRAMES  Period(); function.

When I execute the script, I need an alert giving me the current chart timeframe in terms of ENUM Values example : 0( for current period), 1 (for one minute chart),2(for 2minute chart),3,4,5,6.... to the respective chart

I earlier used to get the correct result but something went wrong and I can't figure out what I did before.

this is my current code which is giving me an error:


//+------------------------------------------------------------------+

//|                                                         test.mq5 |

//|                                                         S        |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "S"

#property link      "https://www.mql5.com"

#property version   "1.00"

ENUM_TIMEFRAMES  Period();

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

//---

   Alert(ENUM_TIMEFRAMES Period());

  }

//+------------------------------------------------------------------+

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
 
ENUM_TIMEFRAMES  Period();

What is this supposed to do?

 Alert(ENUM_TIMEFRAMES Period());

You need a string for an Alert.

 
Keith Watford:

What is this supposed to do?

You need a string for an Alert.

Hello thanks for the response. 

well I didn't use a string type before when my script worked correctly before. For alerting the current time frame,  I only need the result as a number (ENUM_TIMEFRAME index number).

I found this function from https://www.mql5.com/en/docs/check/period

In this above link they have explained exactly how to use it to get the current chart timeframe. But I'm just lost somewhere around that I can't get it right

Please help me 

Documentation on MQL5: Checkup / Period
Documentation on MQL5: Checkup / Period
  • www.mql5.com
Period - Checkup - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
What are you trying to do?
 
Keith Watford:
What are you trying to do?

I want to get the ENUM index numerical value for the the current timeframe, when I run my script on a forex chart.

example : I get an alert saying "1"  which means I'm in 1 minute chart

 
  Alert(Period());
 
Keith Watford:

Thats giving me the basic chart time frame value which is not the ENUM_TIMEFRAME  Index value.

period function itself without enum returns strange values after m30 chart like 16385 for 1 hour chart.

I want to obtain the ENUM index value

May I also know what parameters can we insert into period() function ?
Documentation on MQL5: Checkup / Period
Documentation on MQL5: Checkup / Period
  • www.mql5.com
Period - Checkup - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
16385 is the numerical representation of the H1 time frame
 

If you want the actual string.

Alert(EnumToString(Period()));
 
Keith Watford:

If you want the actual string.

Problem solved! Thanks a ton. I was stucked with this for days and was stressed out so much! I know, it's just a simple thing, but it means a lot to me. Appreciate it man! 
Reason: