Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

ADR Levels: Average Daily Range, range used in percent, projected high and low (no repaint) - indicator for MetaTrader 5

Muhammad Muqeem Korejo
Muhammad Muqeem Korejo
Hi, I'm Muhammad Muqeem Korejo, an MQL4/MQL5 developer from Pakistan with 1.5 years of trading experience.
I build and fix trading tools for MetaTrader 4 and MetaTrader 5:
• Expert Advisors (EAs) built from your strategy rules
• Custom indicators, alerts and on-chart panels
Views:
31
Rating:
(1)
Published:
ADRLevels.mq5 (17.43 KB) view
BrokerTime.mqh (14.37 KB) view
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The Average Daily Range (ADR) tells you how far price usually travels in one day. Day traders use it in three ways: to see if today has already done its usual distance (a move that has used 100 percent of the ADR is often late to chase), to place a realistic take profit, and to judge if a stop is wide or tight for this market. This indicator shows all of it on the chart and in a small panel.

ADR Levels on a XAUUSD M15 chart: ADR high and low lines and the panel with the range used

Files

  • ADRLevels.mq5 - the indicator.
  • BrokerTime.mqh - the time zone class (the same file as in the code "Broker Time"). Put both files in the same folder and compile the indicator.

What is shown

  • ADR high and ADR low lines. By default they are projected from today's extremes: ADR high = today's low + ADR, ADR low = today's high - ADR. When today's range reaches the ADR, the two lines meet the day's high and low. You can also project them from the day open (open plus and minus half the ADR).
  • A panel: the ADR of your chosen length, ADR 5 / 10 / 20 for comparison, today's range, the range used in percent (red from 100 percent), and the distance from the price to the ADR high and the ADR low.
  • Optional alerts when today's range reaches 80 and 100 percent of the ADR, once per day.

The ADR is an average, not a limit. Trend days often go to 150 percent or more, so use it as a guide, not as a wall.

How it is calculated

  • ADR = the average of high minus low of the last 14 finished days (an input). Today is never in the average, so the ADR does not change during the day.
  • The days are built from M15 bars, so the ADR is the same on every chart timeframe.
  • The day can start at broker midnight, New York midnight or 17:00 New York (the forex day, the default). For the New York options the class BrokerTime finds the clock of your broker from the Friday closes in the history, with the right summer time on every date.
  • The short Sunday session of some brokers is added to Monday, so it does not pull the ADR down as a tiny extra "day".

No repaint

The lines from today's extremes move during the day, because today's high and low move. This is shown honestly as a step line: every closed bar keeps the value that it had when it closed, and that value never changes later. A value is calculated only from the bars up to that bar.

For Expert Advisors

Buffers 2 to 6 hold the exact values: 2 ADR high, 3 ADR low, 4 ADR, 5 range used in percent, 6 today's range. Buffers 0 and 1 are the drawn lines (empty on the first bar of each day, so the lines have no vertical steps).

When you call the indicator with iCustom, each "input group" counts as one parameter: pass a string for it, for example iCustom(_Symbol, _Period, "ADRLevels", "ADR", 14, 0, "Day", 2, 0, 2.0, ...).

Inputs: days in the average, projection (from the extremes or from the open), day start, broker clock, days of history to draw, panel (corner, font size, colour), alerts at 100 and 80 percent, push notifications.

How it was tested

  • An independent calculation in Python (own code, New York time from the IANA time zone database through zoneinfo) rebuilt the days from the exported M15 bars and compared the ADR, the projections, today's range and the range used with the buffers, for four setups on a demo account: EURUSD H1 (17:00 New York), XAUUSD M15 (New York midnight), GBPUSD H4 (broker midnight) and EURUSD M5 (projection from the open). 31,635 values compared, 0 differences.
  • Repaint test: on every new bar, a test Expert Advisor saved the values of the bar that had just closed. At the end of the test the same bars were read again. 32,100 values compared, 0 changed.
  • Validator-style runs in the Strategy Tester: EURUSD H1, XAUUSD D1, GBPUSD M30 and EURUSD M1 (663,241 bars): no errors. Nothing is drawn in a Strategy Tester run without visualization, but all buffers are calculated.
  • The screenshot is a real XAUUSD M15 chart of a demo account (that day had already used 147 percent of its ADR).
Broker Time Panel - server clock, local zone, measured offset, candle close countdown Broker Time Panel - server clock, local zone, measured offset, candle close countdown

The panel prints the broker's server clock, your local clock with its GMT zone, the offset between the two to the minute, and the countdown to the close of the chart's current candle. The offset is measured from the terminal's own clocks on every pass, so nothing is typed in and no broker zone is assumed. If you set a lead in seconds and enable a channel, it sends one alert per candle while a bid is available, with the seconds left and the bid; its eight objects stay out of the object list and cannot be selected.

TradeDiagnostics - include file that explains why an EA cannot open a trade TradeDiagnostics - include file that explains why an EA cannot open a trade

One function call checks the terminal, account, program permission, symbol, trading session, quotes, spread, volume and margin, and tells you in plain words why a new trade cannot be opened. No order is ever sent.

Candlestick Pattern Scanner with honest statistics (engulfing, pin bar, stars, no repaint) Candlestick Pattern Scanner with honest statistics (engulfing, pin bar, stars, no repaint)

Seven candlestick patterns with exact rules, trend / swing / size filters against clutter, and a statistics table that compares every pattern with the base rate of the same chart. Closed candles only, no repaint, buffers for EAs.

Broker Symbol Compatibility Scanner Broker Symbol Compatibility Scanner

Scans the broker's complete MT5 symbol catalogue, resolves common prefixes, suffixes and aliases, checks trading specifications and exports a compatibility report to CSV.