Back

Dealing with Futures and technical indicators...

Hi

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?

thanks

Update Backtest








hey AlphAngel,

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

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.


thanks JayJayD

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, ...)

Best.

0


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). 

0

Did you change the date ranges? I can't reproduce cloning the latest algo, this is not an error I've ever seen, though I'm new to the platform too.

0

Update Backtest





0

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...

This discussion is closed