Skip to content
All library documents

Reservoir Sampling and Linear Regression for Trailing Stops

Article MQL5 articles

Summary

The article describes a custom trailing stop that combines reservoir sampling with a linear regression filter. The reservoir keeps a fixed-size, probabilistically representative sample of incoming prices, limiting memory use while providing a base price for stop calculations. A deterministic linear congruential generator supplies replacement choices so backtests can reproduce the same sample sequence.

An ordinary least squares fit over recent prices projects the next price. For a long position, a forecast pointing downward pauses stop updates; an upward forecast allows trailing to resume. The article also describes configurable reservoir sizes and operating modes, but the available text omits much of the mode logic and implementation details. It reports a backtest trade-off: lower net profit alongside reduced equity drawdown and a higher Sharpe ratio, and suggests further testing across longer periods and more symbols. The results are limited to the reported test and do not establish that the method generalizes across markets or conditions.

Key ideas

  • Reservoir sampling maintains a fixed-size sample of a continuing price stream, with each observed price receiving an equal chance of inclusion.
  • A class-specific deterministic random generator supports repeatable sampling during backtests.
  • A linear regression forecast acts as a filter that can pause or resume trailing stop updates.
  • The reported test exchanged net profit for lower drawdown and a higher Sharpe ratio, requiring broader validation.

Tags

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