The MT5 deviation setting and what it does to your fills on fast markets
when you send a market order on MT5, there's a deviation or slippage setting, which is the maximum difference in price you'll accept between what you requested and what you get. I didn't pay attention to it for a long time and it was costing me.
If it's set too wide, the order will fill at nearly any price during a fast move, and you can get a bad fill. If it's set too tight, the order may be rejected in a fast market, and you'll miss the entry. There's no perfect value. It depends on the pair, the time of day and how fast you need the fill.
For my entries in normal conditions, I use a small value, like a pip or so on majors, and for stop orders I allow a bit more because I'd rather exit than not. In an EA, you set it in the code, and it's worth thinking about it per symbol rather than using one number.
Better yet, use limit orders where possible. Then the question goes away because you're stating the price you'll accept.
The MT5 deviation setting and what it does to your fills on fast markets
Re: The MT5 deviation setting and what it does to your fills on fast markets
Worth knowing that on some account types the deviation setting does nothing. If your broker uses market execution, orders are filled at whatever price is available and the setting is ignored. It only applies with instant execution, where the broker can reject or requote if the price moved too far. You can usually see which one your account uses in the order window or the symbol specification. I spent a while adjusting it before realising it had no effect on my account.
It’s Fairman 
Re: The MT5 deviation setting and what it does to your fills on fast markets
For EAs, I set the deviation per symbol by looking at the normal spread and allowing roughly one to two times that amount. A single number across everything made no sense, because one pip on EURUSD and one pip on GBPJPY are very different in a fast market. I keep the values in an input so I can change them without recompiling. On news days the EA does not trade anyway, so the setting mostly matters around busy session opens.
It’s Fairman 