@marsario I know that backtrader can be frustrating when you first start. Trust me I know. However, I would argue, after looking some more at your code, that you must first learn to walk before you run. And you are already trying to run.
You need to take a step back and work through some of the examples.
But if you insist on tackling a multi data/multi indicator dictionary strategy to start, here are a few more tips.
Add in these loggers they will give you more information:
def notify_order(self, order):
self.log(
"Order ref: {} / Type {} / Status {}".format(
order.ref, "Buy" * order.isbuy() or "Sell", order.getstatusname()
)
)
if order.status == order.Completed:
self.holdstart = len(self)
# if not order.alive() and order.ref in self.orefs:
# self.orefs.remove(order.ref)
def notify_trade(self, trade):
"""Provides notification of closed trades."""
dt = self.data.datetime.datetime()
if trade.isclosed:
print(
"{} {} Closed: PnL Gross {}, Net {},".format(
dt,
trade.data._name,
round(trade.pnl, 2),
round(trade.pnlcomm, 1),
)
)
You don't need the try/except clause.
When you add the loggers above, you will see you are getting margin notice. This means there's not enough cash. This is because you are trying to buy 100% of the cash value of the account and TSLA is rising. You need to use a percentage of the account. You could use Cheat On Open, but again, that's a bit advanced.
The following makes no sense in backtrader.
best_mo_data.open[1]
The numbering goes 0, -1, -2, etc.
IMHO, you need to read the docs and work on simpler examples.
Good luck.