{ TestMarketChange strategy This system is designed to test the function MarketChange, which compares the indicator averages between recent market data and the market as a whole. Mike Bryant Breakout Futures www.BreakoutFutures.com mrb@BreakoutFutures.com Copyright 2008 Breakout Futures } Input: NSample (180), { Number of bars of recent data to analyze } NStart (5000); { Start calculations this number bars from start } Var: NArray (0), { Number of elements in indicator arrays } AveSam (0), { sample average } NEndSamp (0), { Number of samples at end of data } Sum1 (0), { Running count for z values for indicator 1 } Sum2 (0), { Running count for z values for indicator 2 } Sum3 (0), { Running count for z values for indicator 3 } Sum4 (0), { Running count for z values for indicator 4 } Sum5 (0), { Running count for z values for indicator 5 } ii (0); { loop counter } Array: Ind1[10000](0), { Indicator 1 } Ind2[10000](0), { Indicator 2 } Ind3[10000](0), { Indicator 3 } Ind4[10000](0), { Indicator 4 } Ind5[10000](0), { Indicator 5 } zStat1[500](0), { z statistic for indicator 1 } zStat2[500](0), { z statistic for indicator 2 } zStat3[500](0), { z statistic for indicator 3 } zStat4[500](0), { z statistic for indicator 4 } zStat5[500](0); { z statistic for indicator 5 } { Store indicator values } Ind1[NArray] = Close - Average(Close, 30); Ind2[NArray] = Average(TrueRange, 30); Ind3[NArray] = SlowD(14); Ind4[NArray] = ADX(14); Ind5[NArray] = (Highest(H, 30) - Lowest(L, 30))/Average(TrueRange, 30); //Print(Ind1[NArray], ",", Ind2[NArray], ",", Ind3[NArray], ",", Ind4[NArray], ",", Ind5[NArray]); NArray = NArray + 1; { Calculate z values on most recent bar of chart } If BarNumber >= NStart then Begin if (BarNumber = NStart) then Print(Newline, "End-of-Data Samples..."); zStat1[NEndSamp] = MarketChange(Ind1, NArray, NSample, NArray - NSample); zStat2[NEndSamp] = MarketChange(Ind2, NArray, NSample, NArray - NSample); zStat3[NEndSamp] = MarketChange(Ind3, NArray, NSample, NArray - NSample); zStat4[NEndSamp] = MarketChange(Ind4, NArray, NSample, NArray - NSample); zStat5[NEndSamp] = MarketChange(Ind5, NArray, NSample, NArray - NSample); Print((NEndSamp + 1):0:0, ",", date:0:0, ",", zStat1[NEndSamp]:0:4, ",", zStat2[NEndSamp]:0:4, ",", zStat3[NEndSamp]:0:4, ",", zStat4[NEndSamp]:0:4, ",", zStat5[NEndSamp]:0:4); NEndSamp = NEndSamp + 1; End; If LastBarOnChart then Begin { Calculate number of recent samples that lie on population } For ii = 0 to NEndSamp - 1 Begin If AbsValue(zStat1[ii]) <= 1.96 then Sum1 = Sum1 + 1; If AbsValue(zStat2[ii]) <= 1.96 then Sum2 = Sum2 + 1; If AbsValue(zStat3[ii]) <= 1.96 then Sum3 = Sum3 + 1; If AbsValue(zStat4[ii]) <= 1.96 then Sum4 = Sum4 + 1; If AbsValue(zStat5[ii]) <= 1.96 then Sum5 = Sum5 + 1; End; If NEndSamp > 0 then Begin Sum1 = 100 * Sum1/NEndSamp; Sum2 = 100 * Sum2/NEndSamp; Sum3 = 100 * Sum3/NEndSamp; Sum4 = 100 * Sum4/NEndSamp; Sum5 = 100 * Sum5/NEndSamp; End; Print(Newline, "Percent of recent samples that are part of population (to 95% confidence):"); Print("Ind 1: ", Sum1:0:2, " Ind 2: ", Sum2:0:2, " Ind 3: ", Sum3:0:2, " Ind 4: ", Sum4:0:2, " Ind 5: ", Sum5:0:2); { Output raw data for population } {Print(Newline, "Raw population data at End-of-Chart..."); For ii = 0 to NArray - 1 Begin Print((ii + 1):0:0, ",", Ind3[ii]:0:4); End;} { Calculate random sample averages on last bar of chart } {Print(Newline, "Random Samples at End-of-Chart..."); For ii = 0 to NArray - NSample Begin AveSam = RndSampAve(Ind3, NArray, NSample); Print((ii + 1):0:0, ",", AveSam:0:4); End;} End; { MarketChange function Determine z statistic for change in input indicator value relative to market average. This functions compares the mean of the input indicator over NSample bars (sample average) to the average value over all bars (population average). The returned value (z statistic) can be used to determine if the sample average is significantly different than the population average. The index to the input array IndVal is assumed to vary from zero (first bar on chart) to NArray - 1 (last bar on chart). The sample is defined as the portion of IndVal starting from the index value given by iSample and NSample elements in length. Mike Bryant Breakout Futures www.BreakoutFutures.com mrb@BreakoutFutures.com Copyright 2008 Breakout Futures } Input: IndVal[MaxSize](NumericArrayRef), { Array of indicator values } NArray (NumericSimple), { Number of elements in IndVal } NSample (NumericSimple), { Number of bars in sample to analyze } iSample (NumericSimple); { Starting index in IndVal for sample } Var: NPop (0), { Size of population } AvePop (0), { Average of population } AveSam (0), { Average of sample } StdPop (0), { Standard deviation of population } SumInd (0), { sum of indicator values } SumInd2 (0), { sum of squared indicator values } zStat (0), { z statistic to return } ii (0); { loop counter } //NPop = NArray - NSample; NPop = NArray; If NSample > 1 and NPop > 1 then Begin { Calculate mean and standard deviation of population } SumInd = 0; SumInd2 = 0; For ii = 0 to NPop - 1 Begin SumInd = SumInd + IndVal[ii]; SumInd2 = SumInd2 + Square(IndVal[ii]); End; AvePop = SumInd/NPop; StdPop = SquareRoot((SumInd2 - NPop * Square(AvePop))/(NPop - 1)); { Calculate mean of sample } SumInd = 0; For ii = iSample to NSample + iSample - 1 Begin SumInd = SumInd + IndVal[ii]; End; AveSam = SumInd/NSample; // Print(NPop:0:0, ",", NSample:0:0, ",", AvePop:0:4, ",", StdPop:0:4, ",", AveSam:0:4); { Calculate z statistic } If StdPop > 0 then zStat = (AveSam - AvePop)/(StdPop/SquareRoot(NSample)); End; MarketChange = zStat;