LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
As I'm new to QC, I did struggle a fair bit to get the data I need for futures and linking a technical indicator to a future contract, so I'm adding my code to the question so that people can improve it and make suggestions.
In this example, I'm basically just getting Bollinger bands on the S&P Mini next future contract and rolling to the next contract 3 days before expiry.
I have few questions though:
1) I had to do the technical indicator warmup manually, is there a way to do it properly?
2) I'm managing the roll of futures as next calendar, is it posible to roll by volume? How would we go about it?
3) when declaring a technical indicator we can use Minute or Hour from the Resolution enum, however if I want to have indicators on 30 or some weird number of minutes/hours, how would I do it? Should I just feed it IndicatorDataPoints manually from my TradeBarconsolidator or is there a more elegant way to do it? In this case, I assume I should not use the register version but do a new BollinberBands instead of BB?
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.
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.
First of all, Good job! Pretty well implemented algorithm.
Now, your questions:
> I had to do the technical indicator warmup manually, is there a way to do it properly?
I think your implementation is good, I mean, don’t think there is a proper way to warm up contracts indicators. Another alternative can be the attached example algorithm, in that case I add new indicator for each new contract as soon as it is in the OnData method.
I’m not sure which one is better, but IMHO your implementation is more efficient because it doesn’t have a bunch of indicator in memory.
> When declaring a technical indicator we can use Minute or Hour from the Resolution enum, however if I want to have indicators on 30 or some weird number of minutes/hours, how would I do it?
Use Consolidator as you already done
> Should I just feed it IndicatorDataPoints manually from my TradeBarconsolidator or is there a more elegant way to do it?
Is elegant enough to me :D
> In this case, I assume I should not use the register version but do a new BollinberBands instead of BB?
Correct! Something like:
_bbOfSevenMinuteBars = new BollingerBands(...); var weirdNumberConsolidator = new QuoteBarConsolidator(TimeSpan.FromMinutes(7)); weirdNumberConsolidator.DataConsolidated += (sender, bar) => { var idp = new IndicatorDataPoint(bar.Time, bar.Close); _bbOfSevenMinuteBars.Update(idp); };
Respect to the second question I don’t know, maybe Alex can help us with this topic.
Best!
1
Edited by 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.
I've simplified my code, still only dealing with one contract at a time,
FYI, I've had a few issues with data - seems to be missing historical data for ESZ16,,,, - cant seem to register custom data consolidator so I dealt with it in OnData...
not sure what is wonrg with the code below
Log("Before SubscriptionManager.Count " + SubscriptionManager.Count.ToString());
var customFrequency = new TradeBarConsolidator(TimeSpan.FromMinutes(frequency));
customFrequency.DataConsolidated += OnCustomBarUpdate;
SubscriptionManager.AddConsolidator(_contract.Symbol, customFrequency);
Log("After SubscriptionManager.Count " + SubscriptionManager.Count);
but here is the code with a dummy BollingerBands strategy, good enough for me for now!
I'll repost later when I have a version that delas with the roll and indicators or multiple futures contracts (ES, NQ, GC, ...)
Impressed with your effort! Thanks for sharing. I am on the early end of learning to code on this platform or in Csharp or python. I have several years of experience with thinkscript and easylanguage. When I clone and backtest i get this error:
Runtime Error: System.OverflowException: Arithmetic operation resulted in an overflow. at System.Decimal.op_Division (System.Decimal d1, System.Decimal d2) [0x0000a] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 at QuantConnect.Securities.SecurityPortfolioManager.ScanForMarginCall (System.Boolean& issueMarginCallWarning) [0x0002f] in <bbbb39a4b52745838530614190c6e8ea>:0 at QuantConnect.Lean.Engine.AlgorithmManager.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Lean.Engine.DataFeeds.IDataFeed feed, QuantConnect.Lean.Engine.TransactionHandlers.ITransactionHandler transactions, QuantConnect.Lean.Engine.Results.IResultHandler results, QuantConnect.Lean.Engine.RealTime.IRealTimeHandler realtime, QuantConnect.Lean.Engine.Server.ILeanManager leanManager, System.Threading.CancellationToken token) [0x00898] in <00d8c477c26946c6bd4adb0ddc495091>:0 at QuantConnect.Lean.Engine.Engine+<>c__DisplayClass8_1.<Run>b__2 () [0x00097] in <00d8c477c26946c6bd4adb0ddc495091>:0 (Open Stacktrace)
Is everyone getting the same error? Apologizes in advance for my ignorance in this platform (give me some time).
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...
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!
You do not have enough QC Credit to send this award, get a QC Credit Pack
here.
Award Sent Successfully
Thank you for giving back to the community.
Processing...
Choose a Credit Pack
Payment Confirmation
QuantConnect Credit (QCC) can be applied to your cloud-invoices or
gifted to others in the community with Community Awards in recognition of their contributions.
Community Awards highlight the awesome work your fellow community members are doing and inspires
high quality algorithm contributions to the community. Select an option below to add
QuantConnect Credit to your account:
$5
500 Credit Points
 
$10
1,000 Credit Points
 
$18
2,000 Credit Points
10% bonus
$45
5,000 Credit Points
10% bonus
03/23XXXX XXXX XXXX 0592
We will charge your default organization credit card on file, click
here to update.