Refer a friend

Adding scripts on MT4 enables traders to automate repetitive tasks such as trade execution, position size calculation, and more. It also allows traders to automatically close, open and modify orders in real-time, reducing the overall time and effort required. 

This article will discuss how traders can add scripts to MT4 with an in-depth step-wise guide.


What are scripts in MT4?

Scripts in MT4 are small programs written in MetaQuotes Language 4 (MQL4) that execute a specific task or function when triggered. They are useful for automating repetitive actions, performing calculations, or managing orders. Unlike Expert Advisors, scripts do not run continuously. Instead, they execute once and then stop.


Types of scripts  

Trade execution scripts 

These scripts are designed to execute specific trading actions automatically. For example, a script can be programmed to open a trade at a certain price level or close all open positions with a single command.

Position sizing scripts 

Position sizing scripts help determine the appropriate lot size for a trade based on predefined risk management criteria, such as a fixed percentage of account equity or a specific amount.

Order management scripts 

These scripts focus on managing existing orders. They can modify stop-loss and take-profit levels, trail stops, or adjust position sizes based on predefined rules.

Calculation scripts

Calculation scripts perform various calculations and generate outputs based on specific parameters. They can calculate indicators, custom formulas, or other mathematical calculations to assist in trading decisions.

Alert and notification scripts 

These scripts generate alerts or send notifications when specific market conditions are met. Traders can receive alerts about price levels, indicator crossovers, or other events to stay informed without constantly monitoring the charts.

Chart object creation scripts 

These scripts enable traders to create different types of chart objects, including lines, shapes, and text. With these scripts, traders can automate the process of drawing trend lines, support and resistance levels, Fibonacci retracement levels, or any other graphical analysis tools directly on the chart.


How to add scripts to MT4?

Downloading pre-existing scripts

1. Traders can go to the MQL5 community website to look for pre-existing scripts or find pre-existing scripts on other platforms

2. Launch the MetaTrader 4 platform on the computer (Note that scripts are not supported on MT4 WebTrader or mobile app)

3. Navigate to the top menu. Select File → Open Data Folder.

4. In the data folder, locate and open the folder named MQL4. This folder contains various MT4-related files, including scripts. Locate the subfolder called ‘scripts’ and open it.

5. Now, take the downloaded script file and paste the script file into the ‘scripts’ folder opened in the last step.

6. Close the data folder and reopen the MetaTrader 4 platform to ensure the script becomes activated and available.

7. Traders can find the newly added script in the Navigator window. To access the Navigator window, press Ctrl+N or click on the Navigator icon in the toolbar.

image source

8. Once the trader locates the script in the Navigator window, they can use it by either dragging and dropping it onto a specific chart or by double-clicking on the script’s name.

Creating a customized Script

1. Open the MetaTrader 4 platform and go to the Tools menu → Select MetaQuotes Language Editor. The MetaEditor will open, providing an integrated development environment for coding in MQL4.

image source

2. In the MetaEditor, click on File→ Select New, or use the shortcut Ctrl+N. This will create a new blank script file where one can start writing the code.

3. At the beginning of the script, one needs to define some basic properties. This includes specifying the script’s name, description, and required input parameters.

image source

4. Below the script properties, traders will have to write the actual code for the script. This will depend on the specific functionality the trader wants the script to perform.

image source

5. After writing the script code, save the File using a relevant name and extension (.mq4 or .mq5). Then, click the Compile button in the MetaEditor toolbar. The script will be compiled, and any errors or warnings will be displayed in the Errors and Warnings tabs at the bottom of the MetaEditor.

image source

6. Review any error messages or warnings in the Errors and Warnings tabs. Fix any syntax or logical errors in the code.

image source

7. After successfully compiling the script without errors, the trader can now deploy it in the MetaTrader 4 platform. Follow the steps mentioned earlier in this article on how to add scripts to MT4.

8. Open a chart in MetaTrader 4, drag and drop the script onto the chart, or double-click the script name in the Navigator window. The script will execute the code written. Monitor the output or any actions the script performs to ensure it behaves as intended.

image source


Streamline trading experience with MT4 scripts  

MT4 allows traders to add scripts which contributes to a better trading experience. The ability to customize scripts aligns with individual trading strategies, enabling traders to tailor their approach and execute trades seamlessly. It also allows traders to evaluate and refine their strategies before deploying them in live trading.

Sign up for a live account or try a demo account on Blueberry Markets today.


Disclaimer: All material published on our website is intended for informational purposes only and should not be considered personal advice or recommendation. Traders should carefully consider their objectives, financial situation, needs, and level of experience before entering into any margined transactions.

About The Author

Join us on Telegram
and get real-time
alerts on
Indices, Gold, Crypto
and Share CFDs

Join now for free
telegram cta
bbjam graphic

Sign up to
Blueberry Jam

Back up your trade positions with insights
and how-to-guides, straight to your
inbox every week

Thank you. You have successfully subscribed to Blueberry Jam!