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.