Hi all,
I have a problem that I need to change the period of an indicator on runtime when using custom time frames (2h). When using standard time resolution (1 minute, 1 hour, 1 day) I can just create a new indicator and feed it with the historical data, but not sure how to do this when using different time frames.
Thanks,
Simon
public override void Initialize()
{
SetStartDate(2018, 1, 1); //Set Start Date
SetEndDate(2018, 1, 2); //Set End Date
SetCash(_startingCash); //Set Strategy Cash
QuantConnect.Securities.Crypto.Crypto crypto = AddCrypto(_ticker, _resolution);
_baseSymbol = crypto.BaseCurrencySymbol;
SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Cash);
_consolidator = new TradeBarConsolidator(TimeSpan.FromHours(2));
SubscriptionManager.AddConsolidator(_ticker, _consolidator);
_consolidator.DataConsolidated += OnCustomHandler;
// how to change the period of this indicator on runtime and feed it with historical data?
_sma = new SimpleMovingAverage(_period);
RegisterIndicator(_ticker, _sma, _consolidator);
SetWarmUp(_period);
}
Simon Nebesky
I have solved this by a small workaround. I am collecting all the trade bars for the given period and updating the newly created indicator with it.
Alexandre Catarino
Hi Simon Nebesky ,
Instead of changing the period of an indicator on runtime, why not creating an indicator for each period?
Please check out the DisplacedMovingAverageRibbon algorithm for an example.
Simon Nebesky
Hi Alexandre,
thank you for the example. Actually I was thinking about this solution as a last resort if I dont find another solution. The period will vary between 20 and 60 so I did not want to create so many indicators.
S.
Alexandre Catarino
Hi Simon Nebesky ,
Since we are talking about an algorithm with just one security, I would keep it simple. It is probably more computationally expensive and error-prone otherwise.
Simon Nebesky
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!