Mariner Backtesting - TA-LIB Three Inside Up/Down

CDL3INSIDE

 

 integer = CDL3INSIDE(open, high, low, close)
Return Codes
  • 0 = No Signal
  • -100 = Bearish Signal
  • 100 = Bullish Signal

The three inside technical analysis patterns indicate a market reversal. To detect this pattern you need at multiple candles (time periods.) The first set of candles are used to indicate trend and the last three are used in the determination of the pattern.

Three Inside Up/Down

Bull Reversals (Moving from Downtrend to Uptrend) occur when:

  • The market is trending down.
  • The 1st candle is red or black and a large differential between open and close price. This is a candle where the time period had a higher open and lower close.
  • The 2nd candle is green or white and a smaller differential between open and close price.
  • The 3rd candle is green or white with a closing price above the close of the 2nd candle.

The Bear Reversals (Moving from Uptrend to Downtrend) occur when:

  • The market is trending up.
  • The 1st candle is green or with and a large differential between open and close price. This is a candle where the time period had a lower open and higher close.
  • The 2nd candle is red or black and a smaller differential between open and close price.
  • The 3rd candle is red or black with a closing price below the close of the 2nd candle.
Candlestick Plot showing TA-LIB Signals on BA

The following chart shows $BA in 4th Quarter of 2017. The blue lines indicate a +100 signal on 3 Inside from TA-LIB

Three Inside Up/Down

Candlestick Plot

Three Inside Up/Down

Working Example

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

class WE_CDL3INSIDE(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
        high = daily_bars.high
        low = daily_bars.low
        open = daily_bars.open
        integer = talib.CDL3INSIDE(open, high, low, close)

        # 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['open'] = open
        dict['high'] = high
        dict['low'] = low
        dict['close'] = close
        dict['integer'] = integer
        symbol = 'CDL3INSIDE: ' + self.symbol
        print ktgfunc.talib_table(symbol, 1, dict)

Console

GOOG:  2014-05-22 09:30:00.000000
CDL3INSIDE: GOOG
Input Output
date open high low close integer
2013-12-27 284.00 284.00 276.46 279.23 0.00
2013-12-30 280.60 283.21 279.33 279.99 0.00
2013-12-31 283.45 283.50 278.46 278.48 0.00
2014-01-02 279.36 284.23 279.36 283.58 0.00
2014-01-03 362.98 362.98 281.10 283.50 0.00
2014-01-06 569.85 587.28 564.13 569.74 0.00
2014-01-07 574.65 577.77 543.00 543.14 0.00
2014-01-08 540.74 548.48 527.15 538.15 0.00
2014-01-09 542.60 555.00 541.61 554.90 0.00
2014-01-10 559.62 565.37 552.95 564.14 0.00
2014-01-13 565.00 565.00 539.90 540.95 0.00
2014-01-14 532.55 540.00 526.53 530.60 0.00
2014-01-15 538.25 544.10 529.56 532.52 0.00
2014-01-16 535.71 538.45 518.46 536.44 0.00
2014-01-17 543.00 557.00 540.00 556.54 0.00
2014-01-21 548.81 549.50 531.15 536.10 0.00
2014-01-22 536.10 536.70 525.60 528.62 0.00
2014-01-23 528.64 537.23 527.51 534.81 0.00
2014-01-24 533.79 533.87 526.25 526.94 0.00
2014-01-27 529.97 531.65 522.12 525.16 0.00
2014-01-28 522.51 524.70 515.42 516.18 0.00
2014-01-29 517.18 518.48 502.80 517.15 0.00
2014-01-30 516.90 529.46 516.32 527.70 0.00
2014-01-31 527.60 528.00 522.52 526.66 0.00
2014-02-03 527.11 532.93 523.88 531.35 0.00
2014-02-04 533.76 534.00 525.61 527.93 0.00
2014-02-05 524.82 528.90 521.32 527.81 0.00
2014-02-06 525.23 526.81 515.06 515.14 0.00
2014-02-07 515.79 516.68 503.30 509.96 0.00
2014-02-10 508.46 517.23 506.45 511.00 0.00
2014-02-11 510.75 519.90 504.20 519.03 0.00
2014-02-12 523.51 530.19 519.01 529.92 0.00
2014-02-13 530.89 536.07 529.51 533.09 0.00
2014-02-14 533.00 533.00 525.29 526.65 0.00
2014-02-18 525.70 525.87 517.42 519.98 0.00
2014-02-19 521.39 521.80 515.44 520.63 0.00
2014-02-20 519.70 529.78 517.58 528.86 100.00
2014-02-21 529.74 536.23 526.30 529.77 0.00
2014-02-24 532.90 539.18 531.91 538.94 0.00