Great, thank you for clearing that up for me.
Posts made by leecallen
RE: Resampling from my own data feed - strange behavior
Resampling from my own data feed - strange behavior
Basically: When strategy next() is called, it is receiving a bar from both the original datafeed, and the resampled datafeed in a single pass. Is that expected? Can I assume all the lines are correct for each data feed?
In other words:
if len( self.datas ) > self.lendata0:
self.lendata0 += 1
if len( self.datas ) > self.lendata1:
self.lendata1 += 1
Both 'if' tests are successful in a single call to next(). If the second test is changed to 'elif' my code never processes datas1 bars.
Live Trading and Compression - question
I have been using BT for a couple years for backtesting on Forex. Now I am preparing to move into live trading, using Oanda.
I'm not sure what compression does in terms of live trading. If I say I want 1-minute bars, does Oanda handle that - does it accumulate the data and send it to my system once per minute? Or does Oanda send tick data and BT (or the Oanda API) summarizes it into 1M bars?
I am planning on running my algo on multiple currency pairs and time-frames, and I want to design this for reasonable performance and minimal traffic.
And question #2 if I can...
I see a lot more documentation "out there" for BT with Interactive Brokers than for Oanda. And the Oanda interface uses their V1 API. Should I be concerned that I am using a less used, possibly less tested and maintained platform?
RE: My stop-loss order is getting executed when it shouldn't
@leecallen Never mind -- I figured it out.
The next bar at 7:45 hits both the SL and the TP. And then I remembered: in Backtrader the order events get processed before the next() logic. And some bug in my code (I know where it is) is posting the prev-bar datetime in my logging.
And I guess I need to set up OCO or bracket orders or something so my SL and TP can't both fire.
My stop-loss order is getting executed when it shouldn't
Hi. This is a big program, I have been using it for a long time, but yesterday I discovered a problem and it's driving me crazy.
I am back-testing using Forex 5M data.
I open a BUY market order on 7/24 at 14:00.
The order Completes (opening the order) in the next bar at 14:05 at price 1.11351.
I open a stop-loss order below my executed BUY price:
self.sell( exectype=bt.Order.Stop, price=1.11194, size=self.order_size )
and a take-profit order above my executed price:
self.sell( exectype=bt.Order.Limit, price=1.11520, size=self.order_size )
Many bars go by that don't have lows below my SL or highs above my TP.
Then the next morning at 7:40 I get this bar:
Date Time Open High Low Close Volume 25.04.2019 07:40:00.000 GMT-0400,1.11243,1.11260,1.11235,1.11259,1505.38
the low is still above my SL and the high is still below my TP, but both my SL and TP orders complete!
My next() method is printing each bar so I know that's the one.
Here's a dump of my SL order -- print(order) in the notify_order for status Completed:
2019-07-25T07:40:00-04:00, 1.11416 1.11433 1.11394 1.11396 33.958517326947884 1.0 2 Ref: 41 OrdType: 1 OrdType: Sell Status: 4 Status: Completed Size: -100 Price: 1.1119400000000002 Price Limit: None TrailAmount: None TrailPercent: None ExecType: 3 ExecType: Stop CommInfo: <backtrader.comminfo.CommInfoBase object at 0x7fde4c3ad780> End of Session: 737264.9999999999 Info: AutoOrderedDict([('type', 'sl'), ('parent', 40)]) Broker: None Alive: False 2019-07-25T07:40:00-04:00, order #41 SELL completed, info AutoOrderedDict([('type', 'sl'), ('parent', 40)]) price 1.11194 size 100.00 pnl -0.16 pprice 0.00000 balance 999
Why did that SL order fire?
I'm running Backtrader 18.104.22.168
Any ideas would be hugely appreciated.
RE: Smart optimizations and performance
Actually I think all the information I need is here:
I will work on that. If you can pass on any additional tips I would sure appreciate them.