Select Language

Create indicator

If you wish to create an indicator on MetaTrader4 (MT4) / MetaTrader5 (MT5), you can do so by using a tool called MetaEditor, which uses a special programming language for MT4/MT5 called MQL4/MQL5.

Here we will look at how to create an indicator on MT4/MT5.

Switch between MT4/MT5 tabs to check the steps for each.

mt4
mt5

Step 1

Click "Tools" in the menu and select "MetaQuotes Language Editor".

Open Options Open Options

Step 2

MetaEditor will be launched. Click the "New" button in the menu.

MetaEditor is launched MetaEditor is launched

Step 3

Select "Custom Indicator" and click "Next".

Create a custom indicator Create a custom indicator

Step 4

Enter the indicator name, author, and link to display. Configure the parameters as necessary and click "Next".

Properties of the custom indicator Properties of the custom indicator

Number

Item name

Descriptions

1

Name

The name of the indicator that you create.

2

Author

The author of the indicator.

3

Link

Enter the link of the indicator to display.

point Name and author will be displayed in settings

The registered name, author, and link information will be displayed on the indicator settings window.

Step 5

Set event handlers, which are the functions that are called if certain conditions are met.

Set event handlers Set event handlers

Number

Item name

Descriptions

1

OnCalculate
(...,open,high,low,close)

OnCalculate(...,open,high,low,close) is a function that is executed when ticks are updated. It retrieves open, high, low, and close prices, time, tick volume, volume, and spread necessary to calculate the indicator.

2

OnCalculate
(...,prices)

OnCalculate(prices) is a function that is executed when ticks are updated. It calculates the indicator using the applied price data selected in the parameter.

3

OnTimer

OnTimer is a function that runs at a specified time interval.

4

OnChartEvent

OnChartEvent is a function that handles events on a chart. It is executed when an event occurs on a chart, such as creating, deleting, moving, or editing an object.

Step 6

To display it in a sub-window, check the "Indicator in separate window" box. To set the minimum/maximum values for the sub-window, check the "Minimum" and "Maximum" boxes and enter the values.

Drawing properties of the custom indicator Drawing properties of the custom indicator

Step 7

To use an object in the indicator, click "Add". After specifying the name in the "Label" field, type in "Type", and color in "Colors", click "Finish".

Add an object Add an object

Step 8

Write an MQL4 program.

Write MQL4 program Write MQL4 program

Step 9

After writing the MQL4 program, click the "Compile" button on the menu.

Compile Compile

Step 10

After the compilation, the indicator created will appear in the designated folder in the Navigator.

Compilation completed Compilation completed

Step 11

Close the MetaEditor and go back to MT4. Check that the indicator created is in the Navigator on MT4.

The indicator created is in the Navigator The indicator created is in the Navigator

Step 1

Click the "Tools" in the menu and select the "MetaQuotes Language Editor".

MetaQuotes Language Editor MetaQuotes Language Editor

Step 2

The MetaEditor will be launched. Click the "New" button in the menu.

MetaEditor is launched MetaEditor is launched

Step 3

Select "Custom Indicator" and click "Next".

MetaEditor is launched MetaEditor is launched

Step 4

Enter the indicator name, author, and link to display. Configure the parameters as necessary and click "Next".

MetaEditor is launched MetaEditor is launched

Number

Item name

Descriptions

1

Name

The name of the indicator that you create.

2

Author

The author of the indicator.

3

Link

Enter the link of the indicator to display.

point Name and author will be displayed in settings

The registered name, author, and link information will be displayed on the indicator settings window.

Name and author will be displayed in settings Name and author will be displayed in settings

Step 5

Set event handlers, which are the functions that are called if certain conditions are met.

Event handlers Event handlers

Number

Item name

Descriptions

1

OnCalculate(...,open,high,low,close)

OnCalculate(...,open,high,low,close) is a function that is executed when ticks are updated. It retrieves open, high, low, and close prices, time, tick volume, volume, and spread necessary to calculate the indicator.

2

OnCalculate(...,prices)

OnCalculate(prices) is a function that is executed when ticks are updated. It calculates the indicator using the applied price data selected in the parameter.

3

OnTimer

OnTimer is a function that runs at a specified time interval.

4

OnChartEvent

OnChartEvent is a function that handles events on a chart. It is executed when an event occurs on a chart, such as creating, deleting, moving, or editing an object.

Step 6

To display it in a sub-window, check the "Indicator in separate window" box. To set the minimum/maximum values for the sub-window, check the "Minimum" and "Maximum" boxes and enter the values.

Indicator in separate window Indicator in separate window

Step 7

To use an object in the indicator, click "Add". After specifying the name in the "Label" field, type in "Type", and color in "Colors", click "Finish".

Use an object in the indicator Use an object in the indicator

Step 8

Write MQL5 program.

MQL5 program MQL5 program

Step 9

After writing the MQL5 program, click the "Compile" button on the menu.

The Compile button on the menu The Compile button on the menu

Step 10

After the compilation, the indicator created will appear in the designated folder in the Navigator.

The indicator created is in the Navigator The indicator created is in the Navigator

Step 11

Close the MetaEditor and go back to MT5. Check that the indicator created is in the Navigator on MT5.

The indicator created is in the Navigator The indicator created is in the Navigator

Date

Created

 : 2022.10.11

Update

Last updated

 : 2024.08.28

Takayoshi Nakamaru

Manual production consultant, MBA

arrow
Takayoshi Nakamaru

Nakamaru is a manual production consultant at FINTECS, a company that specializes in creating manuals for their clients.
With a wide range of experience from fintech to entertainment, he presents what user-friendly manuals should be like.
He works with numerous large corporations as an external manual production project manager.

【Business information】
http://www.fintecs.co.jp/profile/

Supervisor

Akira Takagi

Systems engineer, MetaTrader administrator

arrow
Akira Takagi

After graduating from Computer Science at the Uninove, Brazil, in 2014, he has worked on various systems development projects.
He participated as a developer in the launch of forex services in 2019. Since then, he has also been involved in the development of MetaTrader plugins and APIs. He is certified by MetaQuotes as a MetaTrader5 Administrator and active in consulting and advisory as well.

Was this article helpful?

We hope you find this article useful. Any comments or suggestions will be greatly appreciated.  
We are also looking for writers with extensive experience in forex and crypto to join us.

please contact us at [email protected].

Thank you for your feedback.
Thank you for your feedback.

Disclaimer:arw

All information and content provided on this website is provided for informational purposes only and is not intended to solicit any investment. Although all efforts are made in order to ensure that the information is correct, no guarantee is provided for the accuracy of any content on this website. Any decision made shall be the responsibility of the investor and Myforex does not take any responsibility whatsoever regarding the use of any information provided herein.

The content provided on this website belongs to Myforex and, where stated, the relevant licensors. All rights are reserved by Myforex and the relevant licensors, and no content of this website, whether in full or in part, shall be copied or displayed elsewhere without the explicit written permission of the relevant copyright holder. If you wish to use any part of the content provided on this website, please ensure that you contact Myforex.

  • Facebook
  • Twitter
  • LINE

Myforex uses cookies to improve the convenience and functionality of this website. This website may include cookies not only by us but also by third parties (advertisers, log analysts, etc.) for the purpose of tracking the activities of users. Cookie policy

I agree
share
Share
Cancel