how to show chart period current in Comment

 

hi

I write an expert that I want in this expert it shows chart current period I wrote below code that if I select M1 time frame it shows M1 in:

    if(PERIOD_CURRENT==PERIOD_M1)
      {
       Comment("M1");     
      }


but it doesn't show any thing

can any one help me?

Best regards

Neda

 
Neda shahbazi:

hi

I write an expert that I want in this expert it shows chart current period I wrote below code that if I select M1 time frame it shows M1 in:


but it doesn't show any thing

can any one help me?

Best regards

Neda


Comment(Period());
 
Neda shahbazi:

hi

I write an expert that I want in this expert it shows chart current period I wrote below code that if I select M1 time frame it shows M1 in:


but it doesn't show any thing

can any one help me?

Best regards

Neda

Your condition is always false because PERIOD_CURRENT=0 and PERIOD_M1=1. See the documentation: https://www.mql5.com/en/docs/constants/chartconstants/enum_timeframes

Your condition should be like:

if(ChartPeriod()==PERIOD_M1)

if you want to find out the timeframe from the current chart you can use this condition:

if(_Period==PERIOD_M1)
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
All predefined timeframes of charts have unique identifiers. The PERIOD_CURRENT identifier means the current period of a chart, at which a mql5-program is running.
 
Neda shahbazi:
   if(PERIOD_CURRENT==PERIOD_M1)
      {
       Comment("M1");     
      }

but it doesn't show any thing

  1. Of course, it doesn't. PERIOD_CURRENT is zero and PERIOD_M1 is one and zero never equals one.
  2. string   as_string(ENUM_TIMEFRAMES period){
       if(period == PERIOD_CURRENT)  period   = (ENUM_TIMEFRAMES) _Period;
       string   period_xxx  = EnumToString(period);                // PERIOD_XXX
       return StringSubstr(period_xxx, 7);                         // XXX
    }
    string   as_string(ENUM_APPLIED_PRICE p, int len=0){
       string price_XXX = EnumToString(p);                         // PRICE_XXX
       return StringSubstr(price_XXX, 6, len);                     // XXX
    }
    string   as_string(ENUM_MA_METHOD p, int len=0){
       string mode_XXX = EnumToString(p);                          // MODE_XXX
       return StringSubstr(mode_XXX, 5, len);                      // XXX
    }
    ⋮
       Comment( as_string(PERIOD_CURRENT) );

 
William Roeder:
  1. Of course, it doesn't. PERIOD_CURRENT is zero and PERIOD_M1 is one and zero never equals one.

thanks your codes are completely what I wanted