cinar / indicatorts

IndicatorTS - Stock technical indicators and strategies in TypeScript for browser and server programs.
MIT License
280 stars 48 forks source link

The Money Flow Index (MFI) signs should be extracted from Typical Prices #473

Open ebadran opened 3 months ago

ebadran commented 3 months ago

In the current implementation of the Money Flow Index (MFI), the extractSigns function is applied to the changes in the rawMoneyFlow array.

const rawMoneyFlow = multiply(typprice(highs, lows, closings), volumes);
const signs = extractSigns(changes(1, rawMoneyFlow));
const moneyFlow = multiply(signs, rawMoneyFlow);

As a result, the index rarely reaches the 20 or 80 thresholds typically used to signal overbought or oversold conditions.

In the more widely accepted definition of the MFI, as seen in Wikipedia, TradingView and Investopedia, the positive/negative signs are instead extracted from the Typical Prices.

const typicalPrices = typprice(highs, lows, closings);
const signs = extractSigns(changes(1, typicalPrices));
const rawMoneyFlow = multiply(typicalPrices, volumes);
const moneyFlow = multiply(signs, rawMoneyFlow);

This isn’t necessarily an error, but it might confuse some users.