Back

Processing Custom Event Queue

Hello Everyone!

I like to see if this is possible with QuantConnect. My trading signal would be like 3 steps processes as the following:


1. For each 10 minute price update, calculate the the simple moving average and RSI for different time frames :


SMV(timeframe) :

SMV(10 minutes)
SMV(1 hour)
SMV(1 day)


RSI(timeframe) :

RSI(10 minute)
RSI(1 hour)
RSI(1 day)


2. for each indicator calculated, fire an event if the following condition is met:

price cross below SMV(timeframe)
price cross above SMV(timeframe)
RSI(timeframe) cross below 30
RSI(timeframe) cross above 30
RSI(timeframe) cross below 70
RSI(timeframe) cross above 70



3. process the event queue. Based on the history of event queue, I have some logic to determine whether an event is to be ignored, or to be used to trigger a trade.


The reason to keep an event queue is I need the whole event history, not just the event itself to determine how to use the event

It would be great if you can suggest how to structure, or provide some sample code to accomplish this.

Thanks!

Kevin
Update Backtest








typo correction: should be SMA.

Lets make it a 20-period SMA, and 14-period RSI.

0

Hi Kevin,

From a purely coding standpoint, I think this can definitely be done. You'd be invoking six independent indicators, and then we'd set up the OnData() method to only evaluate our current position if ten minutes have passed since the last evaluation. During this evaluation, we'd determine the boolean (True/False) result of each of the six "checks" that you've mentioned:

price cross below SMV(timeframe)
price cross above SMV(timeframe)
RSI(timeframe) cross below 30
RSI(timeframe) cross above 30
RSI(timeframe) cross below 70
RSI(timeframe) cross above 70

I assume you'd like to evaluate all six of these checks for all three lookback periods? So three lookback periods times six checks is 18 checks. So far so good.

We'd then take all of this data and throw it into an object (let's call it RollingHistory.cs) declared up in the global space that "follows us" as we move through time. This object would be responsible for containing the resultant check data as we move through time.

So after the evaluation, we pump the results of all 18 checks into a new slot in our RollingHistory.cs object, then evaluate our history based on your choice of logic.

All of this can be done from OnData(). :-)

I could even help write this up if I have time. Currently busy, but I could let you know. But for the meantime, you should know that from what you've written, this is very doable.

0

If you need a rolling history of data, check out the RollingWindow<T> class, designed specifically for this purpose.

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.


I just realized I reinvented the wheel in several of my algos, Michael. I need to read through the documentation more closely :-P

0

Thank you Michael, Stephen.

Yes sample code would be great!

One question on calculating the indicator. I see from Jared's video that there js a code library that I can copy over the code for indicator calculation but I don't see the code library on the site.
What is the easiest way to calculate mutiple indicators with different time frame? I also need average true range.
0

@Kevin, here's a list of the currently supported indicators. Here's a thread from this forum that goes into some of the features in the indicator system. Also, take a look through the many example algorithms in github. They explain most features offered by the platform.

As for creating an indicator with a certain time frame:var atr = ATR("SPY", 14); // uses data time frame
var atr2 = new AverageTrueRange(14);
// register atr2 to receive automatic data updates
RegisterIndicator("SPY", atr2, TimeSpan.FromMinutes(30));

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.


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