convert string to enum function

 

I want to create a function that takes the string and returns the enum, but this function gives the following error. how can i convert string to enum?

error: begining bracket expected

enum TIMEFRAME(string timeframe)
{
  if(timeframe=="H1")        return(PERIOD_H1);
  else if(timeframe=="H4")   return(PERIOD_H4);
  else if(timeframe=="D1")   return(PERIOD_D1);   
  else                       return(PERIOD_CURRENT);
}
 
Farhad1:

I want to create a function that takes the string and returns the enum, but this function gives the following error. how can i convert string to enum?

error: begining bracket expected

ENUM_TIMEFRAMES FunctionName (string timeframe)
{
}
 
Keith Watford:

Tanks 

 
  1. Farhad1: I want to create a function that takes the string and returns the enum, but this function gives the following error. how can i convert string to enum?

    Simplify your code. Stop using strings. Use the enumeration and you are done. input ENUM_TIMEFRAMES timeframe = PERIOD_D1; No function needed, no conversion needed.

  2. See also Chartperiod() or period() value greater than 1 hour quite divergent from minute values. Incl. request table enhancement (mql5 documentation) - General - MQL5 programming forum #1 and #6 2020.08.28