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:

http://s32.postimg.org/3q4fi9cpx/screenshot_1936.png


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.

    if(Ask-Bid>_Point*Maximum_Spread)
      return;

The code will look like that:
http://s32.postimg.org/xqgp4eisl/screenshot_1940.png





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)

http://s32.postimg.org/5yrsr2ylh/screenshot_1938.png


2. Add the following check in the ManageOpen function.

   MqlTick tick;
   SymbolInfoTick(_Symbol,tick);
   if(tick.ask-tick.bid>_Point*Maximum_Spread)
      return;

http://s32.postimg.org/cqmt7ocyt/screenshot_1939.png

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?

Re: Protection - Maximum Spread

I wanted to set a criteria ... if spread is greater than allowable spread, don't trade.

Is this post still relevant ?  I couldn't find ManageOpen in the EA generated by FSB Pro.

If this post is no long relevant, what is the open logic that I can use to prevent trading when spread is too high ?

Re: Protection - Maximum Spread

This thread is for the Expert Advisor Studio experts.

You don't need this for FSB Pro. You can do it there with the Spread Level Pro indicator.