'**********************************************************************
'*   Z-Score Moving Average System  (ZMA)
'*     by Jeremy Williams
'*	   February 21,2006
'*
'*	Adapted from Technical Analysis of Stocks and Commodities
'*    February 2003
'*
'*  Summary: 
'*
'*      This system generates signals based on crossover of the moving
'*  average of the Z-score indicator and the moving average of the moving
'*  average of the Z-score. For more information see "Z-Score Indicator" 
'*  in the February 2003 edition of Technical Analysis of Stocks and
'*  Commodities.
'*
'*  Parameters:
'*
'*  	N= Specifies the number of Periods used for the Average and
'*             Standard Deviation calculations used to determine the 
'*             Z-Score.
'*		
'*		ShortPeriod= Specifies the number of periods used in the calculation
'*                   of the first moving average
'*
'*      LongPeriod= Specifies the number of periods used in the calculation
'*                   of the compound moving average
'*
'*	Note: Requires the Z-Score Indicator
'*
'******************************************************************** 

#System

#Param "N",20
#Param "ShortPeriod",3
#Param "LongPeriod",5

Dim myZScore    As Single
Dim LongMA 		As Single
Dim ShortMA		As Single

myZScore = ZScore(N)					' Find the Z-Values, and their Moving Averages
ShortMA = SMA(myZScore,ShortPeriod)
LongMA = SMA(ShortMA,LongPeriod)


debugmsg(myzscore)
debugmsg(LongMA)
debugmsg("*******************")

If ShortMA > LongMA then				' If the Short MA is above the LongMA then send long signal
	Signal = LongSignal
Else If ShortMA < LongMA then			' If the Short MA is below the LongMA then send short signal
	Signal = ShortSignal
End if