Back

EndofDay Trading and order execution an 4 pm

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
Update Backtest








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#L86
0

0

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#L173
0

so you could update indicators in the consolidator method if you want or use the schedule function BeforeMarketClose:

beforemarketclose

0

consolidator examples:

https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/DataConsolidationAlgorithm.cshttps://github.com/QuantConnect/Lean/blob/fb7d1994ff0b1859e7204ffedd609236a6fd4827/Algorithm.CSharp/MultipleSymbolConsolidationAlgorithm.cs
0

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 

0


"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

0

But how can the data be obtained wtihin 

 Schedule.On(DateRules.EveryDay(), TimeRules.BeforeMarketClose("SPY", 10), () =>

Is there a parameter for the data ? 

0

like _rc or _holdings you would need to save the price somewhere and access it in schedule.on.

0

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. 

0


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

https://stackoverflow.com/questions/33823781/are-collections-mutable/33823883  https://stackoverflow.com/questions/5853140/copying-an-integerhttps://stackoverflow.com/questions/14651899/create-a-copy-of-integer-array
0

Hi Michael,

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
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