Hi all,
First, thanks for all the contributors' work on Backtrader project, this is a very nice framework compare with what I used before.
I have a question with the build in stop trail order. I use OANDA api before, maybe this influence my understanding on STOP Orders.
In OANDA, when I pose a buy market order with trailing stop, the order will be executed as soon. Then if the price go down in a certain percent, then a sell market order active. If price go up, the order will keep trailing.
mktOrder = MarketOrderRequest(instrument=instruments, units=units, trailingStopLossOnFill=trailingStopLossOnFill.data)
self.order = self.buy(exectype=bt.Order.StopTrail, trailpercent=self.p.trailingPercent, valid = valid1)
After investigate the API doc of backtrader, in my understanding (if correct), the above buy order with a stop trail type means the order will be actived as market order once the price go up exceed a certain percent = self.p.trailingPercent, within time delta = valid1. And if the price go down within valid time, the buy order won't be executed. Once the order exceed valid time, this order will be cancelled.
- Question 3
To achieve what OANDA API do. In backtrader, I need to pose a buy order, and then pose a sell stop trail order (as the example below):
self.buy(size=1)
self.sell(size=1, exectype=bt.Order.StopTrail, price=10.50, trailpercent=0.0.02)
if not self.position:
if Signal = buy_signal:
self.order = self.buy(exectype=bt.Order.StopTrail, trailpercent=self.p.trailingPercent, valid = valid1)
else:
if Signal = sell_signal:
self.order = self.close()
This means,
If we have a buy signal, we pose a buy trail stop order in the market. Then,
-
a: if the price continue go up to a certain threshold, a buy market order will be posed. Once the buy order active, we wait for sell signal to close the position.
-
b: if the price continue go down, the buy order won't become market buy until exceed time threshold valid1, the order will be cancelled.
-
c: During the price going down period, the trail price will be updated.
Thanks,
Ciceron