Back

Improperly Calculating EMA

Hi all, working on my algorithm and appreciate all the help I'm getting on these forums! 

I'm having a few more problems that I've searched around and have been unable to solve. The first problem is that I don't think it is pulling the EMAs properly, for instance the algorithm buys EURUSD at 19:00 on 4/02 and I believe I have it coded that it should only buy if it is not currently long and the 13EMA is greater than the 48EMA, however on my charting platform at that time I have the 13EMA considerably under the 48EMA and a buy crossover doesn't occur until 22:00 on 4/04.

The next problem I'm having is it seems that whenever a crossover happens for one symbol, it seems to be buying or selling all of them at the same time. I may be mistaken as I'm still learning this language but I thought the foreach() should take care of that so that it's running each symbol from the string separately and it's not.

I really appreciate it, thank you!

Update Backtest








Hi William Patterson , there are a few bugs in your algorithm:

 you need one set of EMAs and one RollingWindow for each symbol, otherwise you are overwriting the variables with the EMAs and RollingWindow of the last symbol in the list.

 

Here is the modified algorithm:

1

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.


In our experience, when there is a mismatch between our indicators and those from other platforms it can be explained by differences in the bars. A bar can be difference because the data is different or the openning/closing time of the bar is slightly difference.
Please checkout the docs under Charting section and use our data to verify your indicators and trading signals to be coherent.
 

0

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.


Thank you y'all!

0

Update Backtest





0

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.


Loading...

This discussion is closed