You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, this was bugging me for a while. Originally I had this based on the upward and downward movement when it crosses. Would be nice to make this change. I'll add it to the list, but if you want to fix it, please feel free to send a PR.
I had forked and was going to make the macd strategy take the periods as arguments, which is when I found the bug. The below change was what I quickly tried. But I believe there needs to be other considerations, as your macd/ema functions don't return NaN for the the values before the period begins, I believe that could cause false trade actions as well.
...
for (let i = 1; i < actions.length; i++) {
if (actions[i-1] != Action.BUY && macdResult.macdLine[i] > macdResult.signalLine[i]) {
actions[i] = Action.BUY;
} else if (actions[i-1] != Action.SELL && macdResult.macdLine[i] < macdResult.signalLine[i]) {
actions[i] = Action.SELL;
} else {
actions[i] = Action.HOLD;
}
}
...
I've decided to use a market data API which returns technical indicators for now, but your code is really great and I'll return when the api I'm using reaches its usefulness for me.
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
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.
The text was updated successfully, but these errors were encountered: