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:
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)
- www.mql5.com
if(PERIOD_CURRENT==PERIOD_M1) { Comment("M1"); }
but it doesn't show any thing
- Of course, it doesn't. PERIOD_CURRENT is zero and PERIOD_M1 is one and zero never equals one.
-
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) );
- 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
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