Beispiel #1
0
 def testMACD(self):
     barDs = self.__loadBarDS()
     self.assertTrue(
         compare(
             indicator.MACD(barDs.getCloseDataSeries(), 252, 12, 26,
                            9)[0][33], -1.9738))
     self.assertTrue(
         compare(
             indicator.MACD(barDs.getCloseDataSeries(), 252, 12, 26,
                            9)[1][33], -2.7071))
     self.assertTrue(
         compare(
             indicator.MACD(barDs.getCloseDataSeries(), 252, 12, 26,
                            9)[2][33], (-1.9738) - (-2.7071)))
     self.assertTrue(
         compare(
             indicator.MACD(barDs.getCloseDataSeries(), 252, 26, 12,
                            9)[0][33], -1.9738))
     self.assertTrue(
         compare(
             indicator.MACD(barDs.getCloseDataSeries(), 252, 26, 12,
                            9)[1][33], -2.7071))
     self.assertTrue(
         compare(
             indicator.MACD(barDs.getCloseDataSeries(), 252, 26, 12,
                            9)[2][33], (-1.9738) - (-2.7071)))
Beispiel #2
0
 def testMACD(self):
     barDs = self.__loadBarDS()
     self.assertAmountsAreEqual(indicator.MACD(barDs.getCloseDataSeries(), 252, 12, 26, 9)[0][33], -1.9738)
     self.assertAmountsAreEqual(indicator.MACD(barDs.getCloseDataSeries(), 252, 12, 26, 9)[1][33], -2.7071)
     self.assertAmountsAreEqual(
         indicator.MACD(barDs.getCloseDataSeries(), 252, 12, 26, 9)[2][33],
         (-1.9738)-(-2.7071)
     )
     self.assertAmountsAreEqual(indicator.MACD(barDs.getCloseDataSeries(), 252, 26, 12, 9)[0][33], -1.9738)
     self.assertAmountsAreEqual(indicator.MACD(barDs.getCloseDataSeries(), 252, 26, 12, 9)[1][33], -2.7071)
     self.assertAmountsAreEqual(
         indicator.MACD(barDs.getCloseDataSeries(), 252, 26, 12, 9)[2][33],
         (-1.9738)-(-2.7071)
     )
Beispiel #3
0
    def onBars(self, bars):
        # closePrice = bars[self.__instrument].getPrice()
        closePrice = self.getFeed().getDataSeries(
            instrument).getCloseDataSeries()
        date = bars.getDateTime()

        self.__dif, self.__dea, self.__macd = indicator.MACD(
            closePrice, 200, self.__fast, self.__slow, self.__signal)

        if date < date1:
            return

        if self.__macd[-1] is None:
            return

        if self.__position is not None:
            if not self.__position.exitActive() and self.__macd[-1] < 0:
                self.__position.exitMarket()

        if self.__position is None:
            if self.__macd[-1] > 0:
                shares = int(self.getBroker().getEquity() * 0.9 /
                             bars[self.__instrument].getPrice())
                self.__position = self.enterLong(self.__instrument, shares)