Hi folks!
I have a strategy class with two indicators and one rolling window. I want the class to be as clean as possible, so it hasn’t an instance of QCAlgorithm. It only gives signals when the CheckSignals method is called it form the Main algorithm.
Specifically I have something like this in the strategy class:
public class TrendStrategy
{
#region Fields
public SimpleMovingAverage Trend;
private Momentum TrendMomentum;
private RollingWindow
#endregion
#region Constructors
public TrendStrategy(int period)
{
Trend = new SimpleMovingAverage(period);
TrendMomentum = new Momentum(2).Of(Trend);
MomentumWindow = new RollingWindow
}
#endregion
#region Methods
public OrderSignal CheckSignal()
{
MomentumWindow.Add(TrendMomentum.Current.Value);
// do ultra-top-secret stuff
}
#endregion
}
And in the Main algorithm, something like this:
public override void Initialize()
{
SetStartDate(_startDate);
SetEndDate(_endDate);
SetCash(_portfolioAmount);
AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
TrendStrategy strategy = new TrendStrategy(20);
var consolidator = new IdentityDataConsolidator
SubscriptionManager.AddConsolidator(symbol, consolidator);
consolidator.DataConsolidated += (sender, consolidated) =>
{
strategy.Trend.Update(new IndicatorDataPoint(consolidated.Time, consolidated.Price));
};
}
So the Trend and the TrendMomentum are automatically updated from the Main Algorithm, but the momentumWindow is updated when the CheckSignal method is called. The question is; can I update automatically the MomentumWindow when the TrendMomentum is actualized without using a QCAlgorithm instance inside the strategy class?
Now, after reading it, seems a puzzle more than a question!
Thanks in advance, JJ
Damien Peck
Michael Handschuh
JayJayD
JayJayD
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!