Back

Issue with custom consolidated candle

Hi there,

Attached is a template I have tweaked to be able to trade multiple symbols and on custom timeframe. This is the base template I use for all my algos.

What I am trying to do in the attached example is to have a variable (_EMA_CrossCount) that count how many candles (consolidated TradeBar) have passed since the price last crossed above or below an EMA.

To easily visualise if things are working, I am plotting the Price and the EMA on the “Price” chart and the value of the _EMA_CrossCount on the “EMA cross count” chart. In theory, every time the price crosses the EMA on the first chart, the value on the second chart should go to 0.

Things are working perfectly well when I set the resolution (row 9) to Resolution.Daily and the _BarPerTimeSpan (row 10) to 1 (i.e. using consolidated TradeBar of 1x daily data = standard daily candle).

I would expect to get the exact same result when I set the resolution (row 9) to Resolution.Hour and the _BarPerTimeSpan (row 10) to 24 (i.e. using consolidated TradeBar of 24x hourly data which should be the same standard daily candle), however things do not work as expected in that scenario.

Please note that I am not a programmer and I am just learning to code a bit to be able to use QuantConnet. I have been stuck with that issue for the past 2 days and would really appreciate if somebody could help.

Many thanks in advance!

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.


And here is what I would expect to see.

0


My bad, the issue was that the algorithm was saving the previous close _symbolData._Price_P1 = _symbolData._Price which is different with different resolutions. Consequently the condition that resets the counter was never met in Hour resolution. I was able to fix it by creating a a rolling windows to save the last two values in DataConsolidated.
Thanks a lot Alex Catarino for your help via email!

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