Skip to content
All library documents

MACD Crossovers with an SMA Trend Filter and Trading Controls

Article Strategy library · Author: Khanhtq26

Summary

This Pine Script strategy template uses MACD line and signal-line crossovers to generate long and short signals. It includes configurable fast, slow, and signal periods, and an optional simple moving average filter that classifies direction according to whether the SMA is rising or falling. The template also exposes controls for trade direction, stop-loss and optional take-profit distances, and an intraday trading window. Its comments specify confirmation at the signal bar close and entry at the next bar open.

The code is labeled for VN30F1M trend following, but the supplied material contains no backtest report or performance evidence. It describes natural exits through opposite MACD signals and says strategy entries handle reversals, though the excerpt ends before the full order management implementation is shown. The SMA direction test checks only the latest slope, and MACD is a lagging indicator, so the filter does not eliminate whipsaws or late signals. The template’s market-specific label and configurable controls should not be read as evidence that the settings suit other instruments or sessions.

Key ideas

  • MACD line crossovers provide the template’s long and short entry signals.
  • An optional SMA slope filter restricts entries to the indicated trend direction.
  • The template includes controls for trade side, protective exits, and trading hours.
  • Signal confirmation is described as occurring at bar close, with entry on the next bar open.
  • The excerpt supplies no performance evidence and does not show the complete order management logic.

Tags

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