Skip to content
All library documents

Time-Range Simple, Exponential, and Weighted Moving Averages

Article ProRealCode

Summary

This document presents three moving averages that use only closing prices whose bar opening times fall within a configured daily time range. The simple version averages a specified number of qualifying observations. The exponential version applies the conventional period-based smoothing factor as it processes qualifying bars. The weighted version increases each observation’s weight with its order in the selected sample. Each calculation scans backward through bars and stops once it has collected the requested period count.

The approach is intended to keep prices outside the selected time window from influencing the average, which can support analysis of a particular session segment. The examples include configurable period and start/end time values, with bounds applied to those inputs. The document supplies code but no chart comparisons, trading rules, or performance evidence. It also does not discuss behavior when too few bars qualify, session boundaries, or how to validate the calculations on different data intervals.

Key ideas

  • The three averages include only bars whose opening times lie inside a selected time window.
  • The simple average weights qualifying closes equally.
  • The exponential average applies period-based smoothing to qualifying closes.
  • The weighted average assigns progressively larger weights within the collected sample.
  • The document provides implementation examples but no trading or performance evaluation.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.