Skip to content
All library documents

Plotting MACD Alongside Candlesticks in a Python Strategy

Article FMZ digest · Author: 发明者量化-小小梦

Summary

This example explains how to display candlesticks and the three MACD series—DIF, DEA, and MACD—in a Python trading strategy. Its chart configuration assigns price and indicator data to separate vertical axes, making the smaller indicator values easier to read alongside the asset price. The loop repeatedly retrieves candle history, waits until there are enough bars to calculate the indicator, and then adds candle and MACD values to the chart.

Timestamp comparisons determine whether the newest bar is updated in place or a new data point is added. The example notes that the chart can be run in a backtest or on a live bot. It illustrates indicator calculation and visualization mechanics, rather than using MACD to generate trades or making a claim about returns. It supplies no performance evidence, and the minimum history check is only an example threshold; readers should assess data availability and indicator behavior for their own settings.

Key ideas

  • The chart configuration places price candles and MACD series on separate axes.
  • The example plots DIF, DEA, and MACD with the candle history.
  • The strategy waits for sufficient candle history before calculating the indicator.
  • Bar timestamps distinguish updating the current point from adding a new point.
  • The example teaches charting mechanics and does not evaluate a MACD trading strategy.

Tags

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