I willingly believe that it is possible to do a lot of functions with accelerated calculation. Like subtract a value from the end of a period and add a new value to the beginning, without a cycle.
In particular, here is an example of how you can calculate several types of filter from simple waving to linear regression without a cycle.
Here at N=0 - normal SMA, N=1 - linear-weighted, N=3 - linear regression. And you can also get intermediate values as N is fractional. I also calculated the RMS in a similar way. I think polynomial regression can be done the same way. It would be a practical necessity. At least, I have not managed to use polynomial regression in profitable Expert Advisors yet. Channels on EMAs are simpler and work well in practice.
Here is a slightly contrived variant of linear regression on mq4 with RMS without cycle. There is a cycle once at initiation, or more precisely, when calculating the first set of values, and that's all, - then there are only sums and differences. Of course, it is much faster than with cycles. One subtlety is that the period is specified in hours and is recalculated when switching timeframes.
#property strict#property indicator_chart_window#property indicator_buffers6#property indicator_color1clrDodgerBlue#property indicator_color2clrOrangeRed#property indicator_color3clrLavender#property indicator_color4clrLavender#property indicator_color5clrMediumAquamarine#property indicator_color6clrMagenta#property indicator_width12#property indicator_width22#property indicator_style52#property indicator_type1DRAW_LINE#property indicator_type2DRAW_LINE#property indicator_type3DRAW_LINE#property indicator_type4DRAW_LINE#property indicator_type5DRAW_LINE#property indicator_type6DRAW_LINE//===========================externdouble hrLR = 12;
externdouble ksq = 1;
externint i0 = 1;
externint SPR = 1;
//===========================double ss[],ssL[],sH[],sL[],ma[],sU[];
double lri,sq,mai,ui,spr2;
int p,fs;
//******************************************************************int init()
{
SetIndexBuffer(0,ss);
SetIndexBuffer(1,ssL); SetIndexEmptyValue(1,0);
SetIndexBuffer(2,sH);
SetIndexBuffer(3,sL);
SetIndexBuffer(4,ma);
SetIndexBuffer(5,sU);
//--------------------
p=int(hrLR*60/Period()); if (p<3) p=3;
if (SPR<0) spr2=-SPR*Point/2;
return(0);
}
//******************************************************************int start()
{
int cbi=Bars-IndicatorCounted()-1; if (cbi<0) return(-1);
if (i0==1 && cbi==0) return(0); if (cbi==1) cbi=0;
if (SPR>0) spr2=NormalizeDouble(Ask-Bid,Digits)/2;
if (cbi>1)
{
cbi=Bars-p-1;
af_LR0(0,cbi); ui=mai;
}
//------------------------------for(int i=cbi; i>=0; i--)
{
lri=af_LR0(1,i);
ss[i]=lri;
sH[i]=lri+sq;
sL[i]=lri-sq;
ma[i]=mai;
if (sL[i]>ui) ui=sL[i]; elseif (sH[i]<ui) ui=sH[i];
sU[i]=ui;
if (ss[i]>ss[i+1]) fs=1;
if (ss[i]<ss[i+1]) {if (fs==1) ssL[i+1]=ss[i+1]; fs=2;}
if (fs==2) ssL[i]=ss[i]; elseif (fs==1) ssL[i]=0.0;
}
return(0);
}
//********************************************************************double af_LR0(int index, int i)
{
staticdouble sx,syp,sxy,syyp,S;
double ci=0,c1=0,cp=0,sy,syy,aa,bb;
staticint ti;
if (index==1)
{
if (ti!=Time[i])
{
if (i0==0) {c1=Close[i+1]+spr2; cp=Close[i+p]+spr2;} elseif (i0==1) {c1=Open[i+1]+spr2; cp=Open[i+p]+spr2;} elseif (i0==2) {c1=(High[i+1]+Low[i+1])/2+spr2; cp=(High[i+p]+Low[i+p])/2+spr2;}
sxy+=syp+c1-p*cp;
syp+=c1-cp;
syyp+=c1*c1-cp*cp;
ti=int(Time[i]);
}
}
else
{
int j;
double sxx;
sx=0.0; sxx=0.0;
for (j=0; j<p; j++) {sx+=j; sxx+=j*j;}
S=sx*sx-p*sxx;
syp=0.0; sxy=0.0; syyp=0.0;
for (j=1; j<p; j++)
{
if (i0==0) ci=Close[i+j]+spr2; elseif (i0==1) ci=Open[i+j]+spr2; elseif (i0==2) ci=(High[i+j]+Low[i+j])/2+spr2;
syp+=ci;
sxy+=j*ci;
syyp+=ci*ci;
}
ti=int(Time[i]);
}
if (i0==0) ci=Close[i]+spr2; elseif (i0==1) ci=Open[i]+spr2; elseif (i0==2) ci=(High[i]+Low[i])/2+spr2;
sy=syp+ci;
syy=syyp+ci*ci;
aa=(sx*sy-p*sxy)/S;
bb=(sy-aa*sx)/p;
sq = (syy - aa*sxy - bb*sy)/(p-2);
if (sq>=0) sq = MathSqrt(sq)*ksq;
mai=sy/p;
return(bb);
}
//********************************************************************
A lot, actually. I used to measure it with GetTickCount(). But it's well noticeable when you need to do a lot of optimizations. One thing is when you have to count a lot of variants for several hours, and another thing is when you have to do it in several dozens or units of minutes. But it's rarely needed. That's why you may not bother with it too much.
I willingly believe that it is possible to do a lot of functions with accelerated calculation. Like subtract a value from the end of a period and add a new value to the beginning, without a cycle.
In particular, here is an example of how you can calculate several kinds of filter from simple waving to linear regression, without cycle.
Here at N=0 - normal SMA, N=1 - linear-weighted, N=3 - linear regression. And you can also get intermediate values as N is fractional. I also calculated the RMS in a similar way. I think polynomial regression can be done the same way. It would be a practical necessity. At least, I have not managed to use polynomial regression in profitable Expert Advisors yet. Channels on EMAs are simpler and work well in practice.
Here is a slightly complex variant of the linear regression in mq4 with RMS without loops. There is a cycle once at initiation, or more precisely, when calculating the first reading, and that's it - then there are only sums and differences. Of course it calculates many times faster than with cycles.
Yes. That is correct. This is a real example of cycle-free RMS calculation in linear regression. True, there is a small error somewhere in the algorithm, leading to all three lines (centre, upper and lower limits of the channel) being shifted upwards.
Yes. That is correct. This is a real example of cycle-free RMS calculation in linear regression. True, there is a small error somewhere in the algorithm, leading to all three lines (centre, upper and lower limits of the channel) being shifted upwards.
And there's just half of the spread added up. I did this once, to test a trading Expert Advisor to have alignment relative to - Ask-Bid. If you set SPR=0, there will be no offset. It will count purely on bid prices.
ANG3110: And there's just half of the spread added in. I did this once to test a trading Expert Advisor to have alignment relative to - Ask-Bid. If we set SPR=0, there will be no offset. It will count purely on bid prices.
Yes, exactly. A complete match to my linear regression implementation.
Vladimir Baskakov: How is the Sultonov indicator doing? Has it broken its back to forex yet or is it in the process of doing so?
The indicator is working on one cent real account at UPU on a "run and forget" basis with a deposit of 48 c.u. The second month it has been hovering around 50, apparently, waiting for its time. It is impossible to receive more than 10 % per annum on Forex, stably and without risk, provided reinvestment of profits for many years - these are my conclusions on the backbone of Forex. The hasty conclusions of 8 years ago are shattered by the reality of the market. The powerful universal regression model has failed miserably, producing bankable profits. The URM does a great job on all the technical, social, mining (extracting gold from poor ores) and other processeso except the market element. The conclusion is that regression models have limited potential to extract profits from the market.
I willingly believe that it is possible to do a lot of functions with accelerated calculation. Like subtract a value from the end of a period and add a new value to the beginning, without a cycle.
In particular, here is an example of how you can calculate several types of filter from simple waving to linear regression without a cycle.
Here at N=0 - normal SMA, N=1 - linear-weighted, N=3 - linear regression. And you can also get intermediate values as N is fractional. I also calculated the RMS in a similar way. I think polynomial regression can be done the same way. It would be a practical necessity. At least, I have not managed to use polynomial regression in profitable Expert Advisors yet. Channels on EMAs are simpler and work well in practice.
Here is a slightly contrived variant of linear regression on mq4 with RMS without cycle. There is a cycle once at initiation, or more precisely, when calculating the first set of values, and that's all, - then there are only sums and differences. Of course, it is much faster than with cycles. One subtlety is that the period is specified in hours and is recalculated when switching timeframes.
Why did Fedoseyev self-depart, reasoning correctly?
Because he reasoned incorrectly.
Read the thread.
How much does it speed up code execution?
What does "no loop" do for you?
How much faster does it make your code run?
I willingly believe that it is possible to do a lot of functions with accelerated calculation. Like subtract a value from the end of a period and add a new value to the beginning, without a cycle.
In particular, here is an example of how you can calculate several kinds of filter from simple waving to linear regression, without cycle.
Here at N=0 - normal SMA, N=1 - linear-weighted, N=3 - linear regression. And you can also get intermediate values as N is fractional. I also calculated the RMS in a similar way. I think polynomial regression can be done the same way. It would be a practical necessity. At least, I have not managed to use polynomial regression in profitable Expert Advisors yet. Channels on EMAs are simpler and work well in practice.
Here is a slightly complex variant of the linear regression in mq4 with RMS without loops. There is a cycle once at initiation, or more precisely, when calculating the first reading, and that's it - then there are only sums and differences. Of course it calculates many times faster than with cycles.
Yes. That is correct. This is a real example of cycle-free RMS calculation in linear regression.
True, there is a small error somewhere in the algorithm, leading to all three lines (centre, upper and lower limits of the channel) being shifted upwards.
Yes. That is correct. This is a real example of cycle-free RMS calculation in linear regression.
True, there is a small error somewhere in the algorithm, leading to all three lines (centre, upper and lower limits of the channel) being shifted upwards.
What does this "no loop" do for you?
How much faster does it make your code run?
The RMS calculation alone can give a gain of about 10 to 1,000 times, depending on the period.
And there's just half of the spread added in. I did this once to test a trading Expert Advisor to have alignment relative to - Ask-Bid. If we set SPR=0, there will be no offset. It will count purely on bid prices.
Yes, exactly. A complete match to my linear regression implementation.
How is the Sultonov indicator doing? Has it broken its back to forex yet or is it in the process of doing so?
The indicator is working on one cent real account at UPU on a "run and forget" basis with a deposit of 48 c.u. The second month it has been hovering around 50, apparently, waiting for its time. It is impossible to receive more than 10 % per annum on Forex, stably and without risk, provided reinvestment of profits for many years - these are my conclusions on the backbone of Forex. The hasty conclusions of 8 years ago are shattered by the reality of the market. The powerful universal regression model has failed miserably, producing bankable profits. The URM does a great job on all the technical, social, mining (extracting gold from poor ores) and other processeso except the market element. The conclusion is that regression models have limited potential to extract profits from the market.