Draw Previous Day High Low
The previous day's high and low is one of the most commonly hand-drawn levels in intraday trading, and one of the easiest to get quietly wrong with a script. The obvious approach - read shift 1 on the D1 timeframe - breaks on brokers that open quoting a few hours into Sunday evening and give that short stub its own daily bar. On a Monday session, shift 1 is then that two-hour Sunday fragment, not Friday's full session, and the "previous day" range drawn is noise rather than the level the market actually respected. This script walks back past a Sunday bar when it finds one, using the bar's own day-of-week field rather than assuming a fixed number of days back, because a broker's actual Sunday open time varies and a hardcoded offset would only be right some of the time. The walk is capped at six days so a terminal with thin D1 history gives up and reports the problem instead of spinning. The other classic bug in a script like this is drawing a line at zero. If the D1 bar in question has not actually loaded into memory yet, iHigh() and iLow() return 0 rather than an error, and a script that doesn't check for that draws a perfectly confident line at the bottom of the chart. This one checks explicitly and refuses to draw anything until the source day's data is actually present, telling you to scroll the D1 chart back to force it to load. Lines are drawn ray-right from the source day's open time, so they read forward through today's session rather than cluttering every earlier day behind them, and every object this script creates carries a fixed prefix so a rerun can clean up after itself without touching anything else on the chart. Notes and limitations - Requires D1 history for the symbol to already be loaded. If it is not, the script refuses to draw and tells you to scroll the D1 chart back first, rather than drawing a line at zero. - The Sunday-stub walk looks only at the day-of-week of each D1 bar. A broker whose stub bar happens to fall on a different weekday (unusual, but not impossible depending on session configuration) will not be detected by this check. - The walk-back is capped at six days as a safety limit against thin history; on a symbol with a genuine multi-day gap in D1 data (a long weekend around a public holiday, for instance) it may still land on a bar further back than intended. The log always states which day it used. - Object cleanup only removes objects carrying this script's own prefix. It will not touch lines drawn by any other script or by hand. - This is a static one-shot draw, not a live-updating indicator. It does not redraw automatically at the next daily rollover - run it again, or attach it to a chart template that reruns it, if that is needed.
Script · MT5 · v1.0 · Free
About Draw Previous Day High Low
Draw Previous Day High Low is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Show midpoint, Skip sunday stub and Color high. MQL source code included.
Files in the download: DrawPrevDayRange.ex5, DrawPrevDayRange.mq5, DrawPrevDayRange.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Show midpoint | true | Also draw the midpoint of the range |
| Skip sunday stub | true | Skip a short Sunday bar when finding "previous day" |
| Color high | clrTomato | Colour for the previous day's high |
| Color low | clrLimeGreen | Colour for the previous day's low |
| Color mid | clrSilver | Colour for the midpoint |
| Label font size | 8 | Label font size |
| Cleanup first | true | Delete this script's previous lines first |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trading Sessions · Alerts · MT5 Script · MQL5 Source Code