def next(self): if len(self.data.Volume) > LOOK_BACK: prices = self.data.Close hasBuySignal = jModel.hasCustomBuySignal( self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow) hasSellSignal = jModel.hasCustomSellSignal( self.data.Open, self.data.Close, self.data.High, self.data.Low, self.data.Body, self.data.Height, self.data.UpShadow, self.data.LowerShadow) # 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() if hasBuySignal is not False and self.orderPending is False: self.buy() self.orderIndex = self.orderIndex + 1 print( str(self.orderIndex) + ". Buy at " + str(self.data.Date[-1]) + " by signal: " + str(hasBuySignal)) self.orderPending = True if hasSellSignal is not False and self.orderPending is True: self.position.close() print("----------- Sell at " + str(self.data.Date[-1]) + " by signal: " + str(hasSellSignal)) self.orderPending = False
import warnings warnings.filterwarnings('ignore') import os import sys METHOD_MODULE_PATH = os.path.abspath('../..') sys.path.insert(1, METHOD_MODULE_PATH) import method.algofuncs as _af import method.JavCan as jModel DATA_PATH = os.path.abspath('../../vn-stock-data/VNX/') hold_tickers = ['ABB', 'ACB', 'BSR', 'FPT', 'GMD', 'OCB', 'PVS', 'PVT', 'STB', 'TPB', 'VCI', 'VHG', 'VND', 'VGT'] printedDate = False for ticker_id2 in hold_tickers: ticker_data = _af.get_pricing_by_path(DATA_PATH + '/' + ticker_id2 + '.csv', '2021-05-01') if printedDate == False: print(ticker_data.Date[-1]) printedDate = True _1hit_data = ticker_data.tail(10) new_data = jModel.convertToJapanCandle(_1hit_data) hasSellSignal = jModel.hasCustomSellSignal(new_data.Open, new_data.Close, new_data.High, new_data.Low, new_data.Body, new_data.Height, new_data.UpShadow, new_data.LowerShadow, new_data.Date) if hasSellSignal is not False: print(ticker_id2 + ' -- ' + str(hasSellSignal)) # print(jModel.isBlackCandlestick(new_data.Open[-3], new_data.Close[-3])) # print(jModel.isBlackCandlestick(new_data.Open[-2], new_data.Close[-2])) # print(jModel.isBlackCandlestick(new_data.Open[-1], new_data.Close[-1]))