Back

Indicators with multiple resolutions for multiple symbols

Great day,

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 :)
Update Backtest








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


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


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

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


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

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

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

Everything right, very good system, big thanks.
0

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

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

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

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, thank you, pretty clear, will play with it :)
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