{ Prototype Ex 1 This system uses a neural network-like function to trigger entry. The "weights" of the network are determined by optimization within TradeStation. Mike Bryant Breakout Futures www.BreakoutFutures.com mrb@BreakoutFutures.com Copyright 2005 Breakout Futures } Inputs: w1 (0), { weights } w2 (0), w3 (0), w4 (0), w5 (0), w6 (0), w7 (0); Var: C1 (0), { Entry conditions } C2 (0), C3 (0), C4 (0), C5 (0), C6 (0), C7 (0), BuySig (false), SellSig (false); { Define entry conditions } C1 = C - C[1]; C2 = C - C[2]; C3 = C - C[5]; C4 = C - C[10]; C5 = C - Average(C, 5); C6 = C - Average(C, 25); C7 = C - Average(C, 45); { Define buy/sell signals } BuySig = w1 * C1 >= 0 and w2 * C2 >= 0 and w3 * C3 >= 0 and w4 * C4 >= 0 and w5 * C5 >= 0 and w6 * C6 >= 0 and w7 * C7 >= 0; SellSig = w1 * C1 <= 0 and w2 * C2 <= 0 and w3 * C3 <= 0 and w4 * C4 <= 0 and w5 * C5 <= 0 and w6 * C6 <= 0 and w7 * C7 <= 0; { Place trades based on buy/sell signals } If BuySig then Buy next bar at market; If SellSig then Sell short next bar at market; {Value2 = EqtyCorr3(w1, w2, w3, w4, w5, w6, w7, 0, 0, 0, .50, .95, 0, 160000, 10, 1, "C:\ProtoEx1.txt");} { Prototype Ex 2 This system uses a neural network-like function to trigger entry. The "weights" of the network are determined by optimization within TradeStation. Mike Bryant Breakout Futures www.BreakoutFutures.com mrb@BreakoutFutures.com Copyright 2005 Breakout Futures } Inputs: w1 (0), { weights } w2 (0), w3 (0), w4 (0), w5 (0), w6 (0), w7 (0); Var: C1 (0), { Entry conditions } C2 (0), C3 (0), C4 (0), C5 (0), C6 (0), C7 (0), BuySig (false), SellSig (false); { Define entry conditions } C1 = C - C[1]; C2 = C - C[2]; C3 = C - C[5]; C4 = C - C[10]; C5 = C - Average(C, 5); C6 = C - Average(C, 25); C7 = C - Average(C, 45); { Define buy/sell signals } BuySig = w1 * C1 >= 0 and w2 * C2 >= 0 and w3 * C3 >= 0 and w4 * C4 >= 0 and w5 * C5 >= 0 and w6 * C6 >= 0 and w7 * C7 >= 0; SellSig = w1 * C1 <= 0 and w2 * C2 <= 0 and w3 * C3 <= 0 and w4 * C4 <= 0 and w5 * C5 <= 0 and w6 * C6 <= 0 and w7 * C7 <= 0; { Place trades based on function output } If EntriesToday(date) < 2 and BuySig then Buy next bar at market; If EntriesToday(date) < 2 and SellSig then Sell short next bar at market; Value2 = EqtyCorr3(w1, w2, w3, w4, w5, w6, w7, 0, 0, 0, .50, .95, 0, 160000, 10, 1, "C:\ProtoEx2.txt"); { Prototype Ex 3 This system uses a neural network-like function to trigger entry. The "weights" of the network are determined by optimization within TradeStation. Mike Bryant Breakout Futures www.BreakoutFutures.com mrb@BreakoutFutures.com Copyright 2005 Breakout Futures } Inputs: w1 (0), { weights } w2 (0), w3 (0), w4 (0), w5 (0), w6 (0), w7 (0); Var: C1 (0), { Entry conditions } C2 (0), C3 (0), C4 (0), C5 (0), C6 (0), C7 (0), BuySig (false), SellSig (false); { Define entry conditions } C1 = C - C[1]; C2 = C - L[1]; C3 = C - H[1]; C4 = H - H[1]; C5 = L - L[1]; C6 = C - Average(C, 5); C7 = Average(C, 5) - Average(C, 25); { Define buy/sell signals } BuySig = w1 * C1 >= 0 and w2 * C2 >= 0 and w3 * C3 >= 0 and w4 * C4 >= 0 and w5 * C5 >= 0 and w6 * C6 >= 0 and w7 * C7 >= 0; SellSig = w1 * C1 <= 0 and w2 * C2 <= 0 and w3 * C3 <= 0 and w4 * C4 <= 0 and w5 * C5 <= 0 and w6 * C6 <= 0 and w7 * C7 <= 0; { Place trades based on function output } If BuySig then Buy next bar at market; If SellSig then Sell short next bar at market; If BarsSinceEntry = 2 then Begin Sell next bar at market; Buy to cover next bar at market; End; Value2 = EqtyCorr3(w1, w2, w3, w4, w5, w6, w7, 0, 0, 0, .50, .95, 0, 160000, 10, 1, "C:\ProtoEx3.txt"); { Function EqtyCorr3 Calculate an objective function based on the weighted sum of the correlation coefficient of the equity curve and the net profit. Append the objective function value and system input parameter values to a file. In the following, X represents the bar number, and Y is the total equity (closed trade net profit plus open position profit). Copyright 2004 Breakout Futures www.BreakoutFutures.com } input: Param1 (NumericSimple), { system parameter 1 } Param2 (NumericSimple), { system parameter 2 } Param3 (NumericSimple), { system parameter 3 } Param4 (NumericSimple), { system parameter 4 } Param5 (NumericSimple), { system parameter 5 } Param6 (NumericSimple), { system parameter 6 } Param7 (NumericSimple), { system parameter 7 } Param8 (NumericSimple), { system parameter 8 } Param9 (NumericSimple), { system parameter 9 } Param10 (NumericSimple), { system parameter 10 } CCMin (NumericSimple), { min value of coeff } CCMax (NumericSimple), { max value of coeff } EqMin (NumericSimple), { min net profit } EqMax (NumericSimple), { max net profit } WeightCC (NumericSimple), { weight for coeff } WeightEq (NumericSimple), { weight for net profit } FName (StringSimple); { file name to write results to } Var: XVal (0), { value of x, scaled bar number } YVal (0), { value of y, scaled equity } SumXY (0), { sum of X * Y } SumX (0), { sum of X } SumY (0), { sum of Y } SumXX (0), { sum of X * X } SumYY (0), { sum of Y * Y } CCNum (0), { numerator of correlation coefficient } CCDen (0), { denominator of correlation coefficient } CorrCoef (0), { correlation coefficient } ObjectFn (0), { correlation times net profit } TotalEqty (0), { open plus closed trade equity } TotProf (0), { total profit from weighted sum } PWNum (0), { numerator of profit weights } PWDen (0), { denominator of profit weights } PWFact (100), { factor determining profit weighting } ii (0), { loop counter } NBars (0), { number of bars on chart } StrOut (""); Array: EqtyCh[20100](0); { handles up to 15000 bars of data } TotalEqty = NetProfit + OpenPositionProfit; If BarNumber < 15000 then EqtyCh[BarNumber] = TotalEqty - TotalEqty[1] else Print("***EqtyCorr: ", BarNumber:0:0, " is too many bars."); XVal = BarNumber/100.; YVal = TotalEqty/10000.; SumX = SumX + XVal; SumY = SumY + YVal; SumXY = SumXY + (XVal * YVal); SumXX = SumXX + (XVal * XVal); SumYY = SumYY + (YVal * YVal); {Print("Bar: ", BarNumber:0:0, " SumX = ", SumX:0:0, " SumY = ", SumY:0:2, " SumXY = ", SumXY:0:2, " SumXX = ", SumXX:0:0, " SumYY = ", SumYY:0:2); } If LastBarOnchart then Begin NBars = BarNumber; { Calculate weighted net profit } for ii = 1 to NBars Begin PWDen = PWDen + (PWFact - 1)/(NBars - 1) * (ii - 1) + 1; End; PWDen = PWDen/NBars; for ii = 1 to NBars Begin PWNum = (PWFact - 1)/(NBars - 1) * (ii - 1) + 1; TotProf = TotProf + EqtyCh[ii] * PWNum/PWDen; End; { Calculate correlation coefficient } CCNum = NBars * SumXY - (SumX * SumY); CCDen = SquareRoot((NBars * SumXX - (SumX * SumX)) * (NBars * SumYY - (SumY * SumY))); if CCDen > 0 then CorrCoef = CCNum/CCDen else CorrCoef = 0; { Objective function is weighted sum of profit plus correlation } ObjectFn = WeightCC * (CorrCoef - CCMin)/(CCMax - CCMin) + WeightEq * (TotProf - EqMin)/(EqMax - EqMin); { write correlation coefficient to file along with system parameters } StrOut = NumtoStr(ObjectFn, 2) + ", " + NumtoStr(TotProf, 2) + ", " + NumtoStr(CorrCoef, 3) + ", " + NumtoStr(Param1, 3) + ", " + NumtoStr(Param2, 3) + ", " + NumtoStr(Param3, 3) + ", " + NumtoStr(Param4, 3) + ", " + NumtoStr(Param5, 3) + ", " + NumtoStr(Param6, 3) + ", " + NumtoStr(Param7, 3) + ", " + NumtoStr(Param8, 3) + ", " + NumtoStr(Param9, 3) + ", " + NumtoStr(Param10, 3) + Newline; FileAppend(FName, StrOut); End; EqtyCorr3 = CorrCoef;