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
Need some guidance on how to use indicators with multiple resolutions in multiple symbols with defined consolidator?
1. How to declare those indicators properly for each symbol and request them?
//inside initialize
foreach(var symbol in _symbols)
{
_sma = SMA(symbol, ...);
}
//inside tradebars
OnData(TradeBars data)
{
.. bar consolidator, etc. stuff
foreach(var symbol in )symbols)
{
_sma = [for each symbol]?
}
}
2. What I was able to achieve is this, but by some reason it only uses 3 first symbols from lists, don't think it's according to logic, so my understanding ends here :)
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.
Michael H
35.4k
,
Tadas, I've thrown together an example of using the IDataConsolidator system along with many symbols. In this example they all use the same resolution, but I've written such a way that it should be easy to modify each symbol's consolidation resolution. Take a peak and let me know if I can help any further!
1
Tadas Talaikis
85.1k
,
Aha, everything now seems pretty compact and simple. Am I right to put custom data directly into consolidator on Initialize()? Here's MACD replica with 3 SMAs.
0
Michael H
35.4k
,
Yup that looks right to me! You could also just use the MovingAverageConvergenceDivergence indicator class which has a fast, slow, and signal period.It also allows you to specify different types of moving averages (exp, simple, wilders)
0
Michael H
35.4k
,
I made some mods to the algo I posted before to show how you can easily have different resolutions on the same symbol. We accomplish this by defining another consolidator.
Hope this comes in handy!
1
Tadas Talaikis
85.1k
,
Excellent stuff, Michael, now have a better grasp how it all works.
One question regarding this. If I need lower resolution for Window TradeBars than indicators' resolution, seems system can't do that. Like:
Data.Add(symbol, new SymbolData(symbol, SecurityType.Forex, _OneMinute, RollingWindowSize));
In this case seems I need to make different classes for each bar resolution type? Not tried it yet.
0
Tadas Talaikis
85.1k
,
OK, maybe I was a bit unclear. What if some indicator is on lower timeframe than bars and order logic depends on that lower timeframe indicator? Trading will be done "inside" higher timeframe bar or...?
0
Michael H
35.4k
,
You can set this up however you need it to be. The reason for the Bars property is merely convenience to provide the algorithm access to the last n bars of data produce by a consolidator. The period used for consolidation is completely up to you. We could remove the Bars property and all the indicators will still work as they did before.
Likewise, any indicator can be on any resolution, all that needs to be done is define a consolidator and in its DataConsolidated event attach an event handler to update the indicator.
What I provided is a little structure around this idea. We have a dictionary of symbol data keyed by the symbol. This just provides a way of organizing all of our stuff. We can put anything in SymbolData.
As for the trading being done, you can trade on the resolution specified in your AddSecurity call. What I did was provide a means of letting the algorithm know when the Bars window was just updated. If this doesn't fit your use case then you could simply remove the if check.
If I'm missing your question please let me know, but in short, it can behave however it needs to behave. It just needs to be set up properly.
1
Tadas Talaikis
85.1k
,
Everything right, very good system, big thanks.
0
Tadas Talaikis
85.1k
,
Well, seems I'm having another question. Is it possible to update indicators with some custom data from inside OnData() as seems I don't yet get how to do that for example, if I have some data from Quandl, then I do operations with it inside OnData and then update is on Initialize() wouldn't work even if I load such data through SymbolData().
0
Michael H
35.4k
,
Of course it's possible. Just create an indicator and don't update it with a consolidator in Initialize(). Update it directly in OnData().
In Initialize()
symbolData.MyCustomIndicator = new MyCustomIndicator();
In OnData()
symbolData.MyCustomIndicator.Update( data );
1
Michael Handschuh
50.5k
,
Just call the Update method on the indicator. For example:
// class member fields - this is our symbol data collection
Dictionary Data;
// in Intialize() - we define our indicators by newing them up, note we don't need a consolidator
Data["SPY"].MyCustomDataIndicator = new MyCustomDataIndicator();
// in OnData - we control when Update is called on our indicator passing in whatever data we want
Data["SPY"].MyCustomDataIndicator.Update( data );
When you want full control over the update processing of indicators it's pretty straight forward. You can just create it and use it!
2
Tadas Talaikis
85.1k
,
Michael, thank you, pretty clear, will play with it :)
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!