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.
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.
@vladisld Enjoyed the video. Believe the issue in the code was that it was iterating over rows and writing 1 row at a time to the database...
Can now write 13 years of 1 minute data in ~50 seconds. Needed to batch_size=10000 for it to work on a large data-set.
Problem solved. Now the real work begins.
@backtrader said in Implement stop loss:
No, under buy_price, because your are talking about stop-loss (you are in the market), people will understand the price at which you bought your asset and not the expected (and yet unknown) price at which the next order, the stop-loss one will execute.
Got this. I've declared a new variable which is store buy_price and updates it in notify order method with order.executed.price.
@scottz1 said in My Orders dont get Closed (wrong implementation of SL/TP?):
Looks ok basically. However,
remember to add logic for partial fills so the tp/sl orders will have the correct size.
remember to check existing position so as not to overwrite self.order and end up doubling your position.
One comment that I see.
I believe that we can remove the parameter on timeframe in stockkwargs so that it becomes as follows since we will be resampling the data anyway later on
stockkwargs = dict(
rtbar=False, # use RealTime 5 seconds bars
historical=True, # only historical download
qcheck=0.5, # timeout in seconds (float) to check for events
fromdate=datetime.datetime(2019, 9, 24), # get data from..
todate=datetime.datetime(2019, 9, 25), # get data from..
latethrough=False, # let late samples through
tradename=None # use a different asset as order target
No, it cannot work for me, because that doesn't read from Yahoo. It tries
@Mario-Pellegrini said in float division by zero:
It is not a random code since you also say that the ticker works
It is random, because you apparently want to read from Yahoo and apply Quandl. The code has also nothing to do with the code from the homepage (3 snippets) that directly reads data from Yahoo.
Why don't you start from one of the scripts on the home page, change the ticker to FCA.MI and then slowly modify it? The link again for your reference
One of the latest additions lets you do direct time comparisons directly to lines to generate signals. Probably nobody has used it yet. An example:
lines = ('mysignal',)
self.lines.mysignal = self.data.datetime > datetime.time(10, 30)
This generates an indicator which can be used as a signal to only execute orders when the daily time goes over 10:30.
But since you are probably looking for day, you'll need to work it out in the next method comparing the self.data.datetime.date() (maybe even getting the weekday) against something of your choosing