MACD
The MACD shows the relationship between two moving averages of the price to identify trend changes.
Role in the strategy
| Slot | Available | Role |
|---|---|---|
| Entry Point | No | — |
| Entry Rule | Yes | Filters entries by the MACD line direction or its zero position. |
| Exit Point | No | — |
| Exit Rule | Yes | Triggers exits by the MACD line direction or its zero position. |
The MACD produces conditions, not order prices. As an entry rule it is ANDed with the entry point and the other entry rules; as an exit rule it is ORed with the other exit rules. See Indicators for the slot semantics.
Logic rules
| Rule | Long signal is 1 when | Short signal is 1 when |
|---|---|---|
| MACD line rises | MACD line rose on the previous bar | MACD line fell on the previous bar |
| MACD line falls | MACD line fell on the previous bar | MACD line rose on the previous bar |
| MACD line is higher than the Zero line | MACD line is above 0 | MACD line is below 0 |
| MACD line is lower than the Zero line | MACD line is below 0 | MACD line is above 0 |
| MACD line crosses the Zero line upward | MACD line crossed above 0 from below | MACD line crossed below 0 from above |
| MACD line crosses the Zero line downward | MACD line crossed below 0 from above | MACD line crossed above 0 from below |
| MACD line changes its direction upward | MACD line formed a valley (down then up) | MACD line formed a peak (up then down) |
| MACD line changes its direction downward | MACD line formed a peak (up then down) | MACD line formed a valley (down then up) |
Parameters
| Parameter | Type | Default | Range | Purpose |
|---|---|---|---|---|
| Apply to | select | Close | Open, High, Low, Close, Median, Typical, Weighted | Price series the MACD is calculated from |
| Fast EMA | number | 12 | 2 to 1000 | Period of the fast exponential average |
| Slow EMA | number | 26 | 2 to 1000 | Period of the slow exponential average |
| MACD SMA | number | 9 | 2 to 1000 | Period of the signal line |
Calculation
tech.MACD and tech.MACDSignal in engine/indicator-engine/tech.ts compute:
- MACD line = Fast EMA − Slow EMA of the selected price series.
- Signal line = simple moving average of the MACD line over MACD SMA bars.
The MACD line is drawn as bars and the Signal line as a dotted line in a separate chart pane. The rules use the MACD line against the 0 / 0 level pair.
Backtesting
- The rule is evaluated on the previous (closed) bar with the standard dead zone (
SIGMA = 0.000001). - The MACD contributes only long/short signal arrays — it never changes the entry or exit order price.
- An entry happens only when the entry point allows the direction and every entry rule passes; an exit happens when the exit point is reached and any exit rule passes.