Skip to content
All library documents

Hampel Filtering and BiLSTM Context for Adaptive Trailing Stops

Article MQL5 articles

Summary

This article describes a custom trailing stop intended for noisy, fast-moving markets. Its first component applies a Hampel filter to a recent price window: the median and median absolute deviation define a range, and prices outside that range are treated as outliers so a brief wick does not immediately move the stop. A bidirectional LSTM processes the window in forward and reverse order to provide a bounded trend score, which is meant to help distinguish transient shocks from meaningful momentum changes.

The author presents an MQL5 implementation and compares an algorithm-only test with a version that also uses the network, with RSI and Envelopes as entry signals. Neither test produced a profitable forward walk; the network version reportedly reduced the net loss relative to the first run. The results are therefore preliminary and do not establish an edge. The article recommends wider tests across symbols and periods, and suggests dynamic network weights and incorporating tick volume as possible extensions.

Key ideas

  • A sliding median and median absolute deviation can flag price observations that are unusual within a recent window.
  • The Hampel filter is used to keep transient price spikes from triggering premature trailing-stop adjustments.
  • A bidirectional LSTM adds sequential context by processing the same price window in both temporal directions.
  • The author combines statistical outlier rejection with a trend score to guide stop updates.
  • The reported tests did not achieve a profitable forward walk, so the approach needs broader independent evaluation.

Tags

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