'***********************************************************************
'*   Linear Regression Hook Stop
'*     by Jeremy Williams
'*	   February 21,2006
'*
'*  Summary: 
'*
'*		This stop sends an exit signal when the Linear Regression
'*  moves against the trade for three consecutive bars 
'*
'*  Parameters:
'*
'*    	Periods: Specifies the number of periods used to calculate
'*					the linear regression
'*
'***********************************************************************

#Stop
#Param "Periods",14
Dim LongExit 	As Boolean
Dim ShortExit 	As Boolean

' Determine if the conditions exist for an exit
' from a long position: Three consecutive losses in LnReg 
LongExit = LnReg(Periods) < LnReg(Periods)[1]					
LongExit = LongExit and LnReg(Periods)[1] < LnReg(Periods)[2] 
LongExit = LongExit and LnReg(Periods)[2] < LnReg(Periods)[3] 

' Determine if the conditions exist for an exit
' from a Short position: Three consecutive gains in LnReg
ShortExit = LnReg(Periods) > LnReg(Periods)[1]
ShortExit = ShortExit and LnReg(Periods)[1] > LnReg(Periods)[2]
ShortExit = ShortExit and LnReg(Periods)[2] > LnReg(Periods)[3] 

'If the conditions are correct send exit signals
If LongExit and Signal = LongSignal  then
	Signal = ExitSignal
Else If ShortExit and Signal = ShortSignal then
	Signal = ExitSignal
End If