indicatorts icon indicating copy to clipboard operation
indicatorts copied to clipboard

MACD Strategy doesn't consider crosses

Open mozeryansky opened this issue 9 months ago • 2 comments

Describe the bug https://github.com/cinar/indicatorts/blob/main/src/strategy/trend/macdStrategy.ts

The strategy will say buy or sell based only on if the macd line is above or below the signal, and not when it crosses.

To Reproduce

import { macdStrategy } from 'indicatorts';
const asset: Asset = {
  dates: [],
  openings: [],
  highs: [],
  lows: [],
  closings: [
    19, 38, 55, 70, 83, 92, 98, 100, 98, 92, 83, 70, 55, 38, 19, 0, -19, -38,
    -55, -70, -83, -92, -98, -100, -98, -92, -83, -70, -55, -38, -19, 0, 19, 38,
    55, 70, 83, 92, 98, 100,
  ],
  volumes: [],
};
const actions = macdStrategy(asset);

Will produce: [0, -1, 1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1]

Expected behavior

Only show buy/sell actions on the cross.

mozeryansky avatar Oct 21 '23 02:10 mozeryansky