{ StatBins1 This strategy groups indicator values, which are normalized to the range [-1, +1] into one of four statistical bins: [-1, -.5], [-.5, 0], [0, +.5], and [+.5, +1]. Each day, a simulated trade is placed, entering on the open and exiting on the close of the day. The indicator bin value on the bar prior to entering the simulated trade is recorded. On the last bar, the total profit/loss for each combination of bin values is determined, and the combination that generates the maximum total profit/loss is printed. The combination generating the largest negative total profit/loss, representing simulated short trades, is also printed. This strategy is intended to be run on intraday data with the bar time set to exchange time. The size of the BinI# arrays and the TradePL array must be set to at least the number of days of data. The steps to running the strategy are as follows: 1. Set the CalcScale input to true, and the TradeIt input to false. 2. In the Print Log, note the min and max values of the indicators, IMax1, Min = ..., etc. Copy these values to the corresponding system inputs, SfMax1, SfMin1, etc. This is necessary to properly scale the inputs. 3. Set the CalcScale input to false. TradeIt should still be false. 4. Record the bin results generated in the Print Log for both long and short trades. Copy these bin values to the inputs Bin1L, Bin2L, etc. (longs) and Bin1S, Bin2S, etc. (short trades). 5. Set the TradeIt input to true, and run the system. Note that this is not intended to be used as a standalone trading system. Rather, the results are best used as a starting point for additional research or system development or used in combination with other trade entry and exit techniques. Mike Bryant Breakout Futures www.BreakoutFutures.com mrb@BreakoutFutures.com Copyright 2006 Breakout Futures } Inputs: CalcScale(false), { Flag for calculating scale factors } TradeIt(true), { Flag for turning on/off trading system } Bin1L (2), { Bin for indicator 1, long trades } Bin2L (2), { Bin for indicator 2, long trades } Bin3L (1), { Bin for indicator 3, long trades } Bin4L (2), { Bin for indicator 4, long trades } Bin5L (0), { Bin for indicator 5, long trades } Bin1S (1), { Bin for indicator 1, short trades } Bin2S (2), { Bin for indicator 2, short trades } Bin3S (1), { Bin for indicator 3, short trades } Bin4S (1), { Bin for indicator 4, short trades } Bin5S (0), { Bin for indicator 5, short trades } SfMax1 (3.93), { Scaling factors } SfMin1 (-3.97), SfMax2 (5.17), SfMin2 (-5.7), SfMax3 (5.76), SfMin3 (-5.11), SfMax4 (5.97), SfMin4 (-5.98), SfMax5 (3.67), SfMin5 (-1); Var: ATR (0), { Average true range } AMA (0), { Kauffman adaptive moving average } I1r (0), { Raw (unscaled) inputs } I2r (0), I3r (0), I4r (0), I5r (0), I1 (0), { Scaled inputs } I2 (0), I3 (0), I4 (0), I5 (0), I1Max (0), { Max input values } I2Max (0), I3Max (0), I4Max (0), I5Max (0), I1Min (99999999), { Min input values } I2Min (99999999), I3Min (99999999), I4Min (99999999), I5Min (99999999), itrade (0), { Index of current trade } EnPrice (0), { Entry price of trades } ExPrice (0), { Exit price of trades } ii (0), { Loop counter } icombo (0), { Combination number } MaxCombo(0), { Max value of ComboPL } iMaxCombo(0), { Location of MaxCombo } MinCombo(9999), { Min value of ComboPL } iMinCombo(0), { Location of MinCombo } FracPart(0), { Fractional part of number } IntPart (0); { Integer part of number } Array: BinI1[1300](0), { Bin index for each trade for indicator 1 } BinI2[1300](0), { Bin index for each trade for indicator 2 } BinI3[1300](0), { Bin index for each trade for indicator 3 } BinI4[1300](0), { Bin index for each trade for indicator 4 } BinI5[1300](0), { Bin index for each trade for indicator 5 } TradePL[1300](0), { Trade profit/losses } ComboPL[1024](0), { Total profit/losses for each indicator combo } ComboNT[1024](0), { Number of trades in each indicator combination } InvCombo[5](0); { Bin numbers for a given combination } { Define inputs, scaled } ATR = Average(TrueRange, 30); AMA = AdaptiveMovAvg(C, 20, 2, 40); I1r = (C - C[1])/ATR; I2r = (C - C[3])/ATR; I3r = (C - AMA)/ATR; I4r = (AMA - Average(C, 30))/ATR; I5r = (TrueRange - ATR)/ATR; If CalcScale then Begin I1 = I1r; I2 = I2r; I3 = I3r; I4 = I4r; I5 = I5r; end else Begin I1 = (2 * I1r - (SfMax1 + SfMin1))/(SfMax1 - SfMin1); I2 = (2 * I2r - (SfMax2 + SfMin2))/(SfMax2 - SfMin2); I3 = (2 * I3r - (SfMax3 + SfMin3))/(SfMax3 - SfMin3); I4 = (2 * I4r - (SfMax4 + SfMin4))/(SfMax4 - SfMin4); I5 = (2 * I5r - (SfMax5 + SfMin5))/(SfMax5 - SfMin5); end; { track min and max input values } If CalcScale then Begin I1Max = MaxList(I1, I1Max); I2Max = MaxList(I2, I2Max); I3Max = MaxList(I3, I3Max); I4Max = MaxList(I4, I4Max); I5Max = MaxList(I5, I5Max); I1Min = MinList(I1, I1Min); I2Min = MinList(I2, I2Min); I3Min = MinList(I3, I3Min); I4Min = MinList(I4, I4Min); I5Min = MinList(I5, I5Min); If LastBarOnChart then Begin print("I1Max, Min = ", I1Max, I1Min); print("I2Max, Min = ", I2Max, I2Min); print("I3Max, Min = ", I3Max, I3Min); print("I4Max, Min = ", I4Max, I4Min); print("I5Max, Min = ", I5Max, I5Min); End; End; { Place trades: Enter on close of first bar of day; exit on close of day } If TradeIt and time = SessionEndtime(0, 1) then Begin BinI1[itrade] = MinList(4, MaxList(Ceiling(2*I1 + 2), 1)) - 1; BinI2[itrade] = MinList(4, MaxList(Ceiling(2*I2 + 2), 1)) - 1; BinI3[itrade] = MinList(4, MaxList(Ceiling(2*I3 + 2), 1)) - 1; BinI4[itrade] = MinList(4, MaxList(Ceiling(2*I4 + 2), 1)) - 1; BinI5[itrade] = MinList(4, MaxList(Ceiling(2*I5 + 2), 1)) - 1; If BinI1[0] = Bin1L and BinI2[0] = Bin2L and BinI3[0] = Bin3L and BinI4[0] = Bin4L and BinI5[0] = Bin5L then Buy next bar at market; If BinI1[0] = Bin1S and BinI2[0] = Bin2S and BinI3[0] = Bin3S and BinI4[0] = Bin4S and BinI5[0] = Bin5S then Sell short next bar at market; End; SetExitOnClose; { Initialize bins and entry price of first simulated trade } If BarNumber = 1 and CalcScale = FALSE and TradeIt = FALSE then Begin BinI1[itrade] = MinList(4, MaxList(Ceiling(2*I1 + 2), 1)) - 1; BinI2[itrade] = MinList(4, MaxList(Ceiling(2*I2 + 2), 1)) - 1; BinI3[itrade] = MinList(4, MaxList(Ceiling(2*I3 + 2), 1)) - 1; BinI4[itrade] = MinList(4, MaxList(Ceiling(2*I4 + 2), 1)) - 1; BinI5[itrade] = MinList(4, MaxList(Ceiling(2*I5 + 2), 1)) - 1; End; If BarNumber = 2 and CalcScale = FALSE and TradeIt = FALSE then EnPrice = Open; { Simulated trade enters at day's open } { Record simulated entry price at day's open } If Date <> Date[1] and BarNumber > 1 and CalcScale = FALSE and TradeIt = FALSE then EnPrice = Open; { On the last bar of day, record simulated trade results and bin values } If time = SessionEndtime(0, 1) and BarNumber > 1 and CalcScale = FALSE and TradeIt = FALSE then Begin { Calculate and record trade profit from today } ExPrice = Close; { Trade exits at day's close } TradePL[itrade] = (ExPrice - EnPrice) * BigPointValue; itrade = itrade + 1; { Record bin values for each indicator } BinI1[itrade] = MinList(4, MaxList(Ceiling(2*I1 + 2), 1)) - 1; BinI2[itrade] = MinList(4, MaxList(Ceiling(2*I2 + 2), 1)) - 1; BinI3[itrade] = MinList(4, MaxList(Ceiling(2*I3 + 2), 1)) - 1; BinI4[itrade] = MinList(4, MaxList(Ceiling(2*I4 + 2), 1)) - 1; BinI5[itrade] = MinList(4, MaxList(Ceiling(2*I5 + 2), 1)) - 1; End; { Process results on last bar of chart } If LastBarOnChart and CalcScale = FALSE and TradeIt = FALSE then Begin { Loop over trades and add up results for each combination } For ii = 0 to itrade - 1 Begin icombo = BinI1[ii] + BinI2[ii] * 4 + BinI3[ii] * 16 + BinI4[ii] * 64 + BinI5[ii] * 256; ComboPL[icombo] = ComboPL[icombo] + TradePL[ii]; ComboNT[icombo] = ComboNT[icombo] + 1; End; { Find min and max values of total profit/loss for combinations } Print(" "); Print("StatBins1..."); Print(" Total Number of Simulated Trades = ", itrade:3:0); Print(" Combo Total Long P/L No. Trades"); For icombo = 0 to 1023 Begin If ComboNT[icombo] > 1 then Print(" ", (icombo + 1):0:0, " ", ComboPL[icombo]:0:2, " ", ComboNT[icombo]:0:0); If ComboPL[icombo] > MaxCombo then Begin MaxCombo = ComboPL[icombo]; iMaxCombo = icombo; End; If ComboPL[icombo] < MinCombo then Begin MinCombo = ComboPL[icombo]; iMinCombo = icombo; End; End; { Write out min and max combination values } Print(" "); Print(" Bins (0 - 3): [-1, -.5] (-.5, 0] (0, .5] (.5, 1]"); Print(" Maximum Profit/Loss, Long: ", MaxCombo); IntPart = iMaxCombo; For ii = 0 to 4 Begin FracPart = FracPortion(IntPart/4.); InvCombo[ii] = FracPart * 4; IntPart = IntPortion(IntPart/4.); End; Print(" Bins: ", InvCombo[0]:3:0, InvCombo[1]:3:0, InvCombo[2]:3:0, InvCombo[3]:3:0, InvCombo[4]:3:0); Print(" Number of trades: ", ComboNT[iMaxCombo]:0:0); Print(" "); Print(" Maximum Profit/Loss, Short: ", AbsValue(MinCombo)); IntPart = iMinCombo; For ii = 0 to 4 Begin FracPart = FracPortion(IntPart/4.); InvCombo[ii] = FracPart * 4; IntPart = IntPortion(IntPart/4.); End; Print(" Bins: ", InvCombo[0]:3:0, InvCombo[1]:3:0, InvCombo[2]:3:0, InvCombo[3]:3:0, InvCombo[4]:3:0); Print(" Number of trades: ", ComboNT[iMinCombo]:0:0); End;