Hi
need help in order to understand if it's possible to "pre-calculate " an indicator few minutes before the market close
My objective is to pre calculate the "daily" indicator few minutes before the market close in order to set a market on close order and not have to wait for a whole day for issuing the order
how would I do that?
Shile Wen
Hi Pier,
This can be achieved by creating an indicator object not tied to the algorithm (e.g. using self.sma = SimpleMovingAverage(...) instead of self.sma = self.SMA(...)) and manually updating the indicator under the “Manually Updating” section here. Also, since the indicator needs to be updated data a few minutes before market close, we need to change our resolution to Resolution.Minute.
I’ve shown an implementation in the attached backtest.
Best,
Shile Wen
Pier Paolo
Thanks Shile
by my understanding this sma indicator has a minute resolution, so it's not going to calculate a 20 day moving average and use the last value to precalculate the sma
is it correct?
My aim is trying to precalculate the value in order to anticipate the entering in the market , but it's important to calculate the average on the last 19 close plus the latest 10 min to close" value and do this everyday..
when I use a manual indicator, will it calculate sma on the "10 min to close" value or will it use the correct close value in the following days?
I hope my question is clear .. it's a bit complicated to explain
Shile Wen
Hi Pier,
Because we use a Scheduled Event that executes once per day, it is very similar to being on a Daily Resolution, the only difference being the close value used for the computation uses the price 10 minutes before Market Close as opposed to the price at Market Close.
Please note the solution will not use a LEAN indicator, and other indicators using similar data will be more difficult to implement.
To achieve “the average on the last 19 close plus the latest 10 min to close value and do this everyday”, we can use a RollingWindow of the past 19 market closing prices, sum these prices, then add on the price 10 minutes before Market Close of the current day, then divide the result by 20. I’ve shown how to do this in the attached backtest.
Best,
Shile Wen
Pier Paolo
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!