[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Linear Trend with Automatic Start Point



PureBytes Links

Trading Reference Links

Joe, that's pretty cool, but it doesn't really help me because I want
the starting point to be defined automatically so I can backtest it
without defining it by having to look at the chart.  Is it possible to
use a barssince value to define the period for the regression as in my
example?

> > Daysbackb = LastValue(LowestSinceBars( Buy, C)); 
> > shift = Param("Look back period",0,0,50000,1); 
> > xb = Cum(1);
> > lastxb = LastValue( xb ) - shift; 
> > ab = LastValue( Ref(LinRegIntercept( p, Daysbackb), -shift) ); 
> > bb = LastValue( Ref(LinRegSlope( p, Daysbackb ), -shift) ); 
> > yb = Ab + bb * ( xb - (Lastxb - DaysBackb +1 ) );

Chuck

--- In amibroker@xxxxxxxxxxxxxxx, "Joe Landry" <jelandry@xxx> wrote:
>
> Charles -  I didn't look at your code but here's food for thought. 
This clip
> from another script draws a trendline starting from the cursor going
back in time. 
> HTH, Joe 
> _SECTION_BEGIN("slope study");
> 
> Plot(C,"Close",1,64); 
> 
> _TRACE("DBGVIEWCLEAR"); 
> 
> // LINEAR REGRESSION LINE
> 
> Daysback = Param("Lookback",20,2,100,1); 
> 
> x = Cum(1); 
> 
> lastx = SelectedValue( x );
> 
> // Lastx = LastValue(x); 
> 
> // Set last bar at selected value
> 
> // Plot from that point backwards for NN bars say 10
> 
> i = LinRegIntercept(Close,Daysback); 
> 
> aa = LastValue(ValueWhen(x ==Lastx,i)); 
> 
> s = LinRegSlope(Close,Daysback); 
> 
> bb = LastValue(ValueWhen(x==Lastx,s)); // Slope of the regressed line
> 
> _TRACE("Intcpt= "+aa +" Slope= "+bb); 
> 
> y = Aa + bb * ( x - (Lastx - DaysBack) );
> 
> _TRACE("lastx= "+ Lastx + " LX - 20= "+ (Lastx-20)); 
> 
> Plot( IIf( x >= ( Lastx-daysback) AND x <= Lastx, y, -1e10 ),
"LinReg", colorRed,8 );



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.11/542 - Release Date: 11/20/2006