Back

Struggling to use sequential indicators.

I'm trying to use sequential operators using the .Of() method. I haven't been successful using this operator with my own simple custom indicator. Can anybody tell me what mistake I am making?

I'm a little fuzzy on which of the indicators(or is both) that have to be registered, I tried to follow the "DisplacedMovingAverageRibbon.cs" example in the Lean source.

Thanks for any help.
Update Backtest








Hey @Jordan - you're correct that they both need to be registered. I fixed it by adding this line:
RegisterIndicator("SPY", returnIndicator, Resolution.Minute, x => x.Value);

This line: sma = _sma.Of ( myCustomIndicator );
takes the output of your custom indicator, and pipes it into the SMA indicator's input. In order for the myCustomIndicator to generate output's it needs to be registered for data updates.

You can do this manually if you wish to avoid using the register function.
myCustomIndicator.Update( T price );
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.


Thanks @Jared, but, the plot still shows a constant value of 0. I thought it could just be rounding small numbers to zero, so I multiplied it by 1000. It made no difference. When I try to test this on my desktop, it seems like the ComputeNextValue function isn't being called. It's more difficult to trace the problem on the online platform.

I'm not sure what's up...

Jordan
0


Thanks @Jared, but, the plot still shows a constant value of 0. I thought it could just be rounding small numbers to zero, so I multiplied it by 1000. It made no difference. When I debug this on my desktop, it seems like the ComputeNextValue function isn't being called. It's more difficult to trace the problem on the online platform.

I'm not sure what's up...

Jordan
0


Jordan,

I love seeing that you're digging into some of the advanced concepts in QC! I've made some changes to your indicator and I've also updated your registration. Your woes were two fold.

First, in your indicator we were never incrementing the '_count' variable. Also, this variable seems to be akin to the Samples property on the base class. So I've updated the code to use the Samples property (it is incremented before your ComputeNextValue function gets called).

Secondly, is that registration of indicators defines how to send them data. By defining a sequential indicator you're in fact defining how to send data from one indicator to another. In this case, you don't want to register the 'inner' indicator, just the combined sequential indicator.


// Suppose we want the EMA of the RSI. The RSI is our inner indicator, and the EMA our outter
// We'll define them as follows
var rsi = new RelativeStrengthIndex(14);
var emaOfRsi = new ExponentialMovingAverage(5).Of(rsi);

// Now we have our indicators. The emaOfRsi is actually going to be responsible for sending
// data to the rsi and then piping that output and sending it to our ema, so we only
// want to register the emaOfRsi, since sending data to him will send data to the rsi and ema
// as well
RegisterIndicator("SPY", emaOfRsi, Resolution.Daily, x => x.Value);


// later on we could plot either the rsi or the emaOfRsi
0


@JordanIlott I discussed this with Michael and we're thinking of tweaking this so you don't need to Register the sequential/composite part. With a little internal magic we can make it automatically get the RSI updates. We'll update this for the next release of LEAN :)
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.


Thanks @Jared and @Michael, your efforts to explain have helped a lot. The stupid mistake regarding the _count increment was the result of too much guess and test to figure out what was going on. Now that I understand the registration requirements I think I can get to work on some other indicators.

I saw that there are some updates to the tutorials, that's awesome! I'm heading of to read those now.

Jordan
0

Well, I have more questions. What if I end up with parallel calculations of composite indicators? So, let's say I have two equally derived indicators that depend on the same chain up until two final indicators.Of are created. It seems like if I register them both, I only get the first one that was registered. I can work around this using parallel chains of sequential indicator but it seems wasteful, and it's a little unintuitive when thinking in the dataflow mindset encouraged by the sequential and composite indicator framework.

Second question:
Using the handy plus, minus, etc... methods of the composite indicators is great, but, they don't seem to respect Indicator.IsReady. This is catastrophic in the case of division when the not-yet-ready indicator simply returns 0 from the ComputeNextValue method(for example the StandardDeviation indicator).

Thoughts?
0

I think the new proposed style will handle this. We were discussing tweak the sequential indicators to be driven by internal events instead of the external sequential indicator. E.g. flowing backwards:

var sma = SMA("SPY", 3);
var rsi = RSI("SPY", 14);
var rsiSMA = sma.Of(rsi);


rsiSMA.Value<-OutputEvent<-(IsReady)-sma.Update()<-OutputEvent<-(IsReady)- RSI
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.


That sounds great. Any idea of when the changes will be made? In the mean time I could work around the problem but will wait if the solution is coming soon.
0

I'd recommend working around it for now; I'll ping you once they are coded up and on the public cloud. I wouldn't expect more than a week though, we're just finishing off the brokerage setup handler for live trading & IBrokerage implementations :)
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.


Ok, sounds good.
0

The current change I'm looking at would work very closely to what Jared suggested. The only real difference is you wouldn't want to define both the sma and rsi using the helper functions.


// this configures 'sma' to receive auto updates from SPY data
var sma = SMA("SPY", 3);
// this configures 'rsi' to receive auto updates from SPY data
var rsi = RSI("SPY", 14);
// this would also configure 'sma' to receive auto updates from 'rsi'
// which we probably don't want to do (multiple data source is almost never a good idea)
var rsiSMA = sma.Of(rsi);


Instead we'll define our data source, the root, as 'rsi'

// this configures 'rsi' to receive auto updates from SPY data
var rsi = RSI("SPY", 14);
// this creates a new SMA and configures it to receive auto updates from 'rsi'
var rsiSMA = new SimpleMovingAverage(3).Of(rsi);
// the new SimpleMovingAverage is returned into rsiSMA
// so it's the same as this
rsiSMA = new SimpleMovingAverage(3);
// since this is purely a configuration step (wires up event handlers) we don't
// actually need its return value, but the value that is returned is the value on
// the left side of the .Of call, this is considered the 'second' indicator since it
// receives data from the 'first' (in this case 'rsi').
sma.Of(rsi);


I'm also working on updates being made to the CompositeIndicator to work similarly to this as well, he will, however, need to listen to two indicators before he updates. Hopefully tonight or tomorrow I'll have something in master.
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