Back

RollingWindowAlgorithm example algorithm doesn't run

I'm trying to get a MACD rolling window working in an algorithim im working on and am getting an error. I tried running RollingWindowAlgorithm demostration algorithim to maybe see what I'm doing wrong and that also doesn't run, but gives a different error than the one I got for the one I'm writing. Does anyone know if the documentation is being maintained by QuantConnect or did they just publish it and forget about it?

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.


Hi Marcus. The RollingWindowAlgorithm works fine on my end (see attached). The documentation is certainly being maintained. Can you let us know what errors you're getting?

0


Hello Douglas,

That backtest you posted works for me as well however I'm running it python, which I forgot to mention. When I try to run the RollingWindowAlgorithm I get this error:

During the algorithm initialization, the following exception has occurred: AttributeError : 'RollingWindowAlgorithm' object has no attribute 'Updated'
at Initialize in main.py:line 51
AttributeError : 'RollingWindowAlgorithm' object has no attribute 'Updated'
The error I'm geting on the algorithim I'm trying to write is this:

During the algorithm initialization, the following exception has occurred: ArgumentOutOfRangeException : Must be between 0 and -1
Parameter name: i
Actual value was 5.

which is being caused by this portion of code:   
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

self.SetStartDate(2018, 1, 1) #Set Start Date
self.SetEndDate(2018, 6, 1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Minute
self.SetWarmUp(30)
# Find more symbols here: http://quantconnect.com/data

symbols = ["GBPUSD"]

self.symbol = self.AddForex("GBPUSD", Resolution.Minute, Market.Oanda)
self.adx = self.ADX("GBPUSD", 14, Resolution.Minute)

self.window = RollingWindow[QuoteBar](5)


self.MACD("GBPUSD", 12, 26, 9, MovingAverageType.Exponential,Resolution.Minute).Updated += self.MACDUpdated

self.MACDWin = RollingWindow[IndicatorDataPoint](5)

self.CurrentMACD = self.MACDWin[5]

self.PlotIndicator("MACD", True, self.CurrentMACD.Signal)
self.PlotIndicator("ADX", True, self.adx)

def MACDUpdated(self, sender, updated):
self.MACDWin.Add(updated)

I know the issue is with the MACD rolling window, im just not sure how to fixs it.

0

Hey - can't comment on the error with the original algorithm as I'm running a C# env and can't replicate.However, I see a few potential problems with the code you pasted.

Line 23: the way windows work is that the latest entry is actually at index [0] and not [5] as you have written. Also, since you defined your window to be 5 entries long, the keys will be [0], [1], ... [4]. Key [5] does not exist - this is probably why you're getting the error you're getting.

Also, even if you referenced [0], you would have to be careful in how you used it. At this line (23), the window has not been populated yet, so you'll be referencing an empty location in memory which could cause all kinds of problems. I can't confirm, but most likely Python won't let you do that in the first place.

Solution: rewrite line 23 to reference index [0] and move the entire line inside your OnData method instead.

    0

    Douglas' comment is spot on.
    Just let me add that index 0 is actually the current value, not 4 which is the oldest.
    Since you want to plot the current value, the code should be:

    self.macd = self.MACD("GBPUSD", 12, 26, 9, MovingAverageType.Exponential,Resolution.Minute)
    self.macd.Updated += self.MACDUpdated

    self.MACDWin = RollingWindow[IndicatorDataPoint](5)

    self.PlotIndicator("MACD", True, self.macd)
    self.PlotIndicator("ADX", True, self.adx)
    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.


    Thanks guys, I was able to get it working with your help.

    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