Algorithmic Trading Strategy Using Money Flow Index (MFI) & Python

10 min readOct 3, 2020

Use MFI to know when to buy and sell stock

Disclaimer: The material in this article is purely educational and should not be taken as professional investment advice. Invest at your own discretion.

In this article, I will attempt to create a trading strategy called Money Flow Index (MFI). The MFI is also known as volume-weighted RSI and it is an oscillator that uses price and volume data for identifying overbought or oversold signals in an asset.

A Money Flow Index (MFI) level above 80 is considered overbought which is an indication to (sell) and a level below 20 is considered oversold which is an indication to (buy). Also note that levels of 90 and 10 are also used as thresholds.

if MFI > 80 then Sell
if MFI < 20 then Buy

Calculating the Money Flow Index:

When calculating the Money Flow Index, you want to first calculate the typical price. The typical price indicates an average of each days price. The calculation takes the current high price plus the current low price plus the current close price and divides it by three.

typical price = (high + low + close) / 3

Next, calculate the money flow which is negative when the typical price declines from one period to another and is positive when the typical price rises from one period to another. This calculation is done by multiplying the typical price with the volume.

money flow = typical price x volume

Get the positive money flow and the negative money flow within a given time period. We can get the positive money flow by adding the money flow of all the days where the typical price is higher than the previous day’s typical price, and we can get the negative money flow by adding the money flow of all the days where the typical price is lower than the previous day’s typical price. If the typical price didn’t change then that day is removed, but adding 0 is effectively the same thing.

if current typical price > previous typical price
then add the previous money flow to the…

Recommended from Medium


See more recommendations