Skip to content
All library documents

Stochastic-Based Position Exits with Zone and Profit Filters

Article MQL5 code base

Summary

This expert advisor uses the Stochastic oscillator to close existing positions according to one of three rules: %K crossing %D in an extreme zone, %D entering an overbought or oversold zone, or %D leaving one. The rules are directional: for example, an overbought cross can close a buy, while an oversold cross can close a sell. A separate filter limits closures to positions currently at a loss, currently profitable, or either state. The indicator timeframe is configurable, and the logic evaluates on each tick for the chart’s symbol.

An optional test mode adds simple entries when %D crosses thresholds around its midpoint, using a fixed lot size and no stop loss or take profit. It operates alongside the closing rules. The document presents the tool as a research aid for position management, not a validated trading system; it supplies no performance results. Its scope is limited to the current chart symbol, and the test entries lack money management, protective stops, and magic-number filtering, so the behavior requires careful validation before use.

Key ideas

  • Three Stochastic modes close positions on extreme-zone crosses, entries, or exits.
  • A profit-state filter determines whether only losing positions, only profitable positions, or all matching positions can close.
  • The indicator timeframe can differ from the chart timeframe, but management applies only to the chart symbol.
  • Optional test entries use fixed sizing and have no stop loss or take profit.
  • The document reports no performance evidence and recommends validation before practical use.

Tags

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