Hello!
I am trying to program an algorithm that uses tick data and an indicator to trade future contracts. Is there a way of consolidating say 300 ticks into trade bars in python? I know that it's possible in C# but I haven't been able to find any information or examples for python. If not would I just have to program the sizes into the indicators?
I would appreciate any help anyone could offer. Cheers!!
Fred Painchaud
Hi Ariel,
I never did it before but I don't see why it would not be possible in Python, especially if you say it is possible in C#. From the little I've been learning so far on LEAN:
1- The Python API is very close to the C# API. So if you know how to do it in C#, look for the same API/way in Python and you should be good to go.
2- I've also come across this, which might help you:Â
https://www.quantconnect.com/docs/algorithm-reference/consolidating-data#Consolidating-Data-Manually-Consolidating-Bar-Count
You would most likely use TickConsolidator instead of TradeBarConsolidator… something like that…
Yeah, I could not use my development environment to answer you but I got the idea to go look at the API reference and found this:
https://lean-api-docs.netlify.app/classQuantConnect_1_1Data_1_1Consolidators_1_1TickConsolidator.html
Hope this helps.
Cheers,
Fred
Louis Szeto
Hi Ariel, Fred
Thank you for your answer, Fred!
We hereby attached an example of using TickConsolidator. Enjoy!
Best
Louis
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.
Ariel Nechemia
Ah thank you Fred and Louis for your help, I really appreciate it! I can't believe that I missed that!
I am struggling to link my subscription manager to the consolidated data, in order to be used with MACD. I haven't really gone into programming how the algorithm will trade based on its' data yet though, but would you mind taking a look at my code? I would appreciate any pointers you may be able to give me.
Varad Kabade
Hi Ariel Nechemia,
Thank you for your patience. The above algorithm recreates and registers the indicator on every on512Data call. We need to create the indicator once and store the object in the dictionary to resolve the issue. Refer to the attached backtest.
Best,
Varad Kabade
Ariel Nechemia
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!