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
Thanks @backtrader. That will cover most cases. Maybe the SAREXT indicator should also be added?
In my case I'm working with a very large datasheet so to avoid performance issues I've coded something like:
self.psar0._lookback = min(100, len(self.data0))
so I have a "dynamic" _lookback from 1 to 100
And why 100?... newbie here! just by observation, it seems to be a good value to calculate a real ParabolicSAR value.
@jacob said in Indicator using multi datafeed: operate only on overlapping bar:
this is a great workaround for this issue/bug.
This is not a workaround. It is clearly stated in the FAQ: Community - FAQ
The system cannot know which timeframe/compression your data feed has unless you tell the system.
@Paska-Houso said in Genetic Optimization:
The built-in optimization (cerebro.optstrategy) was always there from day one. This thread is about Genetic Optimization which implies not simply blindly traversing the cartesian product of all possibilities, but choosing and discarding paths based on outcomes of run. I.e.: If you have 3 parameters and one of the runs gives you a -50% profit, it is highly unlikely that slightly modifying one of the parameters for the next run is going to suddenly make you reach. It will likely deliver a result around -50%. You can therefore discard this part of the tree and focus on some other branches.
checksubmit controls if a submitted order can be accepted by the broker by simulating execution and with it checking if the current cash reserves are enough. It actually pseudo-executes all pending orders, because an order could actually be 1st opening a short and increasing the pseudo-cash reserves.
But this is only pseudo-execution. When the actual execution takes place, the actual cash level is checked again and execution will be rejected if not possible.
My example was with daily bars, as I think is more close to the reality. At the end, forgetting about the -coc option for a moment, if you have a live order feed sending only daily bars, you could have that planned task at, for example, midday, that send the MOC order and gets executed with the close price of the daily bar.
There is difference between backtesting with daily bars and having a live feed which delivers daily bars. The latter probably constantly updates the current daily bar and that's why you think that already at noon time it may be possible to send a MOC order.
To achieve the same effect during backtesting you need one of this:
intraday data and replay daily bars
Set cheat-on-close and allow using the close price
Use filters and break the feed into OHL + C steps (see the Pinkfish Challenge - and the sample in the sources)
For the MOO I can send it to IB with kwargs as you´re proposing, but I cannot get the same effect with backtesting, basically because 1) Backtrader doesn´t support natively MOO orders (what about more order types support for the future? :slight_smile: ) or 2) as I don´t have "planning tasks capability" I should know which one is the last bar - 1 on the day, to send a Market Order, before it close, and simulate MOO behaviour...
Yes you can. If you use daily bars, whenever you get a bar during backtesting, you are at the end of the session. Send for both cases (backtesting and live) a Market order and the extra kwargs. The standard backtesting broker will ignore it and the IB broker will overwrite the order type.
if I do it with a background thread as proposed, I understand this is a real time capability, but no way to reproduce it on backtesting mode, isn´t?
Not at the moment
if implemented as points in lines (kind of time feed), wouldn´t be this more accurate to have same behaviour like in realtime with just 1 code?
At least it would have the same behavior right now for both scenarios.
@mula29 said in Oanda v20 API:
Per Oanda support, the price needs to have not more than 5 decimal precision. In a market order, it works fine but requires more testing for Stoplimit and limit orders.
I have commited today some updates. I hope, your issues are gone now. If not, please open a issue on github.
For the precision, we have details for the traded instrument, so the price precision is known. We use these details for calculting position sizes. Thanks for the code!
Momentarily confused when trying out Kaber's code -- for those who care my code is python 2, and his code appears to be python 3. Changing super() to super(classname, self) successfully executes under python 2.
I bumped into similar situation. Looks like by default, backtrader is not touching DELAYED data and therefore inherits whatever "rightedge" convention from the original data feed, and in case of ibstore, it is "rightedge=False"; while for LIVE data part it will use the default convention of "rightedge=True", which causes the discrepancy.
Many thanks for the tip from @dasch, now the bars match backteset/live trading.