Walking on a treadmill By Murray A. Ruggiero Jr. E-mail: ruggieroassoc@aol.com. When you start to tackle walk-forward analysis, you can reveal more questions than answers. Many of those questions are particularly important if you are automating the process, which is now possible with modern analysis software. In our 2005 series on walk-forward optimization in the print version of Futures (February, April and June) the code for the in-sample/out-of-sample testing was shown. This showed the basics of how to perform an optimization and then do an out-of-sample test, which is a large part of the macro. In this article, code fragments will be shown that deal with some of the new issues of walk-forward testing. This code includes both the TradersStudio macro and the Excel macro, which powers the analysis after the data table is created in Excel. Sub FutureArticleJune(TrainingWindowSize, SampleWindowSize) Œ We have not included Declare deleted to save space GetActiveSession() ' Get the name of the current active session for later use SessionName = TrStGetSessionName() NumWindows = getnumwalkforwardwindows(TrainingWindowSize,SampleWindowSize) ' Loop through each Of the windows SetActiveSession() OpenTrade = False xlstart(True) xlopenworkbook(getprogrampath()&"\walktemplate.xlt") For i = 0 To NumWindows - 1 getWalkForwardDates(TrainingWindowSize, i, StartTrainingDate,EndTrainingDate, SampleWindowSize, StartSampleDate, EndSampleDate) TrStSetSessionRunLongDates(StartTrainingDate,EndTrainingDate,False) ' Copy the session back to the live one and optimize TrStOptimizeSession() UseSession(SessionName) FindAllParameterKeysForSession() RunCount=GetParameterKeyCount() BestResults=-999999999 ' Use the current session database data For Counter=0 To RunCount - 1 ParamKey = GetParamStringForSession(Counter) FindSummResultsCombined(ParamKey) NP = GetSummResultsCombined("NetProfit") DD = GetSummResultsCombined("MAXDRAWDOWN") If Abs(DD) = 0 Then Results=0 Else Results= NP/Abs(DD) End If If Results>BestResults Then BestResults=Results BestKey=ParamKey End If Next TrStSetAllSystemRunArguments(BestKey) ' Double the length Of the out Of sample period RealStartSampleDate = StartSampleDate StartSampleDate = StartSampleDate - (EndSampleDate - StartSampleDate) TrStSetSessionRunLongDates(StartSampleDate,EndSampleDate,False) ' Run the session on the out Of sample period TrstRunSession() ' Get the trade by trades FindTradeByTradeAll(BestKey) ' Create a new worksheet with the name being Window#WINDOWNUM row=row+2 WriteWalkHeaders(Row,i,BestKey,RealStartSampleDate,EndSampleDate) n = SizeTradeByTradeAll() row =row+2 ' Loop through each Of the trades For Counter = 0 To n - 1 ' check If we have an Open trade from the previous window ' make sure we only record the trades in the real sample period If i=1 Then FirstTradeDate=GetAllTradeByTradeResults("EntryDate", Counter) Else FirstTradeDate=GetAllTradeByTradeResults("ExitDate", Counter) End If If FirstTradeDate >= RealStartSampleDate Then row = row + 1 Œ Write the TradeByTrade for each block WriteTBTWalk("WalkForwardTrades",row,Counter) EndIf Next ' Move on to the next window Next Œ Fix the width of all columns for display purposes XLAutoFitColumn("WalkForwardTrades","A") Œ Call repeated for each column XLAutoFitColumn("WalkForwardTrades","L") XLDisplayAlerts(False) XLRunMacro("WalkTemplate1!TradesAll.TradesAll") MsgBox ("We are done. Please examine the results and save them, when you are finished press OK") Xlsaveas(getprogrampath()&‰WalkTest.xls‰) xlclose() End Sub This macro starts by calculating the number of windows based upon our parameters. We loop through each window and set dates on which the optimization runs. The best set of parameters is run in an out-of-sample period, except this time the out-of-sample period starts at the end of the development period minus 200 bars and ends at the number of bars used in SampleWindowSize after the end of the development period. The results for each window are then written in Excel. This process is repeated for each window. You can see at the end of the TradersStudio macro that an Excel macro named "TradesAll()‰ is called. This is in the template that we are loading. This macro is stored in an Excel workbook and calls three different functions. Public Sub TradesAll() TradesFix CreateTradeByTradeSheet CreateSummaryReport End Sub As long as you can paste in trade-by-trade windows in the format exported, you can use this macro. The code for the Excel template to create these reports is available for free at www.TradersStudio.com. Murray A. Ruggiero Jr. is a consultant in East Haven, Conn. His firm, Ruggiero Associates develops market-timing systems. He is editor-in-chief of Inside Advantage Gold Club (www.iagoldclub.com) and is the author of Cybernetic Trading Strategies (John Wiley & Sons).