Implementing a KDJ Crossover Strategy in C++
Summary
This tutorial shows how to turn a KDJ indicator rule into a futures trading program using the FMZ Quant C++ framework. It explains the indicator’s RSV, K, D, and J components, then uses the relationship between K and D to generate directional signals: K above D opens a long position, while K below D opens a short position. It also describes closing positions when the D line changes direction and outlines how to retrieve candles, calculate KDJ, track position state, and submit orders through a trading library.
The article emphasizes checking that market data is valid and long enough for the indicator, organizing strategy logic in an onTick function, and handling closes before new entries when signals reverse. It recommends acting on completed candles and executing on the next candle to reduce differences between backtests and live trading. The document is an implementation walkthrough, not a performance study: it supplies no tested results, and its sample code contains apparent formatting or syntax errors. KDJ signals alone may also produce poor trades in changing market conditions.
Key ideas
- KDJ is derived from recent closing prices relative to the period’s high and low, followed by smoothing into K and D lines.
- The example opens long when K exceeds D and short when K is below D.
- It closes positions based on a change in the direction of the D line.
- A C++ strategy loop should validate connectivity and candle data before calculating signals and placing orders.
- Using completed candles and ordering close logic before new entries can help align execution with the intended rules.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.