Back

Fast Stochastic and CCI return values incorrect (30 minute QuoteBar Consolidated)

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

  1. View:
  • 30 minute QuoteBars for WTICOUSD - West Texas
  1. 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
  1. 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
 
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 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

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 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.

  • sto_value = self.sto.Current.Value's are only minutely different(just the decimals I think) to the values seen on the attached images.
  • Another discrepancy I see is the half an hour difference between the values on the images compared to the backtest values, unless I am misinterpreting the process.
52 | 12:41:03: 2020-06-19 20:00:00 >> STO >> 61.7971887550200853 | 12:41:03: 2020-06-19 20:30:00 >> STO >> 59.086345381526154 | 12:41:03: 2020-06-19 21:00:00 >> STO >> 54.7690763052208855 | 12:41:03: 2020-06-19 21:30:00 >> STO >> 45.93373493975903456 | 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/HCV3nK9

2. 2020-06-19 20:00:00 >> STO >> %%K Line >> 58.952

https://ibb.co/pnBhfcr

3. 2020-06-19 20:30:00 >> STO >> %%K Line >> 54.698

https://ibb.co/Qm5ZL52

4. 2020-06-19 21:00:00 >> STO >> %%K Line >> 45.994

https://ibb.co/WB9WcnH

5. 2020-06-19 21:30:00 >> STO >> %%K Line >> 47.577

https://ibb.co/xz4FJSW

Thank you.

0


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

0

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

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 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/1myfCcq

I 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

0


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

0

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

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.


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/gRtLL3Z

Kind regards,

Martin

0


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

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 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?

0


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

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