def exitLongSignal(self, longPos, extPriceBarDS, extPriceDS):
        upper, middle, lower = indicator.BBANDS(extPriceDS,
                                                count=100,
                                                timeperiod=self.bBandsPeriod,
                                                matype=MA_Type.SMA,
                                                nbdevup=self.numStdDev,
                                                nbdevdn=self.numStdDev)

        longExitFilter_1 = cross.cross_above(extPriceDS, middle) > 0
        longExitFilter_2 = longPos.exitActive()
        return longExitFilter_1 and not longExitFilter_2
    def exitShortSignal(self, shortPos, extPriceBarDS, extPriceDS):
        upper, middle, lower = indicator.BBANDS(extPriceDS,
                                                count=100,
                                                timeperiod=self.bBandsPeriod,
                                                matype=MA_Type.SMA,
                                                nbdevup=self.numStdDev,
                                                nbdevdn=self.numStdDev)

        shortExitFilter_1 = cross.cross_below(extPriceDS, middle) > 0
        shortExitFilter_2 = shortPos.exitActive()
        return shortExitFilter_1 and not shortExitFilter_2
예제 #3
0
 def testBBANDS(self):
     barDs = self.__loadBarDS()
     # EMA
     self.assertTrue(
         compare(
             indicator.BBANDS(barDs.getCloseDataSeries(), 252, 20, 2.0, 2.0,
                              talib.MA_Type.EMA)[0][19 + 13], 93.674))
     self.assertTrue(
         compare(
             indicator.BBANDS(barDs.getCloseDataSeries(), 252, 20, 2.0, 2.0,
                              talib.MA_Type.EMA)[1][19 + 13], 87.679))
     self.assertTrue(
         compare(
             indicator.BBANDS(barDs.getCloseDataSeries(), 252, 20, 2.0, 2.0,
                              talib.MA_Type.EMA)[2][19 + 13], 81.685))
     # SMA
     self.assertTrue(
         compare(
             indicator.BBANDS(barDs.getCloseDataSeries(), 252, 20, 2.0, 2.0,
                              talib.MA_Type.SMA)[0][19], 98.0734))
     self.assertTrue(
         compare(
             indicator.BBANDS(barDs.getCloseDataSeries(), 252, 20, 2.0, 2.0,
                              talib.MA_Type.SMA)[1][19], 92.8910))
     self.assertTrue(
         compare(
             indicator.BBANDS(barDs.getCloseDataSeries(), 252, 20, 2.0, 2.0,
                              talib.MA_Type.SMA)[2][19], 87.7086))
    def enterLongSignal(self, extPriceBarDS, extPriceDS):
        upper, middle, lower = indicator.BBANDS(extPriceDS,
                                                count=100,
                                                timeperiod=self.bBandsPeriod,
                                                matype=MA_Type.SMA,
                                                nbdevup=self.numStdDev,
                                                nbdevdn=self.numStdDev)
        fastk, fastd = indicator.STOCHF(extPriceBarDS,
                                        count=100,
                                        fastk_period=self.soPeriod,
                                        fastd_period=self.soDPeriod,
                                        fastd_matype=MA_Type.SMA)

        rsi = indicator.RSI(extPriceDS, count=100, timeperiod=self.rsiPeriod)

        longEntryFilter_1 = rsi[-1] <= self.overSoldThreshold
        longEntryFilter_2 = fastd[-1] <= self.overSoldThreshold
        longEntryFilter_3 = cross.cross_below(extPriceDS, lower) > 0
        return longEntryFilter_1 and longEntryFilter_2 and longEntryFilter_3