def testTRIX(self): barDs = self.__loadBarDS() self.assertAmountsAreEqual( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[13], 0.2589) self.assertAmountsAreEqual( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[14], 0.010495) self.assertAmountsAreEqual( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[-2], -0.058) self.assertAmountsAreEqual( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[-1], -0.095)
def enterShortSignal(self, extPriceBarDS, extPriceDS): trixNear = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixNearPeriod) trixFar = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixFarPeriod) shortEntryFilter_1 = cross.cross_below(trixNear, trixFar) > 0 return shortEntryFilter_1
def enterLongSignal(self, extPriceBarDS, extPriceDS): trixNear = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixNearPeriod) trixFar = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixFarPeriod) longEntryFilter_1 = cross.cross_above(trixNear, trixFar) > 0 return longEntryFilter_1
def exitShortSignal(self, shortPos, extPriceBarDS, extPriceDS): trixNear = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixNearPeriod) trixFar = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixFarPeriod) shortExitFilter_1 = cross.cross_above(trixNear, trixNear[:-1]) > 0 shortExitFilter_2 = shortPos.exitActive() return shortExitFilter_1 and not shortExitFilter_2
def exitLongSignal(self, longPos, extPriceBarDS, extPriceDS): trixNear = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixNearPeriod) trixFar = indicator.TRIX(extPriceDS, count=100, timeperiod=self.trixFarPeriod) longExitFilter_1 = cross.cross_below(trixNear, trixNear[:-1]) > 0 longExitFilter_2 = longPos.exitActive() return longExitFilter_1 and not longExitFilter_2
def testTRIX(self): barDs = self.__loadBarDS() self.assertTrue( compare( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[13], 0.2589)) self.assertTrue( compare( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[14], 0.010495)) self.assertTrue( compare( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[-2], -0.058)) self.assertTrue( compare( indicator.TRIX(barDs.getCloseDataSeries(), 252, 5)[-1], -0.095))