Hi everyone,
So I am having a problem with my history calls when trying to warm up my indicators. It seems to not being going into the day before no matter how large my lookback is, so the indicators are working great, but the start point is wrong, leading to incorrect values.
In my backtest I have the start date and end date the same because I wanted to just look at one day, so thinking the start date was in the way I moved it back one, and still history doesn't touch it. Now obviously I know that the values will not be exactly the same as charting programs, but if you look you can see they are almost a dollar off. I'm sure it is a simple fix but I am in need of some help.
I attached an example backtest and in the logs you can see the indicator values. (indicators in example are [5MIN - EMA20, 5MIN - EMA200, 5MIN - SMA200, 2MIN - EMA200, 1MIN - EMA200, 2MIN - SMA200, 1MIN - SMA200, VWAP])
Thank you in advance for your help.
Hayden
Derek Melchin
Hi Hayden,
In this example, the History method returns 100-1000 rows with each call. See the attached backtest logs for reference.
The values logged for these indicators may be different from other platforms because we are filling the indicators with data from extended market hours. In addition, other platforms may timestamp their indicator values to the beginning of the period, where we timestamp to the end of the period. Refer to our documentation on Understanding Time.
Best,
Derek Melchin
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.
Hayden Bonneau
Hey Derek thanks for the response,
After looking at the length and the earliest values in the dataframes, the values I expected to see are there, so it seems that the issue is not with the history call, but possibly with how the data is being sent into the indicator? With how the indictors are behaving it seems that they are all starting from the same point at the beginning of trading which is just not how these moving averages work, if the price gaps up/down the moving average should be anchored by the point before the gap.
I picked an example for 'Apple' on April 23rd which has a pretty large gap down before close on the 22nd. If you look at any charting program the 5 minute EMA 200 is on top of the extended market price action, but in the attached backtest you can see the line is starting below (although the backtest version looks favourable to where the line should be haha).
Here's a link to the apple charts on trading view
It seems like the issue is happening when sending the data into the indicator but I can't find where. I appreciate your help with this a lot it's been driving me crazy for a while.
Thanks,
Hayden
Derek Melchin
Hi Hayden,
The issue is the indicators aren't warmed up properly, so the indicator plot starts at 11AM instead of at 6:50AM. To address the issue, we should redefine the `WarmUpIndicators` method so that the SMA is built with the consolidated bars instead of just minute bars.
def WarmUpIndicators(self, algorithm, history): for tuple in history.itertuples(): tradebar = TradeBar(tuple.Index, self.Symbol, tuple.open, tuple.high, tuple.low, tuple.close, tuple.volume) self.fiveMinuteConsolidator.Update(tradebar) self.twoMinuteConsolidator.Update(tradebar) self.oneMinuteConsolidator.Update(tradebar)
See the attached backtest for reference. The new plot now matches the results from TradingView's plot.
Best,
Derek Melchin
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.
Hayden Bonneau
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!