Back

How to get Weekly EMA

Hi all,

I have been trying to get a weekly EMA going however I have realized Resolution only goes to Daily. With that being said, I have also tried to use a consolidator to create a Weekly bar to use:

Consolidate(symbol, Calendar.Weekly, WeeklyEMA);

However I keep receiving the error:

'Calendar' is an ambiguous reference between 'QuantConnect.Data.Consolidators.Calendar' and 'System.Globalization.Calendar'

I have looked through several posts as well as the docs and have not found what I was looking for. A desired example would be something similar to:

ExponentialMovingAverage weekly1 = EMA(symbol, 1, Resolution.Weekly);

(I know this doesn't compile just as an example).

Thank you for your assistance!

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.


Hi Mike Reichard ,

Please check out the docs, under Indicators - Custom Period Indicators.

We need to create a Weekly Consolidator and register the EMA:

var symbol = AddEquity("SPY", Resolution.Daily).Symbol;
var consolidator = new TradeBarConsolidator(CalendarType.Weekly);
ema = new ExponentialMovingAverage(3);
RegisterIndicator(symbol, ema, consolidator);

 

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.


Thanks Alex.  Was just reading on QC and found information on “Sequential Consolidators”.  My goal is to have 5 trading day bars consolidated into 1 bar, then use the bars to calculate the 3 and 5 EMA.  Here’s the process mentioned:

oneDayConsolidator = TradeBarConsolidator(TimeSpan.FromDays(1)

fiveCountConsolidator = TradeBarConsolidator(5)

five_oneDayBar = SequentialConsolidator(oneDayConsolidator, fiveCountConsolidator)

five_oneDayBar.DataConsolidated += self.FiveDayBarConsolidatedHandler

self.SubscriptionManager.AddConsolidator(self.spy, five_oneDayBar)

Let me know if this is how I get 5 trading days into 1 bar that I can then use for the EMA3 and EMA5 crossover.  If this is the right approach would the ema_3 and ema_5 calculate the EMA of 3 and 5 bars as calculated above?

Appreciate your insights.  

Mike

0

Hi Mike,

To use a consolidator, we use a TradeBarConsolidator object, where the parameter is the number of bars we would like to use. To register a function to a TradeBarConsolidator, so we can use our consolidated data, we do TradeBarConsolidator += MyConsolidatorFunction, where MyConsolidatorFunction is where we would like to handle the data (similar to OnData). Finally, to subscribe to our consolidator, we use a SubscriptionManager, to which we add our consolidator object. If different Resolutions are desired, the Resolution should be changed in the add security function (in this case AddEquitiy). To see this in action, check out the attached backtest.

For future reference, see our documentation on Data Consolidation.

Best,
Shile Wen

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.


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