Plotting MACD on a Separate Chart Axis in JavaScript
Summary
This example shows how to plot futures price records alongside MACD indicator lines using separate vertical axes. It configures one axis for the price chart and assigns the DIF, DEA, and MACD series to a second axis, then updates those lines as new records arrive. The code waits for an initial history of at least 30 records before setting up the chart and only begins indicator calculations once the history exceeds 50 records.
The example uses the platform’s MACD function and plots the latest two points when the record timestamp changes, or refreshes the current point when it does not. It is an implementation example rather than a trading strategy: it gives no entry or exit rules, performance results, or risk analysis. Its charting and data-fetching functions depend on the specific trading platform, so the approach may need adaptation elsewhere.
Key ideas
- A second vertical axis lets price records and MACD lines use separate scales.
- The example assigns DIF, DEA, and MACD to the indicator axis.
- It updates the previous and current indicator points when a new record timestamp appears.
- The document provides charting code but no trading rules or performance evidence.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.