Hello,
I am running into a problem which I cant resolve.
See attached backtest and code.
If the resolution is set to daily: spy_d = AddCfd("SPX500USD", Resolution.Daily, Market.Oanda);
The heikin ashi indicator gives the correct values. e.g. on the 19th Heikin ashi close = 2900
If the resolution is set to hourly: spy_d = AddCfd("SPX500USD", Resolution.Hourly, Market.Oanda);
The heikin ashi indicator gives NOT the correct values. e.g. on the 19th Heikin ashi close = 2898
Why is that?
thx.
Link Liang
Hi,
First of all, it is expected to see different outputs with different resolution level used. Typically higher resolution has more accurate output, although it might sometimes perform worse.
I believe this could cause something wrong:
spy_d = AddCfd("SPX500USD", Resolution.Hour, Market.Oanda);
spyHA_d = HeikinAshi("SPX500USD", Resolution.Daily);
If the indicator uses lower resolution than the subscribed data, we need to use data consolidator. Here is my attempt to implement a consolidator with hourly data and daily indicator. Notice that the data consolidator combines 24 bars into 1 bar. Since SPX500USD does not trade 7*24, the indicator is not updated exactly every day, but every 24 data entries instead.
Hope it helps!
Eugene
Hello Link,
thank you!
I tried your code and indeed it works better. It gives still a slightly different value but very close to the daily settings.
Actually, I expected the helper method of the heikin ashi indicator to do exactly the same thing as consolidating the data like you coded it. Why else does the indicator offer a resolution setting?
Another thing which bothers me is that the daily setting give the right value compared to the actually more accurate hourly data.
Maybe its an issue of the asset SPX500USD because it trades 23h a day starting at 22:00 UTC.
thx again.
Douglas Stridsberg
There is no such thing as the right value - it depends what data provider you compare against. The best you can do is use your indicators in a way which is consistent across your algorithm. It's unlikely all values will line up 100% with some other data provider's indicator data.
Link Liang
Hi,
My previous example was just a showcase of our data consolidator. In fact, this would consolidate data every day instead of 24 bars, which is more proper for your strategy:
var consolidator = new QuoteBarConsolidator(TimeSpan.FromDays(1));
Moreover Instead of logging the indicator value in OnData() method, log it in Indicator.Updated event makes more sense:
spyHA_d.Updated += (sender, updated) => Log($"Indicator: {spyHA_d.Close}");
Now from the log, we learn that our indicator gets updated at 01:00 everyday except for 19:00 once every week, and I believe that's due to marketing hour of SPX500USD. However, from the backtest with daily data subscription, we see that the daily bar arrives at 20:00 everyday. The two algorithms upgrade the indicator at different time, that's why we have different outputs. However, I wouldn't say which one is correct or not.
Regarding the resolution setting of indicators, we have to set it to let the indicator know when (or how often) it needs to update. At the same time, we need to feed the right bars to our indicator. If we feed hourly bars to an indicator who is looking for daily bar, there is definitely going to be problems.
Eugene
thank you a lot. that helped!
Eugene
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!