Skip to content
All library documents

Recent High and Low Levels as Trailing Stops

Article Strategy library · Author: Zer3192

Summary

This example uses recent price extremes as stop levels for open positions. It calculates the lowest low over a configurable lookback for a long position and the highest high over a separate lookback for a short position, excluding the current bar from each calculation. The stop values are plotted while the corresponding position is open and submitted as exit orders, so the level can change as new bars arrive.

Entries in the example are based on three consecutive rising closes for a long trade or three consecutive falling closes for a short trade, and new entries are allowed only while flat. Both lookback lengths default to 20 bars. The document is a code example, not an evaluation: it supplies no instrument, timeframe, costs, backtest results, or evidence that these entry and stop rules are profitable. Extreme-based stops may also produce different risk distances as volatility and price structure change.

Key ideas

  • The long stop uses the lowest low over a configurable lookback, excluding the current bar.
  • The short stop uses the highest high over a separate lookback, also excluding the current bar.
  • The example enters after three consecutive rising or falling closes and only enters while flat.
  • Both lookback lengths default to 20 bars.
  • No backtest results or evidence of profitability are provided.

Tags

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