Highliting MQL4 and MQL5 Code

Enivid

Administrator
Staff member
Nov 30, 2008
14,542
651
144
Odessa
www.earnforex.com
Dear Forum users!

I am glad to announce that EarnForex.com Forum now fully supports MQL4 and MQL5 highlighting. If you insert a peace of code, be it indicator, expert advisor, script or something else, written in MQL4 or MQL5, you can now highlight with a simple highlight tag.

For MQL4:
[code=mql4][/code]

For MQL5:
[code=mql5][/code]

Or simply use the Insert Code option from the toolbar:

insert-code.png

And then select the right language - MQL4, for example:

mql4-code.png

Our forum is currently the only forum supporting full MQL4/MQL5 highlighting. It closely resembles the highlighting seen in MQL Editor. Even official MetaQuotes forums can't beat us here: MQL4.com's highlighting is a joke, MQL5.com's is good but lacks some features. So, if you need to discuss MQL code, EarnForex.com Forum is your choice. If you want to discuss pink unicorns - choose other forums.

Now, it's recommended to use highlighting when you write your posts. After all, something like this:

Code:
#property copyright "EarnForex.com"
#property link      "http://www.earnforex.com"
#property version   "1.00"

#property description "Displays the Market Profile indicator for the daily trading sessions."

#property indicator_chart_window

input datetime  StartFromDate  = D'';
input bool        StartFromToday = true;
input int         DaysToCount    = 2; // Number of days for which to count the Market Profile
input int         ColorScheme    = 0; // 0 - Blue to Red, 1 - Red to Green, 2 - Green to Blue
input color     MedianColor    = clrWhite;
input color     ValueAreaColor = clrWhite;

int DigitsM;                     // Amount of digits normalized for standard 4 and 2 digits after dot
datetime StartDate;             // Will hold either StartFromDate or Time[0]
double onetick;                 // One normalized pip
int SecondsInPeriod;         // Will hold calculated amount of seconds in the selected timeframe period
bool FirstRunDone = false; // If true - OnCalculate() was already executed once

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorSetString(INDICATOR_SHORTNAME, "MarketProfile");

    // Normalizing the digits to standard 4- and 2-digit quotes
    if (_Digits == 5) DigitsM = 4;
    else if (_Digits == 3) DigitsM = 2;
    else DigitsM = _Digits;

    if (_Period == PERIOD_M30) SecondsInPeriod = 1800;
    if (_Period == PERIOD_M15) SecondsInPeriod = 900;
    if (_Period == PERIOD_M5) SecondsInPeriod = 300;

    onetick = NormalizeDouble(1 / (MathPow(10, DigitsM)), DigitsM);
}

Looks much better when it is highlighted:

MQL5:
#property copyright "EarnForex.com"
#property link      "http://www.earnforex.com"
#property version   "1.00"
 
#property description "Displays the Market Profile indicator for the daily trading sessions."
 
#property indicator_chart_window
 
input datetime  StartFromDate  = D'';
input bool        StartFromToday = true;
input int         DaysToCount    = 2; // Number of days for which to count the Market Profile
input int         ColorScheme    = 0; // 0 - Blue to Red, 1 - Red to Green, 2 - Green to Blue
input color     MedianColor    = clrWhite;
input color     ValueAreaColor = clrWhite;
 
int DigitsM;                     // Amount of digits normalized for standard 4 and 2 digits after dot
datetime StartDate;             // Will hold either StartFromDate or Time[0]
double onetick;                 // One normalized pip
int SecondsInPeriod;         // Will hold calculated amount of seconds in the selected timeframe period
bool FirstRunDone = false; // If true - OnCalculate() was already executed once
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
{
   IndicatorSetString(INDICATOR_SHORTNAME, "MarketProfile");
 
    // Normalizing the digits to standard 4- and 2-digit quotes
    if (_Digits == 5) DigitsM = 4;
    else if (_Digits == 3) DigitsM = 2;
    else DigitsM = _Digits;
 
    if (_Period == PERIOD_M30) SecondsInPeriod = 1800;
    if (_Period == PERIOD_M15) SecondsInPeriod = 900;
    if (_Period == PERIOD_M5) SecondsInPeriod = 300;
 
    onetick = NormalizeDouble(1 / (MathPow(10, DigitsM)), DigitsM);
}

If you find any bugs or glitches in the MQL highlighting system or would like to suggest some other features, please post your reply here.
 
Last edited:

Enivid

Administrator
Staff member
Nov 30, 2008
14,542
651
144
Odessa
www.earnforex.com
I have updated the syntax highlighting feature to work properly with the MT4 input parameters, including ENUM parameters. It is something that even the official MQL4/5 forums lack. See example:

MQL4:
#property copyright "Copyright © 2009-2016, EarnForex.com"
#property link      "http://www.earnforex.com"
/*
   Kicks in when position reaches at least TrailingStop pips of profit.
*/
extern double TrailingStop = 5;
// Set it to some value above 0 to activate stop-loss
extern double StopLoss = 0;
int init()
{
   return(0);
}
int deinit()
{
   return(0);
}
int start()
{
  double PointValue;
  for (int i = 0; i < OrdersTotal(); i++)
  {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol()) continue; // Skipping positions in other currency pairs
      //Calculate the point value in case there are extra digits in the quotes
      if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) PointValue = 0.0001;
      else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) PointValue = 0.01;
      else PointValue = MarketInfo(OrderSymbol(), MODE_POINT);
      //Normalize trailing stop value to the point value
      double TSTP = TrailingStop * PointValue;
 
Last edited:
  • Like
Reactions: hayseed