int n=m_pos[1]-m_pos[0]+1; //---- calculate price values double value=Close[m_pos[0]]; double a,b,c; double sumy=value; double sumx=0.0; double sumxy=0.0; double sumx2=0.0; for(i=1; i<n; i++) { value=Close[m_pos[0]+i]; sumy+=value; sumxy+=value*i; sumx+=i; sumx2+=i*i; } c=sumx2*n-sumx*sumx; if(c==0.0) return; b=(sumxy*n-sumx*sumy)/c; a=(sumy-sumx*b)/n; m_value[0]=a; m_value[1]=a+b*n; //---- maximal deviation double maxdev=0; double deviation=0; double dvalue=a; for(i=0; i<n; i++) { value=Close[m_pos[0]+i]; dvalue+=b; deviation=fabs(value-dvalue); if(maxdev<=deviation) maxdev=deviation; }
where
m_pos[0] и m_pos[1] - begin and end bars numbers
m_value[0] и m_value[1] - calculated prices ont the begin and end bars of the channel (central line)
maxdev - half-width of the channel
note that bars are numbered from begin to end - last bar is current bar
Thank you!
:)
:)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
it says in the manual that Linear Regression Channel uses maximum closing price deviation for drawing the parallel lines, and Standard Deviation Channel uses standard closing price deviation.
Is the central regression line also calculated on closing prices, or how is it calculated?