When we add an indicator to a RollingWindow like this:
// In Initialize
_win =new RollingWindow<MovingAverageConvergenceDivergence>(2);
_macd = MACD(Symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Daily);
// In OnData
_win.Add(_macd);
We are adding a reference to the instance of object (_macd), all items will refer to it and will have the same values.
To add the states, we need to create a class to hold the current state of that instance:
// class to hold the current state of a MACD instance
public class MacdState {
public readonly decimal Fast;
public readonly decimal Slow;
public readonly decimal Signal;
public readonly decimal Value;
public MacdState(MovingAverageConvergenceDivergence macd) {
Fast = macd.Fast;
Slow = macd.Slow;
Signal = macd.Signal;
Value = macd.Current.Value;
}
}
Another issue in your code is reffering to the previous value with index zero.
Since we add the current value first, the previous value is found at index one.
Please checkout the attached project where we put all the above information together.