1 (edited by DrQuant 2026-08-09 03:49:27)

Topic: Spread Analyzer for "Max Spread" entry protection & Monte Carlo sims

I was trying to decide what spread I should use for the "Max Spread" entry protection input on my EA... and realised that it's not a straight-forward thing to figure out. Spreads vary through the day, over the years, and from one broker to another. We really need to see some broker-specific histograms.

So I asked ChatGPT to create an EA for me to execute in MT5 to do exactly that. After much back & forth (about ten hours and 73 versions so far) this is what we came up with:

https://i.postimg.cc/02QBdnxn/Capture.jpg

These charts are for gold (XAUUSD) on IC Markets, and are based on the spread information that's embedded in the M15 OHLC data. As you can see, the spreads are all integers. The blue numbers are the 50th percentile numbers ("P50", which is the Median). Orange are the 90th percentile ("P90") and Green are the 95th percentile ("P95").

For most of 2021 and 2022 the Median is zero, indicating that a lot of the spreads are claimed to be negligible. That seems unlikely, but might just be rounding-down. However, I have seen speculation online that the spreads embedded in OHLC data are actually the low of the spread for that candle, not the mean or median, which is why I wrote "MT5 Minimum Bar Spread" at the top of the chart.

Since it's unclear whether we can trust the spreads embedded in the OHLC data, I thought it might be interesting to recalculate these charts based on tick data. Unfortunately IC Markets only provide a few months of tick data so the time period will be limited, but the comparison should be interesting. I'll send that in another message.

For now, attached is the code of the EA that produced these charts. If you want to make changes just upload the code to ChatGPT and ask ChatGPT to do it for you. There are lots of input options for this EA. Check the code for comments that might help you figure out what each one does. Or ask me.

Post's attachments

SpreadAnalyzer_v1_73.mq5 88.56 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

2 (edited by DrQuant 2026-08-09 10:07:03)

Re: Spread Analyzer for "Max Spread" entry protection & Monte Carlo sims

In the EA's options there's one called InpDataMode. This option controls how the spread data is calculated. By default this is set to "MT5 Minimum Bar Spread" (which is the chart I sent earlier) and it takes the spread from the OHLC data. If I set it to "Every Tick (Averaged Per Bar)" the EA calculates the spread by taking the mean(bid minus ask) for every tick in the candle. When I select that option for XAUUSD at M15 on my IC Markets Raw Spreads Account I get this:

https://i.postimg.cc/vTqM2mch/Capture.jpg

The spreads per tick start off as integers but once they've been averaged for the candle they become floating point numbers and the resulting chart above looks a lot more reasonable than the earlier one.

You will notice immediately that all the numbers are higher than in the earlier chart. The median ("P50") is now 8.8 instead of 3.0. This would seem to confirm the theory that spreads in the OHLC data are the minimum spreads for the candle, not the mean.

You can also see that the spreads blow up just before the broker shuts down for an hour at midnight. It might therefore be worth setting the "Max Spread" entry protection at a level sufficient to prevent the EA from entering trades when the spread is greater than about 20 (or use a time-based filter).

But note that this is a Raw Spreads account. The spreads will be higher for non-Raw accounts. You can't just assume that these numbers will be the same for other brokers or other types of account. You need to run the EA for your broker and your type of account.