Discussing the article: "MQL5 Wizard Techniques you should know (Part 94): Using Reservoir Sampling and Linear Regression in a Custom Trailing Stop Class"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: MQL5 Wizard Techniques you should know (Part 94): Using Reservoir Sampling and Linear Regression in a Custom Trailing Stop Class.
For this article we rotate to a custom MQL5 Wizard class implementation that explores Trailing Stops. Our custom class is ‘CTrailingReservoirLinReg’ that we derive by combining the Reservoir Sampling algorithm with a Linear Regression network. As has been the case throughout these series, this formulation is testable with MQL5 Wizard Assembled Expert Advisors that can be tuned with various entry signals and money management classes.
In order to establish the case for why this model combination thrives in continuous trending environments, we need to look into its two pillars. Our Trailing Stops application will run in two modes: the 'Engine' or the Reservoir Sampling algorithm gives us a base price that is stabilized with probability; and the 'Filter' or Linear Regression network that establishes whether it is safe to run the stop-loss update.
Reservoir Sampling
For most algorithmic trading, whether high-frequency or not, storing every price bar in order to work out the moving average can be computationally expensive. As the buffer size increases, the strain on resources can be a major processing bottleneck. Whereas with the Skip-List we mapped disjoint price gaps by skipping over data, with Reservoir Sampling we tackle a different problem. How do we maintain a statistically 'fair' and proper representation of prices from a continuous data stream whose size is not known, by using as small an amount of memory as possible. This is a reservoir-sampling algorithm. We decide whether an incoming price should replace an existing element in the buffer (the reservoir) while keeping memory usage fixed. We follow these steps in implementing this:
Author: Stephen Njuki