For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Execution price problem with order for multiple stocks
-
Hi all!
I am new to backtrader and countering some difficulty about the transaction part. For some reason I don't know, the execution price for the order is always 0 when I try to run a portfolio strategy, though it looks all good when I step back and test a single stock test strategy.I printed the open price data supposed to be used, and it seems all right. And I tried both simple buy order and target percent order, both return the same issue.
Hers is the code and result. It would be much appreciated for you help. Thanks very much!
Code:
Result:
-
Hello! )) Please resend your screen shots again.
-
This post is deleted! -
Hello! I am using the same construction, and all seems OK:
self.log(ticker + f": >>> BUY ORDER '{order.info.level_name}' COMPLETED at {order.executed.price:.{globals.f_decimal[ticker]}f} price, " f"size = {order.size}, Cost={order.executed.value:.2f}, Comm={order.executed.comm:.2f}, " f"DEPO={self.cerebro.broker.getcash():.2f}, Was Created={order.info.created_date}") self.log_for_csv(ticker=ticker, level_name=order.info.level_name, order='BUY', order_price=f"{order.executed.price:.{globals.f_decimal[ticker]}f}", size=order.size, status=order.getstatusname(order.status), cost=f"{order.executed.value:.2f}", comm=f"{order.executed.comm:.2f}", amount="?", bar_high=order.data.high[0], bar_low=order.data.low[0])
Have you resolved your problem?