what i am trying to do is to test MACD signal Against MACD line to take short or long desicion , on daily basis , so i am trying to store yesterdays MACD in Rolling Window and compare today's MACD with yesterdays MACD line and signal
but what really happens is the value doesnt seem to change and no positins opened at all. or i am using the wrong macd line and signal
Alexandre Catarino
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.
Mohamed abbas
thank you Alexandre it seems that i got it all wrong but u corrected all to me
Mohamed abbas
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!