====== Export Expert Advisor ======
===== How to export an Expert Advisor =====
When you open a strategy in the **Editor**, you can export it as an Expert Advisor. To do it, click the **Expert Advisor** button in the toolbar, and a drop-down menu will give you options to export Expert Advisor for MetaTrader 4 and MetaTrader 5.
{{:eas-guide:export-expert-advisor.png?nolink|}}
There are several Export options:
* **Expert Advisor for MT4** - exports an Expert Advisor for MetaTrader 4;
* **Expert Advisor for MT5** - exports an Expert Advisor for MetaTrader 5;
The exported Expert Advisor is 100% native MQL code and doesn't require any third-party libraries or indicators to run.
{{youtube>XsObzXqOpzg?medium }}
===== How to load an Expert Advisor in MetaTrader =====
==== MetaTrader 4 ====
- Go to **File > Open Data Folder**
- From the folder list, open the **MQL4** folder
- Open the **Experts** folder
- Paste the Expert Advisor file
- Go back to MetaTrader
- Go to **Navigator** (if it's not open, open if from **View > Navigator**)
- In the **Navigator** box right-click. Click **Refresh** from the menu. Your expert should appear in the **Navigator** under **Expert Advisors**.
- Open the chart you want to place your Expert Advisor on
- To attach the Expert Advisor to the chart, drag-and-drop it from the **Navigator** box to the chart or double-click on the Expert Advisor
**Using different Magic Numbers**
When trading several Experts on the same symbol, they must differentiate between each others' positions. MetaTrader allows us to use a unique Magic Number for each Expert. EA studio will export Expert Advisors with a random Magic Number built-in in the Expert to differentiate its positions from other Experts when trading. However, it is up to you to ensure each Expert you trade on the same symbol has a different Magic Number. Should you have duplicate Magic Numbers, you can change the Magic Number in the Expert's code or from the **Inputs** options of the Expert.
==== MetaTrader 5 ====
- Go to **File > Open Data Folder**
- From the folder list, open the **MQL5** folder
- Open the **Experts** folder
- Paste the Expert Advisor file
- Go back to MetaTrader
- Go to **Navigator** (if it's not open, open if from **View > Navigator**)
- In the **Navigator** box right-click. click **Refresh** from the menu. Your expert should appear in the **Navigator** under **Expert Advisors**.
- In the **Navigator**, right-click on the Expert Advisor name. From the menu, choose **Modify**
- A code editor will open. From the top menu of the window, click **Compile**
- Close the code editor.
- To attach the Expert Advisor to the chart, drag and drop it from the **Navigator** box to the chart.
You cannot trade multiple Experts simultaneously on the same symbol in MT5.
The solution would be an MT5 Hedging account, which can trade several experts per symbol. If using this feature, set a different Magic Number for each Expert Advisor.
==== How to Run an Expert Advisor ====
A dialogue window will open when you drag and drop the Expert onto the chart. You can review the Expert Advisor options in the **Inputs** tab.
{{:eas-guide:export-expert-advisor-input.png?nolink|}}
=== Options ===
* **Magic Number** - a number MetaTrader uses to distinguish which position each expert belongs to.
* **Max spread protection (points)** - possibility to prevent trading on a high spread. The default value is zero, which means the protection is off. Set the desired value in points to engage the protection. For example, if you set 10, the Expert will open new positions only if the current spread is equal to or lower than 10. The Expert may try several times to execute the order. The Max spread protection does not affect the exit orders.
* **Min equity protection (currency)** - a protection which closes the current position and removes the Expert from the MetaTrader chart if the current Equity drops below the given number. The default value is zero, which indicates that the protection is off. Set the desired number in currency to engage the protection.
==== Backtest an Expert Advisor in the MetaTrader tester ====
You can test the Experts in the MetaTrader **Strategy tester** (**View > Strategy Tester**).
{{:eas-guide:export-metatrader-tester.png?nolink|}}
You should get the same result in the MetaTrader test as in EA Studio. If there is a discrepancy, check if you are using **the same data, spreads and commissions**. If there is still a discrepancy, please open a topic in the support forum.
~~DISQUS~~