Skip to content

Instantly share code, notes, and snippets.

@mementum
Created July 19, 2019 08:52
Show Gist options
  • Save mementum/6ad54b6aa6f7821fc531e9d29f07485e to your computer and use it in GitHub Desktop.
Save mementum/6ad54b6aa6f7821fc531e9d29f07485e to your computer and use it in GitHub Desktop.
class MFI_MultipleInputs(bt.Indicator):
lines = ('mfi',)
params = dict(period=14)
def __init__(self):
if len(self.datas) == 1:
# 1 data feed passed, must have components
tprice = (self.data.close + self.data.low + self.data.high) / 3.0
mfraw = tprice * self.data.volume
else:
# if more than 1 data feed, components in OHLCV order
tprice = (self.data0 + self.data1 + self.data2) / 3.0
mfraw = tprice * self.data3
# No changes with regards to previous implementation
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