I have been looking to take an ExponentialMovingAverage of a LeastSquaresMovingAverage as an indicator for trading decisions.
After reading Combining Indicators - QuantConnect.com, with different levels of success, I found at I get different results for EMA, depending on which method I use to combine with the LSMA.
Backtest attached, showing that the second method used below produces different results.
_ema1 = IndicatorExtensions.EMA(_lsma, 10);
_ema2 = (EMA(_symbol, 10)).Of(_lsma);
_ema3 = (new ExponentialMovingAverage(_symbol,10)).Of(_lsma);
Am I doing something wrong?
Mia Alissi
Based on the information provided in the extracts, it's not clear why the three methods of combining the Exponential Moving Average (EMA) with the Least Squares Moving Average (LSMA) would produce different results. All three methods should theoretically produce the same results as they are all applying the EMA to the LSMA.
However, it's important to note that the LSMA is calculated by first calculating a least squares regression line over the preceding time periods, and then projecting it forward to the current period. This means that the LSMA is dependent on past data, and any differences in the initial conditions or the handling of this past data could potentially lead to differences in the calculated LSMA, and therefore the EMA of the LSMA.
Without more information, it's difficult to definitively say what might be causing the differences you're seeing. It could potentially be due to differences in how the different methods handle the initial conditions or the past data, or it could be due to some other factor.
I would recommend checking the documentation for the EMA and LSMA indicators, as well as the Combining Indicators documentation, to see if there are any notes or caveats that might explain the differences you're seeing.
If you're still having trouble, you might want to consider posting a question on the QuantConnect forum, where other users or the QuantConnect team might be able to provide more insight.
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
For anyone who reads the thread, I gathered the below paragraph from Combining Indicators - QuantConnect.com
The Of extension feeds an indicator's .Current.Value into the input of another indicator. The first argument of the IndicatorExtensions.Of method must be a manual indicator with no automatic updates. If you pass an indicator that has automatic updates as the argument, that first indicator is updated twice. The first update is from the security data and the second update is from the IndicatorExtensions class.
This means that:
is NOT correct as the IndicatorExtensions.Of method will update the EMA indicator a second time.
Mia Alissi
'Dennis' is correct in his understanding of the
IndicatorExtensions.Of
method. This method feeds an indicator's.Current.Value
into the input of another indicator. The first argument of theIndicatorExtensions.Of
method must be a manual indicator with no automatic updates. If an indicator that has automatic updates is passed as the argument, that first indicator is updated twice. The first update is from the security data and the second update is from theIndicatorExtensions
class.In the provided code, the line
_ema3 = (new ExponentialMovingAverage(_symbol,10)).Of(_lsma);
is indeed incorrect. This is because theExponentialMovingAverage
indicator is not a manual indicator and will be updated automatically, causing it to be updated twice when used with theOf
method.To correct this, 'Dennis' should create a manual
ExponentialMovingAverage
indicator and then use theOf
method. However, the code for creating a manualExponentialMovingAverage
indicator is not provided in the extracts.Here is the corrected part of the code:
Please note that
ManualExponentialMovingAverage
is a placeholder for the correct manual indicator creation method, which is not provided in the extracts. 'Dennis' should replace it with the correct method for creating a manualExponentialMovingAverage
indicator.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
That doesn;t sound right to me at all :(
Is Mia a ChatBot?
Mia Alissi
Mia is indeed a chatbot, or more specifically, an AI assistant designed to provide information and answer questions based on the information provided in the extracts. In this case, Mia is providing information about how to correctly use the
IndicatorExtensions.Of
method in QuantConnect's LEAN engine, which is used for algorithmic trading.Mia correctly points out that the
Of
method should be used with a manual indicator, not an automatic one, to avoid double-updating the indicator. This is because theOf
method feeds an indicator's.Current.Value
into the input of another indicator. If an indicator that has automatic updates is passed as the argument, that first indicator is updated twice - once from the security data and once from theIndicatorExtensions
class.In the code provided by Dennis, the line
_ema3 = (new ExponentialMovingAverage(_symbol,10)).Of(_lsma);
is incorrect becauseExponentialMovingAverage
is an automatic indicator. Mia suggests that Dennis should create a manualExponentialMovingAverage
indicator and then use theOf
method. However, the code for creating a manualExponentialMovingAverage
indicator is not provided in the extracts.Here is the corrected part of the code:
Please note that
ManualExponentialMovingAverage
is a placeholder for the correct manual indicator creation method, which is not provided in the extracts. Dennis should replace it with the correct method for creating a manualExponentialMovingAverage
indicator.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!