Back

Multiple RollingWindow solution?

I have following code that generates RollingWindow error and can't what parameters needed for RW periods. Maybe some better solution?



//init
RollingWindow _L0 = new RollingWindow(?);
RollingWindow _L1 = new RollingWindow(?);
RollingWindow _L2 = new RollingWindow(?);
RollingWindow _L3 = new RollingWindow(?);

//OnData
L0 = (1.0m - _gamma)*_price + _gamma*_L0[1];
_L0.Add(L0);
if(!_L0.IsReady) return;

L1 = -_gamma*L0 + _L0[1] + _gamma*_L1[1];
_L1.Add(L1);
if(!_L1.IsReady) return;

L2 = -_gamma*L1 + _L1[1] + _gamma*_L2[1];
_L2.Add(L2);
if (!_L2.IsReady) return;

L3 = -_gamma*L2 + _L2[1] + _gamma*_L3[1];
_L3.Add(L3);
if (!_L3.IsReady) return;
Update Backtest








With the code supplied you'll need a RollingWindow period of at least 2, since the highest indexer used is 1 (zero based indexing). Does that help or did I not completely understand the question?
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.


Doesn't help, tried many variations, all end with:


Runtime Error: Must be between 0 and Count 1
Parameter name: i
1 (Open Stacktrace)
0

It's also important to wait for the RollingWindow.IsReady to return true. You could also add this condition above the math in OnData:if (_L0.Count < 2) return;
The idea here is that we want to index to '1' which requires a minimum Count of 2, so if less than 2, return.
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.


Thank you, now I understood where problem was :) Though empty indicator is also with 0s. Simply changed to following form, seems working:


_L0.Add(L0);
if(!_L0.IsReady) return;
L0 = (1.0m - _gamma)*_price + _gamma*_L0[1];
0


if (_L0.Samples == 0)
_L0.Add(L0);
0

Hey @Tadas,

Seems you're implementing Laguerre, isn't?

I made an implementation some months ago and I left behind because the results were poor.

Just in case, here's my shoot, hope it helps.

JJ
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.


That's right, Laguerre. Thank you for sharing, My own initial approach:
0


Thanks you @Tadas!

I'll research the use of Renko bars, seem interesting.

Cheers, JJ

P.S. When I can figure out something, I always remember your profile image :D
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.


Jay Jay,

First off, thanks for sharing your Laguerre indicator. I took a look at it and I was wondering if you can tell me where you define the lookback period. Many of the Laguerre indicators that I have seen use a 900 period lookback (or some other value). But I did not see a place in your code where this is defined. Could you point me to the right place? 

Cheers,
Mitch

0

Hey Mitch Christow,

You’re welcome!

I completely forgot this (ugly) implementation and I also forgot the math behind.

From a first sight of the formulas, there is no period, just the factor variable. And for the first actualL formula the factor range is [0, 1]. Seems the factor fulfills the same role as the alpha parameter in an exponential moving average. If so, the higher the factor, the smoother the indicator.

But I’m not sure how to transformation the factor into period.

Respect to the lookback you mention, are you sure they mean the indicator parameter?

Best

JJD

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.


Hi JJD,

Thanks for the quick reply. I think I found part of my confusion. There are several types of Laguerre indicators out there. The one that I have seen before (and am trying to recreate) is the Laguerre ACS indicator. Here is a link to some conversations about the Laguerre ACS. 

https://www.forexfactory.com/showthread.php?t=53189

Along with a code example for a different platform of what the Laguerre ACS looks like.

https://www.forexfactory.com/showthread.php?p=2143557#post2143557

I am trying to implement this custom indicator, but since I have very limited experience on quantconnect I am floundering quite a bit at the moment. If at all possible I would love to see if you can help me out with getting this one running on this platform. I'll be happy to connect privately with you if that is more efficient. Of course I would understand if you are too busy. Thanks in advance.

//---- input parameters
extern double gamma=0.6;
extern int MaxBars=1000;
extern int MA = 2;

double L0 = 0, L1 = 0, L2 = 0, L3 = 0, L0A = 0, L1A = 0, L2A = 0, L3A = 0, LRSI = 0, CU = 0, CD = 0;
double Buffer1[], dummy[];

int start() {
   int i, j, counted_bars=IndicatorCounted(); double sum1=0;
   if (counted_bars < 0) return(-1);  if (counted_bars > 0) counted_bars--;
   if (MaxBars>Bars) MaxBars=Bars;
   SetIndexDrawBegin(0,Bars-MaxBars);

   for(i=MaxBars-1;i>=0;i--) { sum1=0;
      L0A = L0; L1A = L1; L2A = L2; L3A = L3;
      L0 = (1 - gamma)*Close[i] + gamma*L0A;
      L1 = - gamma *L0 + L0A + gamma *L1A;
      L2 = - gamma *L1 + L1A + gamma *L2A;
      L3 = - gamma *L2 + L2A + gamma *L3A;
      CU = 0; CD = 0;
      if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
      if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
      if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;
      if (CU + CD != 0) LRSI = CU / (CU + CD);
      dummy[i] = LRSI;
      if (MA < 2) Buffer1[i] = dummy[i]; else { for (j=i; j < i+MA; j++) sum1 += dummy[j]; Buffer1[i] = sum1/MA; }
   }

Cheers,

Mitch

0

Quick addendum. What is throwing me the most about this algorithm is how to apply a X period moving average to the resulting calculation (line 27) to smooth out the results. I am not sure how to apply that to a custom indicator on the LEAN engine.

0

Hey Mitch,

For sure you can do it by yourself, is easier that what you think!

Some tips:

  • First make sure you understand the math, that is the 90% of developing an indicator.
  • I don’t fully understand the code you shared but seems to me that the code estimates the indicator for a series of data (1000 observation as maximum). Lean indicators process the data observation by observation, keep that in mind.
  • Then follow a model. I suggest to check out his implementations ExponentialMovingAverageDoubleExponentialMovingAverage and T3MovingAverage.
  • Respect to the factor-to-period issue, in the case of EMA you can see that actually there is a correspondence between the EMA alpha (or gamma, or factor, or k) and a period. But in other two indicators there is not correspondence, and the period is only used to check if the indicator is ready. So don’t bother for that.
  • My ugly implementation still makes the estimation for the Laguerre, use it!

Once you have something on hands, I’ll be very glad to help.

Feel free to contact me at QuantConnect’s slack at anytime.

Good luck!

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.


HI JJD,

Thanks for all the tips. I will give it a shot and see how far I can get. It is much apprecaited.

Cheers,
Mitch

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