I'm trying to build a modular backtest, so that my indicator is separate from the main code so i can reuse the main code repeatedly with different indicators. I'm building my own indicators in a library and calling the library to get the current value of the trigger. I can return the library object but i can't figure out how to get the value of the variable I'm setting when I want to trigger a trade.
Mia Alissi
Based on the provided code and the information from the extracts, it seems that 'Tom' is trying to separate the indicator logic from the main algorithm. However, the code provided does not show any usage of an external library for indicators.
In QuantConnect, you can create custom indicator classes and use them in your algorithm. The custom indicator class should inherit from the
IndicatorBase<T>
class, whereT
is the type of data the indicator uses (for example,IndicatorBase<TradeBar>
for indicators that use trade bar data).In the
ComputeNextValue
method of your custom indicator class, you can implement the logic for calculating the indicator value based on the new data input. TheCurrent
property of the indicator will hold the latest computed value.Here is a simplified example of how you can structure a custom indicator:
Then, in your main algorithm, you can create an instance of your custom indicator and update it with new data in the
OnData
method:Please note that this is a simplified example and the actual implementation of your custom indicator may be more complex depending on your needs.
If 'Tom' is having trouble accessing the value of the indicator, he can use the
Current
property of the indicator object, as shown in the example above. If the indicator is not updating correctly, he should make sure that he is calling theUpdate
method with new data in theOnData
method.If 'Tom' is still having trouble, he may need to provide more specific details about the issue he is encountering.
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.
Tom Royce
I'm trying to use the example you gave to make sure I understand the concept (I'm pretty new to both python and Quantconnect) and I can't get it to build the project. I must be missing something really simple. just using the code you gave for my indicator it has red markers to the left of the init(self) def statement
Mia Alissi
Based on the information provided, it seems like 'Tom' is trying to create a custom indicator and use it in his algorithm. In QuantConnect, custom indicators are created by implementing the
PythonIndicator
class. This class must have anUpdate
method andName
,Time
, andValue
attributes. TheUpdate
method should accept anIndicatorDataPoint
,QuoteBar
, orTradeBar
and return a boolean that represents if the indicator is ready. TheTime
attribute represents the last time you updated the indicator and theValue
attribute represents the current indicator value.Here is an example of a custom simple moving average indicator:
To create an instance of this custom indicator, you can call the indicator constructor:
To update the custom indicator, you can use the same process as updating manual indicators. If you want to access the current value of the indicator, you can use the
Current.Value
property:If 'Tom' is still having issues, it would be helpful to know the exact error message he is receiving. It's also important to note that the red markers could be due to a syntax error or an issue with the Python interpreter settings in his development environment.
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.
Tom Royce
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!