How to add new indicator in mt5

To add a new indicator in MetaTrader 5 (MT5), you can follow these steps:

Method 1: Using the built-in indicator wizard

  1. Open MetaTrader 5 and navigate to the "Indicators" tab in the "Navigator" window.
  2. Right-click on the "Indicators" folder and select "New Indicator" from the context menu.
  3. In the "New Indicator" window, select the type of indicator you want to create (e.g., Moving Average, RSI, etc.).
  4. Fill in the required parameters for the indicator (e.g., period, price, etc.).
  5. Click "OK" to create the indicator.

Method 2: Using the MQL5 programming language

  1. Open the MetaEditor (the built-in code editor in MT5) by clicking on "File" > "New" > "MQL5 Program" or by pressing Ctrl + Shift + E.
  2. Create a new file and name it (e.g., "MyIndicator.mq5").
  3. In the file, write the code for your indicator using the MQL5 programming language. You can use the built-in functions and libraries provided by MT5.
  4. Compile the code by clicking on "Build" > "Compile" or by pressing F7.
  5. If the compilation is successful, the indicator will be added to the "Indicators" folder in the "Navigator" window.

Example code for a simple moving average indicator

Here is an example code for a simple moving average indicator:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Script deinit function                                           |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}

//+------------------------------------------------------------------+
//| Script tick function                                            |
//+------------------------------------------------------------------+
void OnTick()
{
   double ma = iMA(Symbol(), PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, 0);
   PlotChar(ma, "MA", 0, 0, 0);
}

This code creates a simple moving average indicator that calculates the 20-period simple moving average of the current symbol and plots it on the chart.

Tips and resources