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);
}
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.