Closed einnairo closed 4 years ago
Other actions taken:
Quick change to oandav20store.py
# Order type matching with oanda _ORDEREXECS = { bt.Order.Market: 'MARKET', bt.Order.Limit: 'LIMIT', bt.Order.Stop: 'STOP', bt.Order.StopLimit: 'STOP', bt.Order.StopTrail: 'TRAILING_STOP_LOSS', # added this line }
But bunch of errors. Program continues running. I think there is not enough code to link single trail orders to oanda api.
This will not work, since we need to process the trail stop transactions correctly. I will add some support this weekend when I get to it.
I have committed a update to the store which enabled trail stop orders, but when using it, you will need to provide the order id to close when creating an order. Put the order id to cancel in the param "oref".
Because the order type is not supported by oanda, I am not really sure how to add this else. Here you can see all supported order types in oanda:
i also see, that the code won't work, since the trail stop order needs to be set for a trade. at the moment, there are no trade ids stored, but I will most probably add them. we then know, which order created an trade. so we can later look, which order created which trade. but to open a trail stop order, you will have to have an open trade, provide the oref to buy or sell call, then it should work.
in code I will look up the trade id, if there is any available for the order.
Support for StopTrail, StopLimit or StopTrailLimit is only available through bracket_orders, see README.md for details.
If there are any issues with the implementation open a new issue
Hi! As discussed, am having an error putting in a single stoptrail order without brackets.
Code is as below.
error:
Traceback (most recent call last): File "C:/Users/bob/Trade/Algo/oanda.py", line 195, in <module> strat = cerebro.run(maxcpus=2, exactbars=-1, runonce=False) File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies self._runnext(runstrats) File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\cerebro.py", line 1630, in _runnext strat._next() File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\strategy.py", line 347, in _next super(Strategy, self)._next() File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\lineiterator.py", line 271, in _next self.next() File "C:/Users/bob/Dropbox/Trade/Algo/oanda.py", line 157, in next self.long_trailstop = self.sell(price=trail_stop_px, exectype=bt.Order.StopTrail, size=stop_size, trailamount=self.ATR_at_exe * 1.5) File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\backtrader\strategy.py", line 963, in sell return self.broker.sell( File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\btoandav20\brokers\oandav20broker.py", line 315, in sell return self._transmit(order) File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\btoandav20\brokers\oandav20broker.py", line 277, in _transmit return self.o.order_create(order) File "C:\Users\bob\AppData\Local\Programs\Python\Python38\lib\site-packages\btoandav20\stores\oandav20store.py", line 360, in order_create okwargs['type'] = self._ORDEREXECS[order.exectype] KeyError: 5
Other actions taken:
Quick change to oandav20store.py
But bunch of errors. Program continues running. I think there is not enough code to link single trail orders to oanda api.
Pls help us to have a look. Thanks!!