Thank you for your reply.
I could fix my bag.
The cause of my bag was tradeid.
Thank you.
https://community.backtrader.com/topic/622/multiple-order-managment
Latest posts made by kumagai
-
RE: Can get_analysis() count multiple positions(trades)?
-
RE: There are many trades in the log, but it occuers keyError in the analyzer
Thank you for your replay.
I found the reason is I didn't use tradeid.
In my trade, there are buy,buy,sell,sell.
After I rewrite multitrade version by using tradeid, the bag fixed.
Thank you -
Can get_analysis() count multiple positions(trades)?
I want to count multiple trades.
In my strategy, I buy() at time T and T+1, and I sell() at time T+20 and T+21.
In this case, I desire the amount of tredes by get_analysis is 2.
Otherwise, it return 0 and occuers keyError.
Can't get_analysis() count multiple positions(trades)?
plz help me. -
RE: There are many trades in the log, but it occuers keyError in the analyzer
Thank you for your advice. This is my strategy. The analysis does not work, it couldn't count the amount of trades.
I run get_analysis() and then,
winrate = analysis.won.total / analysis.total.closed
It occuers keyError.def next(self): # 行ごとに呼び出される
#print(self.position) if self.judge_order_buy(): trade_amount= int(self.cash/20/self.dataclose) self.count+=1 #if self.position: # ポジションを持っている場合 # self.close() # self.order=self.buy(size=trade_amount) self.sell_unwind.append([len(self),trade_amount,0]) elif self.judge_order_sell(): trade_amount = int(self.cash/ 20 / self.dataclose) self.order = self.sell(trade_amount) self.buy_unwind.append([len(self), trade_amount, 0]) #if self.order.status in [self.order.Canceled, self.order.Margin, self.order.Rejected]: #self.broker.cancel(self.order) self.unwind_buy_operate() self.unwind_sell_operate() if Close_all_positions: # i = list(range(0, len(self.datas))) # for (d, j) in zip(self.datas, i): for j, d in enumerate(self.datas): if len(d) == d.buflen() - 1: close = self.close(d, exectype=bt.Order.Market)
class strategy_my(myStrategy):
unwind_days = 20 # 1M
count=0def judge_order_buy(self): return self.signal == 1 def judge_order_sell(self): return False def unwind_buy_operate(self, expected_rate=None, loss_cut_rate=None): for i, buy in enumerate(self.buy_unwind): if buy[0] + self.unwind_days == len(self) and buy[1] > 0: # Unwind at the last day self.buy(size=buy[1]) self.buy_unwind[i][1] = 0 def unwind_sell_operate(self, expected_rate=None, loss_cut_rate=None): for i, sell in enumerate(self.sell_unwind): if sell[0] + self.unwind_days == len(self) and sell[1] > 0: # Unwind at the last day print(len(self)) if self.position: # ポジションを持っている場合 self.order=self.close(size=sell[1]) self.sell_unwind[i][1] = 0
-
There are many trades in the log, but it occuers keyError in the analyzer
There are many trades in the log, but it occuers keyError.
analysis["total"]["total"] is 1.
How can I fix it?
