Hello Jolly:
Someone had the definition of a kludge the other day in this forum and surely 
this is probably one. I clipped it out of a database I have of almost few years 
of interesting work publ here on the forum, starting with Dimitris Tsokakis and 
Corey Saxe. 

Try this and see if it works for you. The angle that gets printed in the title 
by the WriteVal  looks about right but how can you tell when both scales of the 
display are changeable. My understanding is the slope of the regression is not 
relative to the plotting scale although you can get some idea of it.  Had a 
hard time finding a strong upward slope. 

I'm hoping this helps you understand it and you can turn it into your logic for 
your trading rules.

Best regards
Joe L. 
THANKS to Herman who's a coreligionist in believing that one should us a tool 
like InfoSelect to store and index all this "stuff" and code clippets.     

Daysback = Param("DysBack",126,30,252,1);

x = Cum(1); // the X axis, abscissa

LastX = LastValue(X);

C1 = Close; 

aa = LastValue( LinRegIntercept( C1, Daysback) );

bb = LastValue( LinRegSlope( C1, Daysback ) );

yy = Aa + bb * ( x - (Lastx - DaysBack) ); // the algebraic equation for a 
straight line

yy=IIf( x >= (lastx - Daysback), yy, -1e10 ); // roll the plot forward and show 
only the 6 months

Plot( yy, "LinRegression Line", colorDarkRed,styleThick);

UpperSEBand = YY + 2*StdErr(C,126);

LowerSEBand = YY - 2*StdErr(C,126);

Plot(UpperSEBand,"Upper 2 Sigma",colorBlue,styleLine);

Plot(LowerSEband,"Lower 2 Sigma",colorBlue,styleLine);

// General Section

period = 22; // 22 trading days a month

MPT_Period = Param("MPT Period", 252,125,500,5);

IndexSym = ParamStr("Russell 2000 Index Symbol","!spx");

Plot(Close,"Close",colorBlue,styleLine); 

// calc angel from bb

pi = 4 * atan(1) ; //Pi

slopeangle = atan(bb)*(180/pi); 

Title = FullName()+" "+ Date()+"\n"+ "Slope of Regression Line(in degrees) = "+ 
WriteVal(slopeangle,1.2)+

"\n"+"Standard Err of of RS Line(%) = "+ WriteVal(StdErr(100*Close,126),1.2); 




  ----- Original Message ----- 
  From: jollypollyanna 
  To: [email protected] 
  Sent: Tuesday, May 18, 2010 4:11 AM
  Subject: [amibroker] Linear Regression Angle


    

  --- In [email protected], "Tony Grimes" <tonez.em...@...> wrote:
  >
  > What do you mean be gradient of the slope?



  Hi. I'm obviously an AFL learner so am inquiring about the existence of a  
Linear Regression Angle formula. 

  Ideally to be effective the trend angle would need to be known so as to allow 
a trade to proceed based on whether the angle is greater than or lesser than 
your chosen boundaries.

  For example a trend angle of lesser than 30°  would not be traded. Or a trend 
angle greater than 60° would not be traded. Obviously the look back period 
would be the determinant of angle.  A number on a scale of say 1 to 10 would 
suffice rather than returning a specific angle which might be harder to code.

  Linear Regression Slope is an angle so maybe that angle could be defined  for 
use in trade selection?? 

  Any  concept or solution most welcome. 

  From the ESignal Forum ->

  "In fact, to obtain the LinearRegAngle one could take the ArcTangent of the 
LinearRegSlope function."




  

Reply via email to