Skip to content
All library documents

Bollinger Breakouts with MACD Confirmation and ATR Trailing Stops

Code Quant course library

Summary

This strategy combines Bollinger Bands, MACD, and ATR to trade breakouts in either direction. It opens a long position when price reaches the upper band while MACD and its histogram are positive; it opens a short position when price reaches the lower band while both MACD measures are negative. The bands use a configurable lookback and deviation, while MACD uses its conventional fast, slow, and signal periods.

Position size is set from a configured cash risk amount divided by rolling close-price standard deviation scaled by a risk factor. An initial stop uses that same risk measure; after entry, the stop trails the favorable price extreme by a multiple of ATR. The code also saves strategy state for restart recovery and includes order and position event handling. It provides implementation details, not backtest results or evidence of profitability. Execution assumptions, parameter selection, fees, slippage, and the reliability of saved or broker-reported position state need independent evaluation.

Key ideas

  • The strategy enters on a Bollinger Band breakout only when MACD direction and histogram agree.
  • Position size is derived from a configured risk amount and rolling price standard deviation.
  • Initial stops use standard deviation, while subsequent stops trail price extremes using ATR.
  • The implementation persists position and indicator state, but reports no performance evaluation.

Tags

Cited by

From a private course collection; the original is not published.