For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Bracket order discrepancies
-
Here's the log
2019-07-29T16:11:00, Buying GOOG at price 1241.0930500000002 Stop 1240.0542443892334 Target 1242.131855610767 CurrentPrice 1228.805 2019-07-29T16:12:00, BUY ORDER SUBMITTED for GOOG size 1 Created on 2019-07-29 16:11:00 2019-07-29T16:12:00, SELL ORDER SUBMITTED for GOOG size -1 Created on 2019-07-29 16:11:00 2019-07-29T16:12:00, SELL ORDER SUBMITTED for GOOG size -1 Created on 2019-07-29 16:11:00 2019-07-29T16:12:00, BUY ORDER ACCEPTED for GOOG size 1 Created on 2019-07-29 16:11:00 2019-07-29T16:12:00, SELL ORDER ACCEPTED for GOOG size -1 Created on 2019-07-29 16:11:00 2019-07-29T16:12:00, SELL ORDER ACCEPTED for GOOG size -1 Created on 2019-07-29 16:11:00 2019-07-29T16:12:00, BUY EXECUTED for GOOG, Size 1.000000 Price: 1228.855000, Cost: 1228.855000, Comm 1.228855 2019-07-29T16:13:00, SELL EXECUTED for GOOG, Size -1 , Price: 1229.120000, Cost: 1228.855000, Comm 1.229120
and here's the code which executed it
p1 = d.close[0] *1.01 p2 = d.close[0] *1.01 - 2* std p3 = d.close[0] *1.01 + 2* std self.log("Buying {} at price {} Stop {} Target {} CurrentPrice {}".format(d._name,p1,p2,p3,d.close[0])) valid=self.datas[0].datetime.datetime(0) + datetime.timedelta(minutes = 2) order = self.buy_bracket(d, size=1, exectype=bt.Order.Limit, price=p1, valid=valid, stopprice=p2, limitprice=p3)
As you can see from the logs, the ordered price and the execution price are completely different. Why is this happening?
-
@new_trader I tried using the manual way to create bracket orders using 1 buy and two sell orders. It lead to the same results. I tried to increase the price all the prices by 100 so that they could never get executed but here's the result
2019-07-08T19:08:00, Buying AAPL at price 149.5 Stop 149.47220847072128 Target 149.52779152927872 CurrentPrice 50.0 2019-07-08T19:09:00, BUY ORDER SUBMITTED for AAPL size 1 Created on 2019-07-08 19:08:00 2019-07-08T19:09:00, SELL ORDER SUBMITTED for AAPL size -1 Created on 2019-07-08 19:08:00 2019-07-08T19:09:00, SELL ORDER SUBMITTED for AAPL size -1 Created on 2019-07-08 19:08:00 2019-07-08T19:09:00, BUY ORDER ACCEPTED for AAPL size 1 Created on 2019-07-08 19:08:00 2019-07-08T19:09:00, SELL ORDER ACCEPTED for AAPL size -1 Created on 2019-07-08 19:08:00 2019-07-08T19:09:00, SELL ORDER ACCEPTED for AAPL size -1 Created on 2019-07-08 19:08:00 2019-07-08T19:09:00, BUY EXECUTED for AAPL, Size 1.000000 Price: 49.997500, Cost: 49.997500, Comm 0.049998 2019-07-08T19:10:00, SELL EXECUTED for AAPL, Size -1 , Price: 49.992500, Cost: 49.997500, Comm 0.049993
-
@new_trader Read this page carefully.