Skip to content

MACD Strategy doesn't consider crosses #365

Description

@mozeryansky

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions