I am trying to define sma's for different symbols, and i would like to parameterize them individually because i do not wish each symbol to have sma's with the same parameters as the other symbosl. However, I am having rouble accessing my data in the OnData function. Mainly, the line "self.window.Add(data["EURUSD"])" is where i seem to be having running into issues. If i incorporate another symbol within the brackets (ex: ["EURUSD", "USDJPY"] )it throws an error saying "Object reference not set to an instance of an object". Is there an efficient way i can define multiple sma's each with its own parameters and then access them each individually in the OnData function? I also need the values to be stored in a rolling window so i can access specific indecies of each sma. Any help would really be greatly appreciated
Thank you!!
Jing Wu
Hi Johnny,
We developed a simple algorithm for Multiple Simple Condolidation, you can find this algortihm on Github
Johnny VanNuland
Thank you for your response! That algorithm is very helpful and very similar to what i am trying to do but i still have some of the same questions as originally posted.. In that algorithim i see that we define an SMA within a roling window, and i also see that I can access specific bars from the SMA within the "symboldata" class in the "_init_function". However I would like to be able to refrence those specific index values in the OnData function as well. How can I access those SMA indicies within the OnData function?
Michael Manus
i am joining the group with:
with Runtime Error: Cannot perform runtime binding on a null reference
Jared Broad
Jared Broad
If its a bug report in the LEAN stack please report to support@quantconnect.com. We'll need a little more information -
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.
Johnny VanNuland
Jing Wu
With regards to the Multiple symbol consolidatino template posted earlier, how am i able to access the different SMA indicies from withiin the OnData function???
Jing Wu
Hi Johnny,
You could use symbolData.SMA.Current.Value when the indicator is ready to use. For example
def OnData(self,data): for symbol in self.Data.keys(): symbolData = self.Data[symbol] if symbolData.IsReady() and symbolData.WasJustUpdated(self.Time): # print the SMA value for each symbol self.Log(str(symbol) + " SMA " + str(symbolData.SMA.Current.Value))
Johnny VanNuland
I am trying to access the index values from the SMA, not just the current value. When i attempt to do so, i get an error saying that is an unindexable object.
This is what i tried within the OnData function...
"
Currentsma = symbolData.SMA[0]
previoussma = symbolData.SMA[1]
"
Thank you again for your help
Jing Wu
Jing Wu
Hi Johnny,
symbolData.SMA is a SimpleMovingAverage object not a list of indicator values. It only has the current value property. If you want to access the history value of the indicator, First add a rolling window attribute in SymbolData class. Each time you get a new indicator value in OnData(), add that value to the window, The window size depends on the periods of history you wanna keep. Please see the attached algorithm for an example
Johnny VanNuland
Thank you for your help. Very much appreciated!
Johnny VanNuland
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!