Ejemplo n.º 1
0
    def next(self):
        prices = self.data.Close
        opens = self.data.Open
        volumes = self.data.Volume
        if len(self.data.Volume) > 5:
            last_price = prices[-1]
            # price is increased
            if last_price > self.trailing_price:
                self.trailing_price = last_price

            if self.buy_price == 0 and Ticker.isFollowTrendingV2(
                    prices, volumes, opens[-1], 2.5):
                self.buy_price = last_price
                self.buy()
            if self.buy_price != 0:
                # print(self.buy_price * (1 - STOPLOSS))
                # print(last_price)
                # print(self.trailing_price * (1 - STOPLOSS))
                # print('------------------------')
                if TakeProfit.takeProfit(
                        15, last_price,
                        self.buy_price) or last_price < self.buy_price * (
                            1 - STOPLOSS
                        ) or last_price < self.trailing_price * (1 - STOPLOSS):
                    print(self.data.Date[-1])
                    self.position.close()
                    self.buy_price = 0
                    self.trailing_price = 0
Ejemplo n.º 2
0
 def next(self):
     prices = self.data.Close
     opens = self.data.Open
     volumes = self.data.Volume
     if len(self.data.Volume) > 5:
         last_price = prices[-1]
         if self.buy_price == 0 and Ticker.isFollowTrendingV2(
                 prices, volumes, opens[-1], 2.5):
             self.buy_price = last_price
             self.buy()
         if self.buy_price != 0 and (TakeProfit.takeProfit(
                 5, last_price, self.buy_price)
                                     or CutLoss.shouldCutLossByPercent(
                                         8, last_price, self.buy_price)):
             self.position.close()
             self.buy_price = 0
Ejemplo n.º 3
0
 def next(self):
     prices = self.data.Close
     opens = self.data.Open
     volumes = self.data.Volume
     lows = pd.DataFrame(data=self.data.Low).Low
     highs = pd.DataFrame(data=self.data.High).High
     if len(prices) > 23:
         last_price = prices[-1]
         atr_22 = _sr.getATR(22, highs, lows)
         if self.buy_price == 0 and Ticker.isFollowTrendingV2(
                 prices, volumes, opens[-1], 2.5):
             self.buy_price = last_price
             self.buy()
         if self.buy_price != 0 and (
             (_sr.takeProfitByPercent(5, last_price, self.buy_price)
              and opens[-1] < prices[-1]
              and abs(highs.iloc[-1] - lows.iloc[-1]) > 2 * atr_22) or
                 _sr.shouldCutLossByPercent(8, last_price, self.buy_price)):
             # if self.buy_price != 0 and ((_sr.takeProfitByPercent(5, last_price, self.buy_price) and abs(highs.iloc[-1] - lows.iloc[-1]) > 2*atr_22 ) or _sr.shouldCutLossByPercent(8, last_price, self.buy_price)):
             self.position.close()
             self.buy_price = 0
Ejemplo n.º 4
0
 def next(self):
     prices = self.data.Close
     opens = self.data.Open
     volumes = self.data.Volume
     # self._index = self._index + 1
     # print("----------"+str(self._index)+"--------")
     if len(self.data.Volume) > 5:
         last_5_volumes = volumes[-5::]
         last_3_prices = prices[-3::]
         # min_volume = min(last_5_volumes)
         max_volume = max(last_5_volumes)
         last_volume = last_5_volumes[-1]
         mean_f = np.mean(volumes[-5:-2])
         last_open_price = opens[-1]
         last_price = prices[-1]
         if self.buy_price == 0 and Ticker.isFollowTrendingV2(prices, volumes, opens[-1], 2.5):
             self.buy_price = last_price
             self.buy()
         if self.buy_price != 0 and (TakeProfit.takeProfit(5, last_price, self.buy_price) or CutLoss.shouldCutLossByPercent(8,last_price,self.buy_price)):
             self.position.close()
             self.buy_price = 0