def next(self): if len(self.data.Volume) > 4: prices = self.data.Close opens = self.data.Open bodies = self.data.Body ups = self.data.UpShadow lows = self.data.LowerShadow height = self.data.Height dates = self.data.Date current_date = numpy.datetime_as_string(dates[-1], unit="D") isUmbrellaCandlestick = jModel.isUmbrellaCandlestick( bodies[-2], height[-2], ups[-2], lows[-2]) isWhiteCandlestick = jModel.isWhiteCandlestick( opens[-1], prices[-1]) isBlackCandlestick = jModel.isBlackCandlestick( opens[-1], prices[-1]) isShavenHead = jModel.isShavenHead(height[-1], ups[-1]) if isUmbrellaCandlestick is True and isWhiteCandlestick is True and prices[ -1] > prices[-2] and isShavenHead is True: self.buy(sl=0.9 * prices[-1], tp=1.2 * prices[-1]) # self.buy(sl=0.9*prices[-1]) # if isUmbrellaCandlestick is True and isBlackCandlestick is True: # self.position.close() py_date = datetime.datetime.strptime(current_date, "%Y-%m-%d") week_day = py_date.weekday() day = py_date.day if day > 22 and week_day > 2: self.position.close()
def next(self): if len(self.data.Volume) > LOOK_BACK: prices = self.data.Close # if np.datetime64(self.data.Date[-1]) == np.datetime64('2018-01-29T00:00:00.000000000'): # t4 = jModel.isBearishEngulfing(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow) # print('today - isBearishEngulfing - ' + str(t4)) # exit() the1stDayIsBlack = jModel.isBlackCandlestick( self.data.Open[-3], self.data.Close[-3]) isDownTrend = jModel.isDownTrendV1(self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow) the2ndDayIsDoji = jModel.isDoji(self.data.Body[-2], self.data.Height[-2]) todayIsShavenHead = jModel.isShavenHead(self.data.Height[-1], self.data.UpShadow[-1]) todayIsWhite = jModel.isWhiteCandlestick(self.data.Open[-1], self.data.Close[-1]) if isDownTrend is True and the2ndDayIsDoji is True and todayIsShavenHead is True and todayIsWhite is True: hasBuySignal = True else: hasBuySignal = False if hasBuySignal is not False: self.buy(sl=0.9 * prices[-1], tp=1.2 * prices[-1])
def next(self): if len(self.data.Volume) > 4: prices = self.data.Close opens = self.data.Open bodies = self.data.Body ups = self.data.UpShadow lows = self.data.LowerShadow height = self.data.Height dates = self.data.Date prevDayIsSpinningTopCandlestick = jModel.isSpinningTopCandlestick( bodies[-2], height[-2], ups[-2], lows[-2]) prevDayIsBlackCandlestick = jModel.isBlackCandlestick( opens[-2], prices[-2]) prevDayIsWhiteCandlestick = jModel.isWhiteCandlestick( opens[-2], prices[-2]) prevDayMaxOpenClose = opens[ -2] if opens[-2] > prices[-2] else prices[-2] prevDayMinOpenClose = opens[ -2] if opens[-2] < prices[-2] else prices[-2] todayIsWhiteCandlestick = jModel.isWhiteCandlestick( opens[-1], prices[-1]) todayIsBlackCandlestick = jModel.isBlackCandlestick( opens[-1], prices[-1]) todayMaxOpenClose = opens[ -1] if opens[-1] > prices[-1] else prices[-1] todayMinOpenClose = opens[ -1] if opens[-1] < prices[-1] else prices[-1] if prevDayIsBlackCandlestick is True \ and prices[-1] >= opens[-2] \ and opens[-1] <= prices[-2] \ and todayIsWhiteCandlestick is True: # self.buy(sl=0.9*prices[-1], tp=1.2 * prices[-1]) self.buy(sl=0.9 * prices[-1]) if prevDayIsWhiteCandlestick is True \ and prices[-1] <= opens[-2] \ and opens[-1] >= prices[-2] \ and todayIsBlackCandlestick is True: self.position.close() if prevDayIsBlackCandlestick is True \ and ((prices[-1] <= opens[-2] and opens[-1] <= prices[-2] and todayIsBlackCandlestick is True) \ or prevDayMinOpenClose > todayMaxOpenClose): self.position.close()