#62853
richard
Participant

I had similar  concerns when I first started using EAS.  I “borrowed” some code from the other forum and played around with it till it did what I thought it should do.  It prevents the EA from entering / exiting if the spread is above a preset level. If you are not in a position and price spikes you will not be entered into the position until spread drops below your preset level and if you are in a position you won’t get taken out with a spike.

I am not a coder so you will have to verify that it is working correctly in saying that I carried out many side by side tests and I believe it is working correctly.

I found that initially the spread protection does make the EAs more profitable but after a while it averages out to a similar level as the EA without spread protection.  I have not used it for a while but will start to again as I am looking at running Live accounts for shorter periods of time and it may be beneficial.

This code is for the portfolio EAs and will probably be slightly different for the std EAs.

Settings are in points so I normally use 30 for 3 pips.

So, open up the Portfolio EA with meta editor.

and copy in this line as shown:

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

 

 

Then these line as shown:

//Add protection maximum spread
if(Ask-Bid>_Point*Maximum_Spread)
return;

 

See image in next post

 

Compile and save.

Run some side by side tests and see how you go…..