Skip to content

Instantly share code, notes, and snippets.

@mementum
Created July 19, 2019 12:29
Show Gist options
  • Save mementum/a740f41ce3653d03b3dea3ce01d2b770 to your computer and use it in GitHub Desktop.
Save mementum/a740f41ce3653d03b3dea3ce01d2b770 to your computer and use it in GitHub Desktop.
class MFI_Canonical(bt.Indicator):
lines = ('mfi',)
params = dict(period=14)
def __init__(self):
tprice = (self.data.close + self.data.low + self.data.high) / 3.0
mfraw = tprice * self.data.volume
flowpos = bt.ind.SumN(mfraw * (tprice > tprice(-1)), period=self.p.period)
flowneg = bt.ind.SumN(mfraw * (tprice < tprice(-1)), period=self.p.period)
mfiratio = bt.ind.DivByZero(flowpos, flowneg, zero=100.0)
self.l.mfi = 100.0 - 100.0 / (1.0 + mfiratio)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment