In my experience EndOfDay – trading means that at 4pm (end of day) indicators are updated, current stock values are used to execute trade logic to determine orders and then orders are sent to the exchange. But I cannot achieve this behavior with QuantConnect. What I can see is that when using minute data OnData() is executed every minute from 9:30 until 4pm and EndofDay() is executed at 11:58pm. I have no idea when the indicator is updated?
To use minute data helps to understand intrabar behaviour when using limit orders. How can I achieve using minute data the intended behavior? The goal: updating indicators at 4 pm, executing order logic and issuing the order.
When using daily data (var equity = AddEquity(_spy, Resolution.Daily) then OnData is excuted at 12:00 pm and OnEndOfDay() at 11:58 PM. I don‘t know when the indicator is updated. ??
My question:
What is the best way using minute data that at 4pm (or 10 minutes before) the following activities take place:
- indicators are updated
- trade logic is executed
- orders are issued
Michael Manus
there is the Time property which you can help you. you can print the time and see when something happens:
line 86:
https://github.com/QuantConnect/Lean/blob/8dc78a3a76944cdece2f9d5a943c4cf1b03eb508/Algorithm.CSharp/BasicTemplateCryptoAlgorithm.cs#L86Michael Manus
when you need info about orders use the onorder event:
https://github.com/QuantConnect/Lean/blob/1201d84c96d093cdd7a1e53cd87f3fc361db4f88/Algorithm.CSharp/OrderTicketDemoAlgorithm.cs#L429
Michael Manus
more complicated chapter indicator updates:
if you want manually update indicators you can use the update method :
https://github.com/QuantConnect/Lean/blob/fb7d1994ff0b1859e7204ffedd609236a6fd4827/Algorithm.CSharp/EmaCrossUniverseSelectionAlgorithm.cs#L66
class holding info with indicator:
https://github.com/QuantConnect/Lean/blob/92b3ab33c353481d3fd5b6b0bdf91ee1dd93aac0/Algorithm.CSharp/MultipleSymbolConsolidationAlgorithm.cs#L120
same:
https://github.com/QuantConnect/Lean/blob/fb7d1994ff0b1859e7204ffedd609236a6fd4827/Algorithm.CSharp/PortfolioOptimizationNumericsAlgorithm.cs#L173Michael Manus
so you could update indicators in the consolidator method if you want or use the schedule function BeforeMarketClose:
beforemarketclose
Michael Manus
consolidator examples:
Ulrich
Thank you Michael.
I found out how to update the Indicators manually (see modified code in the backtest).
Consolidators will help for this if High, Low data are required. Otherwise the update in OnData() is sufficient.
To reconstruct exchange open/close times in this way is not nice, but at least it works.
Regards Ulrich
Michael Manus
"its not nice" hehe yes that is why you maybe should use beforemarketclose which is than 10 minutes before close. doesnt matter if its at 4 or like at thanksgiving at 1?.... i dont know
Ulrich
But how can the data be obtained wtihin
Schedule.On(DateRules.EveryDay(), TimeRules.BeforeMarketClose("SPY", 10), () =>
Is there a parameter for the data ?
Michael Manus
like _rc or _holdings you would need to save the price somewhere and access it in schedule.on.
Ulrich
Good point. I have changed the programm accordingly.
It is getting nicer now. One question:
_data = data;
Will the above statement copy the whole object or just the pointer to the object? In case of copying the whole object for multiple symbols it would be better to store only the price value and time of latest price.
Michael Manus
phu i am not that good in c#,
but i think if its a string or integer it does a copy.
when its an array or list its a pointer/reference
Ulrich
Thank you for your time and immediates responses.
I think also it is just a copy of a reference/pointer and then it is okay.
Then the system is fine like this and works according to my intention.
regards
Ulrich
Ulrich
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!