Back

Scheduled vs ondata call sequence

I am running a backtest with Minute resolution, working only with NYSE Equity and am not setting Time Zone explicitly in code. I rarely run into a case where, OnOrderEvent gets called twice for the same OrderID and orderEvent.Status.IsFill() is true for both calls and has the same quantity. 

Not 100%, but I suspect this is because I may be calling Update on the same event twice in the same minute - one from a scheduled event (because of some trigger) and one via ondata (to achieve trailing stop loss).

1. Is it ok that OnOrderEvent gets called twice for the same OrderID and orderEvent.Status.IsFill() is true for both calls and has the same quantity? Do we know when that would happen?

A few questions if calling Update on the same event twice in the same minute may be causing the problem:

a. If multiple updates to the order cause (1), whats the recommeded approach to avoid this situation? I tried comparing current Time with OrderTicket.Time to avoid a double update at the same time, but the time values for seem Time and OrderTicket.Time seem to be very different (perhaps the TZ is different on the ticket vs current).

b. Even if comparing last update time (2) worked, I still wouldnt be able to control which update takes precedent. Whats the sequence of scheduled vs ondata calls? Does one always get called before the other?

Thank you.

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Ags,

Please attach a backtest which demonstrates the issue so we can assist more easily.

Best,
Derek Melchin

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Not sure what would cause OnOrderEvent to be fired twice, but hard to tell what's going on (if it's your algo or a bug). 

Regarding b., I've noticed that scheduled events tend to be triggered before OnData calls of the same timestep in backtesting.

Logs (see simple backtest attached):

Scheduled event triggered.
OnData triggered.
Scheduled event triggered.
OnData triggered.

But live trading might behave differently in that both are processed asynchronously.

0


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed