Topic: Protection - Maximum Spread

Hello Traders,

If an Expert advisor is designed to work on a "normal" market, it may not trade well when something unusual happens (like unexpected brexit). Fortunately, it is relatively easy and safe to detect such unexpected market event by monitoring the spread.

Here is how to set a Maximum Spread protection to the expert advisors:

Expert Advisor for MT4

1. Add a Maximum Spread parameter to the expert.

Open the EA in the editor and the following line below the Magic_Number input parameter. It sets default spread protection 25 points. You can change the value in the code or when you run the EA.

static input int Maximum_Spread=25; // Maximum Spread (points)

The code looks like that:

2. Add a check for the market spread in the ManageOpen function. The following code will check the spread and if it is higher than the input parameter, the "return" command will terminate the position opening.


The code will look like that:

Expert Advisor for MT5

1. Add a Maximum Spread parameter to the expert below the Magic_Number input parameter:

static input int Maximum_Spread=25; // Maximum Spread (points)

2. Add the following check in the ManageOpen function.

   MqlTick tick;

Re: Protection - Maximum Spread

Hi Popov,

This spread level protection function is already not available? I exported the MT4 EA and opened it to edit, but these texts i dont see in the code. Should i add it same as like here? Or something changed and already not available this function?

Re: Protection - Maximum Spread

Hello Santaferes,

These are modifications you have to made alone.

The code exported from EA Studio is clean and simple. It is designed to allow easy modifications.

This topic is a guide how a trader to modify his export in order to implement Spread protection.

Re: Protection - Maximum Spread

just to confirm

this EA modification, works with portfolios?