Hello,
I am trying to construct an algorithm that compares the chosen indicator/metric values of the current bar with those of the previous bars.
Example:
I would like to check
if (10 period EMA > 30 period EMA for 3 bars in a row)
-------
if ( close of the previous bar > low of the bar that occurred 2 bars ago)
How would I code these sorts of criteria in C#?
I appreciate any and all help.
Michael Handschuh
Nicholas Caffrey
Nicholas Caffrey
Nicholas Caffrey
Jared Broad
public RollingWindow FastEmaHistory = new RollingWindow(10);
Roughly translates to this: [Scope of Variable] TypeOfVariable NameOfVariable = new TypeVariable(initial value / settings) In this particular use the rolling window saves the last 10 values. The 0.005 tolerance is to avoid trading thousands of times when the values are very close together. Check out the video EMA Cross Video in the documentation which guides you through this implementation.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.
Nicholas Caffrey
Nicholas Caffrey
Michael Handschuh
Brad Gessner
Hi Michael,
I've been debugging an algorithm which uses rolling windows(5) to determine when one value crosses above or below another. I've noticed when debugging locally in Visual Studio that the most recent value (or previous value) is not at index[0] but rather moves down the list with each time iteration and can be referenced at index[tail # - 1]. When it gets to the end of the list, it is saved back to the index[0] position.
Is this "by design" or should I always be able to reference the previous value at index[0]?
Thanks
Alexandre Catarino
Hi Brad,
Yes, this is by design. The RollingWindow indicator uses indexers (check it here).
With this design, we don't need to add and remove elements from the list, we just replace the oldest item for the new one and update the tail position used by the indexer.
You can always reference reference the previous item in the window at this[0] and the last on at this[Count - 1].
Nicholas Caffrey
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!