Back

RollingWindow.Add(data?)

I can't seem to figure out how to name the data to put it into RollingWindow. I am sure, the solution should be intuitive, but I am not having that moment of clarity now.

Basically I am just trying to find the volume of prior bar. That simple. I started using RollingWindow, based on example in QCU and on examples in Forum. But I can't seem to add data to the RollingWindow, no matter what I try. I also tried Add(data ["ES"]) , but so far nothing works. I would appreciate your advise.

Update Backtest








Any suggestions on how to get prior bar's volume would be appreciated.

0

@Boris, if you want to read any field of the previous bar, the RollingWindow must be at least of size 2 (one for the current bar, one for the previous bar).

Also, if you are adding objects of a custom type you should declare it as a RollingWindow of the same type, so you have access to all its properties:

RollingWindow<CloseMaribos1> history = new RollingWindow<CloseMaribos1>(2);

 

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.


@Stefano

Happy New Year! And thanks for your help. However, I am still struggling with this algorithm and I am  still not getting the desired output (i.e. previous bar's volume). It seems so simple, but I am probably not entering the correct source of data into history.Add( ), line 47 in OnData method. I am receiving this:

2016-01-04 11:16:00 Runtime Error: System.ArgumentOutOfRangeException: Must be between 0 and Count 1
Parameter name: i
Actual value was 2.
  at QuantConnect.Lean.Engine.Engine.Run (QuantConnect.Packets.AlgorithmNodePacket job, System.String assemblyPath) [0x0062b] in <ce05d63309ce421b983800daf43bff65>:0

I have so far tried everything I could think of (at my present programming level). I also looked through all relevevant discussions in Forum. See my project (updated, per your recommendation) and you will probably immediately see my problem. Thanks in advance. 

0


@Boris,

the history.Add(data) call is correct.

The error is generated by this line:

Debug("Prior Vol = " + history[2].Volume);

Previous bars in the RollingWindow are referenced by a zero-based index,
so history[0] is the current bar, history[1] is the previous bar and so on.

If the RollingWindow has a size of 2 as in this line:

public RollingWindow<CloseMaribos1> history = new RollingWindow<CloseMaribos1>(2);

0 and 1 are the only valid values for the index.

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.


@Stefano,

Thanks again for your response. However, previously I tried all those combinations of numbers. Now again, I increased the size of the RollingWindow to 3, so now it looks like this:

public RollingWindow<CloseMaribos1> history = new RollingWindow<CloseMaribos1>(3);

 And I changed history[2] to history[1], so now it looks like this:

Debug("Prior Vol = " + history[1].Volume);

However, it still does not work, and I keep getting similar ArgumentOutOfRangeException message: Must be between 0 and Count 1
Parameter name: i

But this time, only the following message changed: Actual value was 1. 
And I receive the above messages every time, no matter what numbers I put into the size of the window and into history[ ].Volume. The only thing that changes is Actual value, and it is always equal to whatever number is inside of history[ ].Volume snippet.

Here is the project, updated with above lines of code:

                                                                                                          

0


After multiple trials and errors, I was able to solve this problem myself. The line:

history.Add(data);

should be directly within OnData method, and not inside of If statement inside of OnData method. And I was finally able to get previous bar's volume.

Updated project:

1


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