I'm trying to create an indicator and need to multiply the max value returned by the MAX() function. I'm not sure what the data type the function returns, so I'm not sure how to make it compatible with a float.
Q: How do I use the data from MAX() in math operations ( *, -, +, / ) with floats?
CODE:
from datetime import datetime
def initialize(self):
# create a percent of max price DD sell indicator
self.previous = datetime.now() # reset at OnData on Buy
self.then = self.previous # DATE OF PAST PURCHASE
self.now = datetime.now() # Reset at OnData Now
self.duration = self.now - self.then # For build-in functions
self.days = self.duration.days + 1 # Build-in datetime function
self.maxDD = (self.MAX(self.symbol, (self.days), self.resolution))*.95
ERROR:
During the algorithm initialization, the following exception has occurred: Trying to perform a summation, subtraction, multiplication or division between 'Maximum' and 'float' objects throws a TypeError exception. To prevent the exception, ensure that both values share the same type.
at Initialize
self.maxDD = (self.MAX(self.symbol in main.py:line 61
TypeError : unsupported operand type(s) for *: 'Maximum' and 'float'
Def returns
It looks like this is an issue when trying to perform summation, multiplication, division or subtraction between an indicator that doesn't deliver a float or int value. I've searched and can't find anything on how to use the value from one of these indicators in a math equation.
Louis Szeto
You should use the indicator in OnData method
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.
Def returns
Awesome. Thank you Louis Szeto ! That fixed the issue.
Def returns
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!