Пример #1
0
    def run(self):
        self.stop = False
        active_trade = False
        profits = 0
        self.trailingstop = Trailingstop(self.datum[0]['close'],
                                         self.stoploss_percentage)
        while not self.stop:
            signal = self.indicator.get_signal()
            if signal == 'buy' and not active_trade:
                #buy
                self.buy()
                self.trailingstop = Trailingstop(self.datum[0]['close'],
                                                 self.stoploss_percentage)
                active_trade = True

            elif signal == 'sell' and active_trade:
                #sell
                self.sell()
                active_trade = False

            elif signal == 'wait' and active_trade:
                if self.datum[0]['close'] <= self.trailingstop.stop:
                    self.sell()
                    active_trade = False
                else:
                    print('[' + self.name + ']: is waiting. ' +
                          str(self.datum[0]))
            elif signal == 'wait':
                print('[' + self.name + ']: is waiting. ' + str(self.datum[0]))

            self.get_candle()