For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Multiple notify_order logs



  • Hello everyone,

    I created a simple strategy that does a prediction for the close price of the next day and invests accordingly. If an increase is predicted, the broker will invest 20% of the starting capital. If a decrease is predicted, it will short 20% of the investment. This is for foreign exchange prices. The code is as follows.

    def notify_order(self, order):
            if order.status in [order.Completed]:
                if order.isbuy():
                    self.log("BUY EXECUTED {}".format(order.executed.price))
                elif order.issell():
                    self.log("SELL EXECUTED {}".format(order.executed.price))
    
            self.order = None
    
        def next(self):
            prediction = #prediction code returning 0 (decrease) or 1 (increase)
    
            self.log('Close, %.5f' % self.dataclose[0])
    
            STAKE_PERCENTAGE = 0.2
            STAKE = math.floor(self.starting_cash / self.dataclose[0] * STAKE_PERCENTAGE)
    
            if prediction == 1:
                if (self.position.size < 0):
                    self.close()
    
                if (self.position.size + STAKE < self.broker.getvalue() / self.dataclose[0]):
                    self.log('BUY CREATE, %.5f, size %.2f' % (self.dataclose[0], STAKE))
                    self.order = self.buy(size=STAKE)
            elif prediction == 0:
                if (self.position.size > 0):
                    self.close()
    
                if (self.position.size + STAKE < self.broker.getvalue() / self.dataclose[0]):
                    self.log('SELL CREATE, %.5f, size %.2f' % (self.dataclose[0], STAKE))
                    self.order = self.sell(size=STAKE)
    

    My problem is that in the logs I sometimes see more than 1 notify_order log. An example is the following log:

    2018-08-13, BUY CREATE, 1.56699, size 12763.00
    2018-08-14, BUY EXECUTED 1.56703
    2018-08-14, BUY EXECUTED 1.56703
    

    Why is this happening? Am I doing something wrong here? I get some pretty high returns (up to 60% ROI in a year) and very few losses for some currencies.

    Any other general advice is appreciated.



  • Sometimes you issue two orders on the same next() call: self.close and self.buy or self.sell. Therefore two notifications called.



  • @ab_trader Aaah, that makes sense. Thanks a lot!


Log in to reply
 

});