Pulling a value from an indicator (MOMP)

Hi guys, 

I just want to get the value of the MOMP to use in my algorithm. 

I think (I am pretty sure) it has something to do with RollingWindow, but I am honestly a bit confused with the explanation in the documentation. 

I have pulled/manipulated some code snippets below. Can anyone let me know if I am on the right track? 

My big question is commented on the right of the first line after //OnData in the code below. Thanks!Alix//RollingWindow Class
private RollingWindow<IndicatorDataPoint> _mompWin;

MOMP(_symbol, 20).Updated += (sender, updated) => _mompWin.Add(updated);
_mompWin = new RollingWindow<IndicatorDataPoint>(20);

_selectorIndicators = new Indicators
MOMP = MOMP(_symbol, 20, Resolution.Daily, Field.Low)

var currMomp = _mompWin[0]; //Does this give me the current MOMP value as a decimal?
decimal mompTrig = -2.5;

if (!Portfolio.Invested && currMomp < mompTrig)
SetHoldings(_symbol, 1);
Update Backtest


you can take a look on many examples provided my the QC team on github:

When you open the rolling window example here:


you will see your answer at line 71   :)


Thanks Michael :-) 

Yes I was using this file and also the IndicatorSuiteAlgorithm.cs to build my algo.  (I cloned thed GitHub library already on my local.)

So, it seems like I am on the right track. 

Let me just ask a few more questions so I make sure I understand the details, if you don't mind :-) (My background is C and C++, so switching gears here.) 

1) A RollingWindow is basically like an object that lets you access a vector, and in the case of an indicatory it basically allows you to access the members of the current period of the specified indicator that the program is looping through. It is basically like accessing a slot in multi-dimensional vector array. (Right ?)

2) So, the number in parentheses at the end of the RollingWindow declaration should in normal circumstances match the size of the period of the indicator, right? I think this is what I was most confused about. Example from your code: 

// Creates a Rolling Window indicator to keep the 2 TradeBar
_window = new RollingWindow<TradeBar>(2); // For other security types, use QuoteBar

// Creates an indicator and adds to a rolling window when it is updated
SMA("SPY", 5).Updated += (sender, updated) => _smaWin.Add(updated);
_smaWin = new RollingWindow<IndicatorDataPoint>(5);

  • So basically, in this example _window is an array of 2 dimensions, and holds "SPY" in the first dim and its period (5) in the second dim. 
  • Then, _smaWin is an array of 5 dimensions, one for each day in the period defined in the SMA indicator. 
  • Right?

3) Can you point me towards the (Lean/QC) documentation that tells me what is going on in this line, please?SMA("SPY", 5).Updated += (sender, updated) => _smaWin.Add(updated);
          Particularly the "+= (sender, updated) =>" part. Thanks for all the help!Best,Alix


as i am a beginner and not that skilled as the others but:

1) lets take a look what happens in the rolling window:


it seems its an thread safe ( ReaderWriterLockSlim ) generic list ( List<T> )where you Add() stuff in it of the predefined length.

And it seems to deque stuff when your added item reaches the size....


2) yep bad example....window of size 2 wit 2 values....

SMA is simple moving average of length (5+4+3+2+1)/5 would be the current value: 3

so in the SMA window _smaWin which tracks 5 values of the sma would had 3 as the most recent value i think

if SPY had 5,4,3,2,1 as last values so yes everything right


3) is much harder to explain as it is c# syntax for subscribing to an event handler which is raised everytime you get a value. So its microsoft c# 3.5 or simething like that:

answered Mar 17 '10    :)


3) Its the same as defining a method. line 62 & 116

Update Backtest


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.


This discussion is closed