Advertisement IC Markets

A custom spread indicator that paints the background when too wide

Optimize MetaTrader 4, MetaTrader 5, cTrader, and TradingView for speed. Discuss Level II Market Depth (DOM), custom hotkeys, and volume indicators.
Post Reply
FXS London Scalper
Posts: 201
Joined: Sun Oct 18, 2026 12:25 pm

A custom spread indicator that paints the background when too wide

Post by FXS London Scalper »

A visual cue on the chart helps avoid entering when spread is wide. An indicator that changes the chart background colour when spread exceeds a threshold is simple and effective.

Logic:
- On each tick, calculate spread.
- If spread > threshold, set chart background to a warning colour.
- If spread < threshold, restore normal background.

MQL5 snippet:

Code: Select all

void OnTick() {
   double spr = (SymbolInfoDouble(_Symbol,SYMBOL_ASK) - SymbolInfoDouble(_Symbol,SYMBOL_BID)) / _Point;
   color bg = (spr > MaxSpreadPts) ? clrMaroon : clrBlack;
   ChartSetInteger(0, CHART_COLOR_BACKGROUND, bg);
}
(For an indicator, use OnCalculate instead of OnTick.)

Refinements:
- Different thresholds by hour.
- Gradual colour change (yellow, orange, red).
- Display current spread as a label.

This kind of visual cue works because it's impossible to miss, unlike a number in the corner.

Does anyone use something similar? Share your version.
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Post Reply