Input: FastMA(9),SlowMA(26),MacdMA(4), NCOs(4), NBars(50), Trailbar(6); Vars: MVal(0), MAvg(0), MDif(0), Counter(0), TotalBars(0), HighestHi(0), LowestLo(0); Array: CO[2,50](0); MVal = MACD(Close,FastMA,SlowMA); MAvg = XAverage(MACD(Close,FastMA,SlowMA),MacdMA); MDif = MVal - MAvg; { Store the MACD Cross information in the CO array } If MDif Crosses Over 0 OR MDIF Crosses Under 0 Then Begin For counter = 0 to 49 Begin CO[ 0 , 50 - Counter ] = CO[ 0 , 49 - Counter ]; CO[ 1 , 50 - Counter ] = CO[ 1 , 49 - Counter ]; CO[ 2 , 50 - Counter ] = CO[ 2 , 49 - Counter ]; End; CO[ 0 , 0 ] = BarNumber; CO[ 1, 0 ] = High; CO[ 2, 0 ] = Low; End; { Find the Highest High and the Lowest Low of the cross over and under bars } HighestHi = -1; LowestLo = 9999; For counter = 0 to NCOs-1 Begin If CO[ 1 , counter ] > HighestHi then HighestHi = CO[ 1 , counter ]; If CO[ 2 , counter ] < LowestLo then LowestLo = CO[ 2 , counter ]; End; { If the last N crosses occured in the last 50 bars, then place the buy and sell orders } Totalbars = BarNumber - CO[ 0 , NCOs - 1]; If TotalBars < NBars then Begin Buy at HighestHi + Average(TrueRange,4)*.5 stop; Sell at LowestLo - Average(TrueRange,4)*.5 stop; End; { Trailing stop orders } ExitLong next bar at Lowest( Low , TrailBar ) Stop; ExitShort next bar at Highest( High , TrailBar ) Stop;