Loading…

Average Range By Hour Study

Every trader has heard which sessions are supposed to move and which are supposed to be dead, and very few have measured it on the specific symbol and broker they actually trade. This script does the measurement: it reads the loaded bars for a chosen symbol and timeframe, buckets each bar's range by the hour of its open time, and reports the mean and median range in pips for every one of the 24 hours. Median sits next to mean deliberately. A handful of outsized bars - a news spike, a rollover gap - can drag an hour's mean well above what a typical bar in that hour actually looks like, and the median is not moved by the same outliers. Reading the two side by side is what makes the table honest about whether an hour is "usually wide" or "occasionally wide". Getting the median right means keeping every sample, not just a running sum, so InpMaxBars exists to bound memory and runtime deliberately when a low timeframe has years of history loaded - there is no reason to hold two million M1 bars in memory to answer a question about typical hourly range. Notes and limitations - The hour used is the bar's own open time in whatever time base the terminal already shows on the chart, usually broker or server time - there is no separate timezone conversion, so the table matches what you are already looking at. - Hours with very few samples (an unusual session hour on an exotic symbol, or a short InpMaxBars) will show a mean and median that are not statistically reliable; the count column makes that visible. - Range here is the simple high-minus-low of each bar, not true range against the previous close, so a bar that gapped from the prior one will not carry that gap into its own range figure. - This is a descriptive study, not a trading signal. It does not account for spread, which is itself often widest exactly when range is highest.

Script · MT4 · v1.0 · Free

About Average Range By Hour Study

Average Range By Hour Study is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Symbol, Timeframe and Max bars. MQL source code included.

Files in the download: AverageRangeByHourStudy.ex4, AverageRangeByHourStudy.mq4, AverageRangeByHourStudy.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
TimeframePERIOD_H1Timeframe to study
Max bars5000Most recent bars to include
Save csvtrueWrite the hourly table to a CSV file
DelimiterDelimiterCommaCSV column separator

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Trading Sessions · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria