Comparing indicator value to 0 while using rolling window

Back

Hi, I am using rolling window to be able to access previous indicator values. However, I am getting error when I comparing the value from the  indicator to 0. I am not sure what the issue is. Thanks!

This works.

long_signal_1 = self.momfiveDayWindow[0] > self.momfiveDayWindow[2]

## THIS DOES NOT WORK.
 long_signal_1 = self.momfiveDayWindow[0] > float(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.


Hi Seine,

The second statement does not work because it is comparing `self.momfiveDayWindow[0]` (which is of type IndicatorDataPoint) with a float. We can get the float value of `self.momfiveDayWindow[0]` by calling `self.momfiveDayWindow[0].Value`. Thus, a working statement would read

long_signal_1 = self.momfiveDayWindow[0].Value > float(0)

In addition to that error, the algorithm was also running into issues with checking the `self.ticket.Time` while `self.ticket` was set to `None`. We can resolve this by ensuring

self.ticket is not None

before checking `self.ticket.Time`.
See the attached backtest which has both of these issues resolved.

Best,

Derek

1

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.


perfect.

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