forked from coin-unknown/Indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update FUNDING.yml * MFI indicator implementation and unit tests for coin-unknown#46 * export MFI from package * add documentation about MFI * add moment value for MFI --------- Co-authored-by: Dmitriy Yurov <[email protected]>
- Loading branch information
1 parent
a106b1e
commit 5dadec0
Showing
36 changed files
with
24,549 additions
and
24,213 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,14 @@ | ||
# Money Flow Index (MFI) | ||
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. | ||
|
||
## Key features | ||
|
||
- The Money Flow Index (MFI) is a technical indicator that generates overbought or oversold signals using both prices and volume data. | ||
|
||
- An MFI reading above 80 is considered overbought and an MFI reading below 20 is considered oversold, although levels of 90 and 10 are also used as thresholds. | ||
|
||
- A divergence between the indicator and price is noteworthy. For example, if the indicator is rising while the price is falling or flat, the price could start rising. | ||
|
||
## How to calculate Money Flow Index (MFI) in excel spreadsheet? | ||
|
||
[Download excel sample](../tests/mfi/MoneyFlowIndex.xlsm) |
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,74 @@ | ||
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) { | ||
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); | ||
} | ||
} |
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.