Edited the snippet from above to reflect that the correct usage is with date2num (obviously)
Of course using the If from backtrader allows for much more complex scenarios. The 1 + boolean in the snippet was just meant to solve the hypothetical case presented above (1 until date x, 2 from that point onwards)
Completely noob question - For forex using Oanda as broker.. How do I realistically model commission on Cerebro? (I know the spread is built-in, which I get through the feed)
You cannot. As you point out: it is built in the spread. There is no way to separate it in real life and there cannot therefore be a way to simulate that.
Is there a way to tell (in next() or another predefined method) if the end of the data feed has been reached?
Your strategy will stop calling next and will call stop
Suppose i have a datafeed that I use pandas to resample in 1 minute time frame. And because of volume issues, instead of using cerebro.resampledata(), i want to use pandas to resample to 3 minute time frame. Do I need to pass this pandas resampled data by calling cerebro.resampledata() or cerebro.adddata()? And what timeframe/compression timeframe parameter do I need to add (since it's already resampled in pandas)? Is it bt.TimeFrame.Minutes / 3?
If you don't want to resample in backtrader, don't use resampledata, which means you use adddata. You should tell the platform that your data has a combination of Minutes and 3
Currently, im taking the average (ask + bid / 2) to calculate OHLC for both price and via pandas. What is the fundamental problem with using the average to write your algo? I would think that it might be smarter to calculate long entry position based on ask price & volume... and short position on bid price / volume, but this would mean keeping "two" copies of data stream
If your assumption about the slippage isn't that bad, using the MIDPOINT should be fine. Slippage will get you below/above the BID/ASK prices and therefore give you a good approximation.
The only thing I would guess is that creating the stop limit order "gives" hints to the broker... who might be using it against you if their not None-Dealing-Desk broker.
If you are worried about that, you should be operating with a different broker and probably a different market altogether.
There is no need for logic there and that's why there is none. The entry order (aka main side) is protected automatically with a stop-loss side and a take-profit side (the high/low side depends on the direction entry), which are only active if the entry order is executed.
Once the stop-loss/take-profit sides become active, the execution of any of them automatically cancels the other.
If you decide to exit the market with an unrelated order, you have to manually cancel any of the sides (the other will be cancelled automatically) as in
self.cancel(order_stop_loss_side) # this automatically cancels the take-profit side too
@backtrader Good catch! I will find a better name for it. I think for the frequency and nature of the strategy, it works perfectly fine, especially when dividend/reinvestments are taken into account in these slow moving strategies.
Thanks for the continued help so far. It is great that you spend so much time to help the community in addition to the good work done to develop the framework.
I tried comparing using the script and initially got the same results. I.e The same values were being output. Eventually, later in the day I managed to get it working but if I am honest, I am not sure how. One thing I did was sync my clock with an NTP server as my time was a little off. However I can't imagine how that would have helped though.
BTW - The exec statements in my script are there just to import custom indicators under the same name name (i.e ind1) so I can easily switch the indicator used in my config file without going into the code. There might be a better way of doing that but that is where experience comes into play. :)