Mariner Backtesting - TA-LIB MACD with controllable MA type

MACDEXT

 

 macd, macdsignal, macdhist = MACDEXT(close, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0)

Plot

MACD with controllable MA type

Working Example

from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import talib

class WE_MACDEXT(Strategy):

    def on_start(self, md, order, service, account):
        # symbol and timestamp
        print(self.symbol + ":  " + service.time_to_string(service.system_time))
        daily_bars = md.bar.daily(start=-100)
        close = daily_bars.close
        macd, macdsignal, macdhist = talib.MACDEXT(close, fastperiod=12, fastmatype=0, slowperiod=26, slowmatype=0, signalperiod=9, signalmatype=0)

        # get the date values
        dates = service._context.market._storage.market_hours.keys()
        dateList = []
        for date in dates:
           dateList.append(str(date.strftime('%Y-%m-%d')))
        dates = sorted(dateList, reverse=True)[1:101]
        dates.sort()

        dict = OrderedDict()
        dict['date'] = dates
        dict['close'] = close
        dict['macd'] = macd
        dict['macdsignal'] = macdsignal
        dict['macdhist'] = macdhist
        symbol = 'MACDEXT: ' + self.symbol
        print ktgfunc.talib_table(symbol, 3, dict)

Console

MSFT:  2017-02-09 09:30:00.000000
MACDEXT: MSFT
Input Output
date close macd macdsignal macdhist
2016-09-16 56.87 nan nan nan
2016-09-19 56.55 nan nan nan
2016-09-20 56.43 nan nan nan
2016-09-21 57.37 nan nan nan
2016-09-22 57.43 nan nan nan
2016-09-23 57.04 nan nan nan
2016-09-26 56.52 nan nan nan
2016-09-27 57.56 nan nan nan
2016-09-28 57.64 nan nan nan
2016-09-29 57.01 nan nan nan
2016-09-30 57.21 nan nan nan
2016-10-03 57.03 nan nan nan
2016-10-04 56.86 nan nan nan
2016-10-05 57.25 nan nan nan
2016-10-06 57.35 nan nan nan
2016-10-07 57.41 nan nan nan
2016-10-10 57.65 nan nan nan
2016-10-11 56.81 nan nan nan
2016-10-12 56.73 nan nan nan
2016-10-13 56.54 nan nan nan
2016-10-14 57.03 nan nan nan
2016-10-17 56.84 nan nan nan
2016-10-18 57.27 nan nan nan
2016-10-19 57.14 nan nan nan
2016-10-20 56.87 nan nan nan
2016-10-21 59.26 nan nan nan
2016-10-24 60.59 nan nan nan
2016-10-25 60.58 nan nan nan
2016-10-26 60.22 nan nan nan
2016-10-27 59.70 nan nan nan
2016-10-28 59.47 nan nan nan
2016-10-31 59.52 nan nan nan
2016-11-01 59.40 nan nan nan
2016-11-02 59.03 1.07 0.58 0.49
2016-11-03 58.81 1.15 0.70 0.46
2016-11-04 58.32 1.20 0.80 0.40
2016-11-07 60.01 1.36 0.92 0.44
2016-11-08 60.06 1.31 1.02 0.29
2016-11-09 59.77 1.13 1.08 0.05
2016-11-10 58.31 0.90 1.10 -0.21
2016-11-11 58.62 0.71 1.09 -0.37
2016-11-14 57.73 0.54 1.04 -0.50
2016-11-15 58.87 0.44 0.97 -0.53
2016-11-16 59.65 0.34 0.88 -0.54
2016-11-17 60.64 0.30 0.78 -0.48
2016-11-18 60.35 0.26 0.66 -0.40
2016-11-21 60.86 0.28 0.54 -0.26
2016-11-22 61.12 0.35 0.46 -0.11
2016-11-23 60.40 0.26 0.39 -0.12
2016-11-25 60.53 0.17 0.33 -0.16
2016-11-28 60.61 0.10 0.28 -0.18
2016-11-29 61.09 0.26 0.26 0.00
2016-11-30 60.26 0.41 0.27 0.14
2016-12-01 59.20 0.58 0.30 0.29
2016-12-02 59.25 0.65 0.34 0.31
2016-12-05 60.22 0.68 0.39 0.30
2016-12-06 59.95 0.61 0.41 0.19
2016-12-07 61.37 0.62 0.45 0.17
2016-12-08 61.01 0.57 0.50 0.07
2016-12-09 61.97 0.53 0.55 -0.02
2016-12-12 62.17 0.55 0.58 -0.03
2016-12-13 62.98 0.57 0.60 -0.02
2016-12-14 62.68 0.64 0.60 0.04
2016-12-15 62.58 0.67 0.60 0.06
2016-12-16 62.30 0.74 0.61 0.13
2016-12-19 63.62 0.90 0.64 0.26
2016-12-20 63.54 1.07 0.69 0.38
2016-12-21 63.54 1.13 0.76 0.37
2016-12-22 63.55 1.25 0.83 0.41
2016-12-23 63.24 1.26 0.91 0.35
2016-12-27 63.28 1.35 1.00 0.35
2016-12-28 62.99 1.33 1.08 0.26
2016-12-29 62.90 1.32 1.15 0.17
2016-12-30 62.14 1.21 1.20 0.01
2017-01-03 62.58 1.12 1.23 -0.11
2017-01-04 62.30 1.02 1.22 -0.20
2017-01-05 62.30 0.96 1.20 -0.24
2017-01-06 62.84 0.83 1.16 -0.33
2017-01-09 62.64 0.66 1.09 -0.43
2017-01-10 62.62 0.45 0.99 -0.54
2017-01-11 63.19 0.27 0.87 -0.60
2017-01-12 62.61 0.13 0.74 -0.61
2017-01-13 62.70 -0.03 0.60 -0.63
2017-01-17 62.53 -0.11 0.46 -0.58
2017-01-18 62.50 -0.20 0.33 -0.53
2017-01-19 62.30 -0.20 0.20 -0.40
2017-01-20 62.74 -0.21 0.08 -0.29
2017-01-23 62.96 -0.15 -0.01 -0.15
2017-01-24 63.52 -0.08 -0.07 -0.02
2017-01-25 63.68 -0.06 -0.10 0.05
2017-01-26 64.27 0.00 -0.12 0.12
2017-01-27 65.78 0.18 -0.09 0.28
2017-01-30 65.13 0.28 -0.05 0.33
2017-01-31 64.65 0.41 0.02 0.39
2017-02-01 63.58 0.48 0.10 0.39
2017-02-02 63.17 0.54 0.18 0.36
2017-02-03 63.68 0.62 0.27 0.36
2017-02-06 63.64 0.71 0.35 0.36
2017-02-07 63.43 0.75 0.44 0.30
2017-02-08 63.34 0.73 0.52 0.21