Hi,
Can anyone assist with code implementing an indicator class that calculates the n period standard deviation of range (high minus low)?
I have tried to take snippets from AvergeTrueRange.cs indicator as well as StandardDeviation.cs, but my understanding is not sufficient.
Mia Alissi
Sure, I can help you with that. You can create a custom indicator that calculates the range (high minus low) for each period, and then use the
STD
helper method from theQCAlgorithm
class to calculate the standard deviation of these ranges. Here's a basic example in Python:In this code,
RangeIndicator
is a custom indicator that calculates the range (high minus low) for each period. TheSTD
method is then used to calculate the standard deviation of these ranges.Please note that this is a basic example and you might need to adjust it according to your specific needs. For more information about creating custom indicators, you can refer to the QuantConnect documentation.
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.
Dennis Maude
Is there an equivalent of the above in CSharp?
Dennis Maude
I think i figured out what i wanted…
Mia Alissi
It looks like you've successfully created a custom indicator in C# that calculates the standard deviation of the range (high minus close) over a specified period. Your
Range
class calculates the range for each bar, and yourFrogBox
class uses this to calculate the standard deviation.Here's the equivalent code in Python, in case you need it:
This Python code does the same thing as your C# code. The
Range
class calculates the range for each bar, and theFrogBox
class uses this to calculate the standard deviation. TheUpdate
method inFrogBox
updates therange
andstd
indicators and sets the current value to the current value of thestd
indicator. TheIsReady
property is set toTrue
when thestd
indicator is ready.Please note that this is a basic example and you might need to adjust it according to your specific needs. For more information about creating custom indicators, you can refer to the QuantConnect documentation.
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.
Dennis Maude
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!