Hi gents,
I am trying to run a scheduled event with a loop over several pairs but I am obviously missing something in the logic flow.
Part of the code has been sanitised but it does not affect the overall design.
Any code revision would be appreciated as my Python skills are still so and so..
R
Riley Raschke
Rob,
No pro here, but wanted to look around at others code some and you were first! It appears `def WasJustUpdated(self, current):` isn't doing what you want.
Your schedule is set to run at 8:05AM
This schedule run time is approximately passed to `SymbolData.WasJustUpdated`, but SymbolData is using an Hourly window with current params.
So at 8:05AM minus 1Hour window, you get 7:05, and the most recent complete bar "began" at 7:00 due to the hourly window.
I adjusted `SymbolData.WasJustUpdated` to use the bar's `EndTime` and replaced the equality check with a >= since 8:05 - 60 minutes will never be equal to an hourly bars start (or end) time.
def WasJustUpdated(self, current):
return self.Bars.Count > 0 and self.Bars[0].EndTime >= current - self.BarPeriod
Also reduced logging and backtest windows to save some bytes :) The only relevant change was the item discussed above.
Rob Pec
Hi Riley ,
Thank you very much for your support
Rob
Alexandre Catarino
First of all, thank you Riley Raschke!
Hi Rob Pec ,
The algorithm is creating indicators using the helper methods and subscribing to a consolidator. Therefore, the indicators are updated with two resolutions. Instead of using the helper methods, it should use the constructors:
symbolData.RSI = RelativeStrengthIndex(self.RSIPeriod)
see the docs, under Indicators section, for more details.
Also, the algorithm is updating the indicators subscribed to different consolidators with the same callback method and RegisterIndicator. So, for example, symbolData.RSI is being updated by 5 different consolidators:
1 - 1-hour consolidator from self.RSI
2 - Update method in OnDataConsolidated with is triggered by 3 consolidators:
3 - 1-hour consolidator with RegisterIndicator.
In order to update the indicators, we just need to use RegisterIndicator which accepts a timedelta (TimeSpan in C#) object and will create the consolidator under-the-hoods.
symbolData.RSI = RelativeStrengthIndex(self.RSIPeriod) self.RegisterIndicator(symbolData.Symbol, symbolData.RSI, self.BarPeriod)
Finally, I would advise creating the indicator, with the constructor, in the SymbolData class to avoid the None.
Rob Pec
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!