From f7189b3be43fbeff49bb06d5c78c466286c9ad08 Mon Sep 17 00:00:00 2001 From: Dmitriy Yurov Date: Wed, 18 Sep 2024 18:02:21 +0200 Subject: [PATCH] add moment value for MFI --- src/mfi.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mfi.ts b/src/mfi.ts index 08b52d1..7e218b1 100644 --- a/src/mfi.ts +++ b/src/mfi.ts @@ -49,6 +49,26 @@ export class MFI { } momentValue(high: number, low: number, close: number, volume: number) { - return 0; + const typicalPrice = (high + low + close) / 3; + const moneyFlow = typicalPrice * volume; + + if (!this.pevTypicalPrice) { + return; + } + + const positiveMoneyFlow = typicalPrice > this.pevTypicalPrice ? moneyFlow : 0; + const negativeMoneyFlow = typicalPrice < this.pevTypicalPrice ? moneyFlow : 0; + + if (!this.posCircular.filled) { + return; + } + + const posRedunant = this.posCircular.peek(); + const negRedunant = this.negCircular.peek(); + const negativeMoneyFlowSum = this.negativeMoneyFlowSum + negativeMoneyFlow - negRedunant; + const positiveMoneyFlowSum = this.positiveMoneyFlowSum + positiveMoneyFlow - posRedunant; + const moneyFlowRatio = positiveMoneyFlowSum / negativeMoneyFlowSum; + + return 100 - 100 / (1 + moneyFlowRatio); } }