Created
July 19, 2019 12:29
-
-
Save mementum/a740f41ce3653d03b3dea3ce01d2b770 to your computer and use it in GitHub Desktop.
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
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