I have been able to get myself as far as displaying values of Fast Stochastic and CCI using 30 minute consolidated QuoteBars yet the values returned are incorrect.
I am now genuienly stuck as I keep reading through the pages of tutorials but I must be missing the relavant information. Any advise would be greatly appreciated, Thank you in advance.
Language: Python
- View:
- 30 minute QuoteBars for WTICOUSD - West Texas
- Time:
- Random Times from the list of dates/times selected for investigation:
- 19th of June 2020 20:30:00PM
- 19th of June 2020 21:00:00PM
- Indicators:
- Fast Stochastic with Initial Period of 21(%%K Line)
- Fast Stochastic with Trigger Period of 39 (%%D Line)
- Expected return value of the Fast Stochastic Trigger Period %%D Line should be 70.748 & 70.128
- Current return value however is:
2020-06-19 21:00:00 >> 62.337662337662344
&&
- CCI with a 200 Period
- Expected return value should be 117.151 & 106.312
- Current return value:
2020-06-19 21:00:00 >> -7.496709964417092
Derek Melchin
Hi Martin,
The issue here is that the algorithm above uses the helper methods (STO and CCI) to create the indicators. Since the indicators are registered with the 30-minute consolidator as well, the indicators are updated with both the minute data and 30-minute data. I've correct this in the backtest below, calling on the Stochastic and CommodityChannelIndex classes explicitly.
self.sto = Stochastic("WTICOUSD", 21, 21, 39) self.cci = CommodityChannelIndex("WTICOUSD", 200) thirtyMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=30)) thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteQuoteBarHandler self.SubscriptionManager.AddConsolidator("WTICOUSD", thirtyMinuteConsolidator)
Another thing to note is that we also have to adjust the warm-up duration to account for the consolidation into 30-minute bars. We can accomplish this by stating
self.SetWarmup(200*30, Resolution.Minute)
See the attached backtest for reference. The logged indicator values are still slightly different from what was posted as correct above. Where/How were these values sourced?
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.
Martin Tolmusk
Hi Derek,
Your assistance has helped me move this in the right direction. Values from the backtest are getting closer to the values I am expecting see.
*Expected values mentioned in my initial post above are referencing the %%D line(Sorry, I wasn't clear enough). These values still however still seem slightly off compared to the values I am seeing on my iPad (Please see the attached images below), however if we get the %%K Line values aligned(as seen below) everything else should hopefully fall in place.
52 | 12:41:03:
2020-06-19 20:00:00 >> STO >> 61.79718875502008
53 | 12:41:03:
2020-06-19 20:30:00 >> STO >> 59.0863453815261
54 | 12:41:03:
2020-06-19 21:00:00 >> STO >> 54.76907630522088
55 | 12:41:03:
2020-06-19 21:30:00 >> STO >> 45.933734939759034
56 | 12:41:03:
2020-06-19 22:00:00 >> STO >> 47.540160642570285
1. 2020-06-19 19:30:00 >> STO >> %%K Line >> 61.622
https://ibb.co/HCV3nK92. 2020-06-19 20:00:00 >> STO >> %%K Line >> 58.952
https://ibb.co/pnBhfcr3. 2020-06-19 20:30:00 >> STO >> %%K Line >> 54.698
https://ibb.co/Qm5ZL524. 2020-06-19 21:00:00 >> STO >> %%K Line >> 45.994
https://ibb.co/WB9WcnH5. 2020-06-19 21:30:00 >> STO >> %%K Line >> 47.577
https://ibb.co/xz4FJSWThank you.
Martin Tolmusk
Hi Derek,
After looking at the Stochastic class hieracrchy I can see that there is no Property for Fast Stochastics %%D Line at all, only the %%K Line, which is retrieved by using the .FastStoch Property.
Kind regards,
Martin
Derek Melchin
Hi Martin,
I'm glad we are going in the right direction here.
The %%D line value is indeed retrievable. We just need to utilize the StochD property of the Stochastic class.
The fractional differences of the STO indicator may be just a result of rounding error or by virtue of using different data sources.
The discrepancy in the timestamp is because our indicators are timestamped to end time and indicators in graphical software are timestamped to the open 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.
Martin Tolmusk
Hi Derek,
Thank you again for your time explanations. These have helped.
Hopefuly this is my last request:
Trading Live(as seen on the screenshot):
https://ibb.co/1myfCcqI am currently not getting correct email notifications based on my check whether the current live 30 minute %%D Line value has passed above 63.
On the screenshot we can see that it has but the IF statement seems to fall through this check and instead ends up in the else statement?
Kind regards,
Martin
Martin Tolmusk
Hi Derek,
I stated I was checking the value above 63 in the IF statement but the screenshot has a value of 71.
Nevertheless, the continuous upwards movement does not seem to update my indicator with live values?
Kind regards,
Martin
Derek Melchin
Hi Martin,
Try plotting the indicator values and the security price during live mode to ensure they are being updated properly. I did so in backtest mode and it looked correct.
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.
Martin Tolmusk
Thank you Derek,
I'll give this a go.
Would you know why I am getting two itrations for the same date as seen in the screenshot when using my backtest,
could it be the reason why it was not updating correctly?
https://ibb.co/gRtLL3ZKind regards,
Martin
Derek Melchin
Hi Martin,
The timestamps in the image above show a single iteration from 6:30-20:00. Using `Log` instead, we see the algorithm completes at the end of the backtest.
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.
Martin Tolmusk
Hi Derek,
Apologies, my bad. I didn't pay attention to detail.
Thank you very much for the plotting tip, as finally I seem to be getting correct values for one of my Stochastic Indicator.
It is almost complete and I am getting my notification values for one Cfd("WTICOUSD") but I do not seem to be getting any values for the other("XAUUSD").
All my Stochastic Indicator values for "XAUUSD" are returned as 0.0 for some reason but the functions for both consolidators are almost identical?
Derek Melchin
Hi Stephen,
The Stochastic indicator for XAUUSD is 0 because the warm-up period is not long enough. Since the Stochastic indicator has two built-in moving averages, we need to set the warmup period to be the sum of the 3 arguments we pass to the indicator constructor. Since XAUUSD has a longer indicator window than WTICOUSD with
self.sto_gold = Stochastic("XAUUSD", 172, 21, 95)
we need to set the warmup period to be
self.SetWarmup((172+21+95)*30, Resolution.Minute)
See the attached backtest for reference.
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.
Martin Tolmusk
Hi Derek,
I hope all is well with you.
My values for my West Texas CommomidyChannelIndex backtest values do not seem to reflect the values seen on the screenshot taken from the Oanda Application.
Screenshot shows various values around the -200 range and below, however my backtest values are consistently floating around the value of 40?
Would you know why my backtest values do not seem to match?
Kind regards,
Martin
https://ibb.co/GcWyr7NDerek Melchin
Hi Martin,
The plots are different because the backtest above is plotting the TypicalPriceAverage property of the CCI. To match the plots, we need to plot just the indicator value.
self.PlotIndicator("Indicator-CommodityChannelIndex_WTI ", self.cci_wti)
See the attached backtest for reference.
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.
Martin Tolmusk
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!