For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
how to reset the buy limit price everyday if no trade is open
-
Hello community,
this is my strategy:
- long only. 1 hour bar chart. Everyday at 01:00, new buy limit order with stop loss and take profit orders will be created.
- buy limit price is 80% of BTC open price. i added a new column in datasheet named btcopen.
- if at 23:00, no order is filled, all orders will be cancelled.
- next day, repeat from 1 to 4
my problem:
- let's say on 1 Oct, BTC open price = 10,000. buy price will be 8,000. But at 23:00, price still doesn't fall to 8,000, so all orders are cancelled.
- on 2 Oct and 3 Oct, price didn't fall to 80% of BTC open price as well. For simplicity sake, let's say the buy price on 2 Oct is 8,100 and buy price on 3 Oct is 7,900. so all orders are void.
- on 4 Oct, the buy price is calculated to be 7,800. However, buy order is filled with buy price 8,100 (2 Oct). Seems the the buy price is still recorded as 8,100 until the order of this price is filled, then only it will reset.
- this issue always occur when no orders are filled on a particular day. the buy price on this day will be carried over to the next day until it's being filled.
How can i reset the buyprice everyday even though no orders are filled? My code is below. Hope you guys can help. Many tks.
if not self.position.size and self.datas[0].datetime.time() == datetime.time(self.p.b_entrytime , 0): buyprice = self.data.btcopen * 0.80 self.order = self.buy(size=100/buyprice, exectype=bt.Order.Limit, price=buyprice, transmit=False) b_stop_price = buyprice* (1.0 - self.p.stop_loss) b_take_profit = buyprice * (1.0 + self.p.take_profit) self.b_stop_loss = self.sell(size=100/buyprice, exectype=bt.Order.Stop, price=b_stop_price, parent=self.order,transmit=False) self.b_take_profit = self.sell(size=100/buyprice, exectype=bt.Order.Limit, price=b_take_profit, parent=self.order,transmit=True) if self.datas[0].datetime.time() == datetime.time(self.p.b_exittime , 0): self.order = self.close() self.cancel(self.b_stop_loss) self.cancel(self.b_take_profit) return
-
My problems (Corrections):
- let's say on 1 Oct, BTC open price = 10,000. buy price will be 8,000. Price falls below 8,000 and buy order is filled. But at 23:00, price doesnt hit stop loss or take profit. All orders are closed.
- on 2 Oct and 3 Oct, price didn't fall to 80% of BTC open price as well. For simplicity sake, let's say the buy price on 2 Oct is 8,100 and buy price on 3 Oct is 7,900. so all orders are void.
- on 4 Oct, the buy price is calculated to be 7,800. However, buy order is filled with buy price 8,100 (2 Oct). Seems like the the buy price is still recorded as 8,100 until the order of this price is filled, then only it will reset.
- this issue always occur when no buy limit order is filled on a particular day. the buy price on this day will be carried over to the next day until it's being filled.
-
@kian-hong-tan
Hello @rajanprabu @ab_trader ! Are you guys able to help? much appreciated.