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): | |
psum = self.data.close + self.data.low + self.data.high | |
tprice = psum / 3.0 | |
mfraw = tprice * self.data.volume | |
... |
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 MyMFIStrategy(bt.Strategy): | |
def __init__(self): | |
mfi = bt.MFI_Canonical(self.data) |
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 MyMFIStrategy2(bt.Strategy): | |
def __init__(self): | |
wclose = self.data.close * 5.0 | |
mfi = bt.MFI_Canonical(self.data.high, self.data.low, wclose, self.data.volume) |
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_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: |
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 MyMFIStrategy2(bt.Strategy): | |
def __init__(self): | |
MFI_Canonical(self.data) | |
MFI_MultipleInputs(self.data, plotname='MFI Single Input') | |
MFI_MultipleInputs(self.data.high, | |
self.data.low, | |
self.data.close, | |
self.data.volume, | |
plotname='MFI Multiple Inputs') |
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 MyMFIStrategy2(bt.Strategy): | |
def __init__(self): | |
MFI_MultipleInputs(self.data) | |
MFI_MultipleInputs(self.data.high, | |
self.data.low, | |
self.data.close * 5.0, | |
self.data.volume, | |
plotname='MFI Close * 5.0') |
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(bt.Indicator): | |
lines = ('mfi', 'money_flow_raw', 'typical', 'money_flow_pos', 'money_flow_neg') | |
plotlines = dict( | |
money_flow_raw=dict(_plotskip=True), | |
money_flow_pos=dict(_plotskip=True), | |
money_flow_neg=dict(_plotskip=True), | |
typical=dict(_plotskip=True), | |
) |
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) |
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
if neg_period == 0: | |
self.lines.mfi[0] = 100 | |
return | |
self.lines.mfi[0] = 100 - 100 / (1 + pos_period / neg_period) |
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
mfiratio = bt.ind.DivByZero(flowpos, flowneg, zero=100.0) | |
self.l.mfi = 100.0 - 100.0 / (1.0 + mfiratio) |
OlderNewer