Oandav20 separate trail order
-
Hi
I like to ask if anyone has experience with creating a single trail order in oanda. I tried the below but got the following error:
self.long_trailstop = self.sell(price=trail_stop_px, exectype=bt.Order.StopTrail, size=stop_size, trailamount=self.ATR_at_exe * 1.5, id='888') but the above does not work.
I got an error which bascially is an error when issuing stoptrail orders without brackets.
okwargs['type'] = self._ORDEREXECS[order.exectype] KeyError: 5
Will some kind souls help me out with this?
Thanks alot!
-
See the latest changes in btonadav20. I have added a somehow simulation of a StopTrail, StopLimit and StopTrailLimit order using brackets. Since these orders are not supported by oanda, I used a stop order to enter, when the entry order is filled, the trail stop is attached to the trade. You can replace the trail stop with a new one, too.
It is using a stop order to enter the market and issues a trailing stop loss order on the stop side. See readme how to use them.
Also the latest change added a possibility to replace pending orders using the replace param.If there are any issues, open a ticket. I have tested it with stop limit orders and it works fine.
Example of create buy StopTrail order
o, ostop, olimit = buy_bracket(exectype=bt.Order.Stop, stopexec=bt.Order.StopTrail, stopargs={trailpercent or trailamount}, limitexec=None)
Create new trailing stop for parent order
self.sell(exectype=bt.Order.StopTrail, replace=ostop.ref, trailamount or trailpercent)