Skip to content
All library documents

MACD Long Entries with Price-Based and Trailing Exits

Article Strategy library · Author: John。

Summary

This automated spot-trading script describes a long-only approach using MACD and price conditions. It checks for enough historical bars, then enters when the MACD difference is positive and the histogram moves above a configured threshold after being below a prior threshold. Orders are submitted as limit orders using a price offset, with repeated attempts subject to a timeout and a minimum order size. The script records the average filled entry price and the entry time.

Exit conditions combine several signals: successive bearish candles with specified price declines, a bearish candle when the market is below the average entry, MACD weakness with a nonpositive histogram, or a loss exceeding a configured trailing threshold. Selling also uses a price offset and retries until the position is closed. These rules and parameters describe an execution method, not evidence of profitability: no asset, bar interval, backtest, or performance results are provided. Actual behavior depends on exchange fills, fees, price gaps, and how the thresholds map to the traded asset.

Key ideas

  • A long entry requires positive MACD difference and a histogram rise through configured thresholds.
  • Buy and sell orders use price offsets, with retries and timeout handling for entries.
  • The script tracks average entry price and the time of entry.
  • Exit conditions combine bearish price moves, MACD weakness, and a loss threshold.
  • The source provides no market-specific backtest or performance evidence.

Tags

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