def testAROONOSC(self): barDs = self.__loadBarDS() self.assertTrue(compare(indicator.AROONOSC(barDs, 252, 14)[14], -21.4285)) self.assertTrue(compare(indicator.AROONOSC(barDs, 252, 14)[14+6], -21.4285)) self.assertTrue(compare(indicator.AROONOSC(barDs, 252, 14)[14+7], -71.4285)) self.assertTrue(compare(indicator.AROONOSC(barDs, 252, 14)[-2], -28.5714)) self.assertTrue(compare(indicator.AROONOSC(barDs, 252, 14)[-1], -14.28571))
def testAROONOSC(self): barDs = self.__loadBarDS() self.assertAmountsAreEqual(indicator.AROONOSC(barDs, 252, 14)[14], -21.4285) self.assertAmountsAreEqual(indicator.AROONOSC(barDs, 252, 14)[14+6], -21.4285) self.assertAmountsAreEqual(indicator.AROONOSC(barDs, 252, 14)[14+7], -71.4285) self.assertAmountsAreEqual(indicator.AROONOSC(barDs, 252, 14)[-2], -28.5714) self.assertAmountsAreEqual(indicator.AROONOSC(barDs, 252, 14)[-1], -14.28571)
def onBars(self, bars): if self._active: for instrument, bar in bars.items(): # Wait for enough bars to be available to calculate a SMA. if not self._smaLong[instrument] or self._smaLong[instrument][-1] is None: return barDs = self.getFeed().getDataSeries(instrument) aroon = indicator.AROONOSC(barDs, self._aroonPeriod + 1, self._aroonPeriod) self._aroon[instrument].appendWithDateTime(self.getCurrentDateTime(), aroon[-1]) pri = self._macdPrice[instrument] vol = self._macdVol[instrument] if instrument in self._posLong: if cross.cross_below(self._smaShort[instrument], self._smaLong[instrument]) and aroon[-1] < -self._aroonOut: position = self._posLong[instrument] self.prepareExit(position) elif instrument in self._posShort: if cross.cross_above(pri.getSignal(), pri) and aroon[-1] > 25: position = self._posShort[instrument] self.prepareExit(position) if cross.cross_above(self._smaShort[instrument], self._smaLong[instrument]) and aroon[-1] > 25: self.prepareEnter(instrument, bars) elif cross.cross_below(pri.getSignal(), pri) and cross.cross_above(vol.getSignal(), vol) and aroon[-1] < -self._aroonIn: self.prepareEnter(instrument, bars, broker.Order.Action.SELL_SHORT)
def onBars(self, bars): for instrument, bar in bars.items(): # Wait for enough bars to be available to calculate a SMA. if not self._smaLong[ instrument] or self._smaLong[instrument][-1] is None: return barDs = self.getFeed().getDataSeries(instrument) aroon = indicator.AROONOSC(barDs, self._aroonPeriod + 1, self._aroonPeriod) self._aroon[instrument].appendWithDateTime( self.getCurrentDateTime(), aroon[-1]) if instrument in self._posLong: if cross.cross_below( self._smaShort[instrument], self._smaLong[instrument]) and aroon[-1] < -50: position = self._posLong[instrument] self.prepareExit(position) if cross.cross_above(self._smaShort[instrument], self._smaLong[instrument]) and aroon[-1] > 50: self.prepareEnter(instrument, bars)