Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Script | Timeframe to short name | MQL5 Library

Explore the latest free tools from the MQL5 community. Here's a new indicator, expert advisor, or script for MetaTrader.

Image for Timeframe to short name

This function gives me the shortened names of the timeframes

Example:

"M1" instead of "PERIOD_M1"


void OnStart()
  {
   ENUM_TIMEFRAMES timeframe = Period();
   string result = GetTimeframeShortName(timeframe);
   Comment(result);
   Print(result);
  }
//+------------------------------------------------------------------+
//| function to get timeframe short name |
//+------------------------------------------------------------------+
string GetTimeframeShortName(const ENUM_TIMEFRAMES timeframe)
  {
    switch(timeframe)
      {
        case PERIOD_M1: return "M1";
        case PERIOD_M2: return "M2";
        case PERIOD_M3: return "M3";
        case PERIOD_M4: return "M4";
        case PERIOD_M5: return "M5";
        case PERIOD_M6: return "M6";
        case PERIOD_M10: return "M10";
        case PERIOD_M12: return "M12";
        case PERIOD_M15: return "M15";
        case PERIOD_M20: return "M20";
        case PERIOD_M30: return "M30";
        case PERIOD_H1: return "H1";
        case PERIOD_H2: return "H2";
        case PERIOD_H3: return "H3";
        case PERIOD_H4: return "H4";
        case PERIOD_H6: return "H6";
        case PERIOD_H8: return "H8";
        case PERIOD_H12: return "H12";
        case PERIOD_D1: return "D1";
        case PERIOD_W1: return "W1";
        case PERIOD_MN1: return "MN1";
        default: return "";
      }
  }

    Capture price channel breakouts with the Price Channel Expert Advisor. Precise entries and exits. Explore now.

    Build better strategies with RobotFX professional tools – check them out.

    43357

    Best MetaTrader Indicators + Profitable Expert Advisors