-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MFI indicator implementation and unit tests for #46
- Loading branch information
1 parent
58fcb58
commit 31245b5
Showing
33 changed files
with
24,512 additions
and
24,212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CircularBuffer } from './providers/circular-buffer'; | ||
|
||
/** | ||
* Money Flow Index (MFI) is a movement indicator used in technical analysis that looks at time and price | ||
* to measure the trading pressure — buying or selling. It is also called volume-weighted | ||
* Relative Strength Index (RSI), as it includes volume, unlike RSI, which only incorporates price. | ||
*/ | ||
export class MFI { | ||
private positiveMoneyFlowSum = 0; | ||
private negativeMoneyFlowSum = 0; | ||
private pevTypicalPrice = 0; | ||
private posCircular: CircularBuffer; | ||
private negCircular: CircularBuffer; | ||
|
||
constructor(period = 14) { | ||
this.posCircular = new CircularBuffer(period); | ||
this.negCircular = new CircularBuffer(period); | ||
} | ||
|
||
nextValue(high: number, low: number, close: number, volume: number) { | ||
const typicalPrice = (high + low + close) / 3; | ||
const moneyFlow = typicalPrice * volume; | ||
|
||
if (!this.pevTypicalPrice) { | ||
this.pevTypicalPrice = typicalPrice; | ||
return; | ||
} | ||
|
||
const positiveMoneyFlow = typicalPrice > this.pevTypicalPrice ? moneyFlow : 0; | ||
const negativeMoneyFlow = typicalPrice < this.pevTypicalPrice ? moneyFlow : 0; | ||
|
||
this.pevTypicalPrice = typicalPrice; | ||
this.negativeMoneyFlowSum += negativeMoneyFlow; | ||
this.positiveMoneyFlowSum += positiveMoneyFlow; | ||
|
||
const posRedunant = this.posCircular.push(positiveMoneyFlow); | ||
const negRedunant = this.negCircular.push(negativeMoneyFlow); | ||
|
||
if (!this.posCircular.filled) { | ||
return; | ||
} | ||
|
||
this.negativeMoneyFlowSum -= negRedunant || 0; | ||
this.positiveMoneyFlowSum -= posRedunant || 0; | ||
|
||
const moneyFlowRatio = this.positiveMoneyFlowSum / this.negativeMoneyFlowSum; | ||
|
||
return 100 - 100 / (1 + moneyFlowRatio); | ||
} | ||
|
||
momentValue(high: number, low: number, close: number, volume: number) { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.