TITLE: Out of sample made easy EXPLAINER: Using the below macro, we can automate the out-of-sample system testing process. Sub SmartOpmitizeWithExcel(PercentOut) Dim FirstDate As Integer Dim LastDate As Integer Dim PeriodLenght As Integer Dim StartRunDate As Integer Dim EndRunDate As Integer Dim SessionName As String Dim runcount As Integer Dim Counter Dim Results Dim BestResults Dim BestKey Dim ParamKey Dim NP, DD Dim parmratings As Array ' Start a copy of Excel and add ResultTable to the worksheet XLStart(True) XLAddWorkSheet("ResultsTable") ' Load the current session into the DLL GetActiveSession() ' Get the name Of the current active session For later use SessionName = TrStGetSessionName() ' This Function gets the list Of all available dates For the session TrstGetCalculatedDates(FirstDate,LastDate) 'Set Date For in sample period PeriodLenght=LastDate-FirstDate StartRunDate=FirstDate EndRunDate=FirstDate+CInt(((100-PercentOut)/100)*PeriodLenght) TrStSetSessionRunLongDates(StartRunDate,EndRunDate,False) ' Copy the session back To the live one And optimize SetActiveSession() TrStOptimizeSession() ' Use the current session database data UseSession(SessionName) ' Find all Parameter keys a given session has been run with FindAllParameterKeysForSession() runcount=GetParameterKeyCount() ReDim(parmratings,runcount,2) BestResults=-99999999999 ' For each run get the stats And see what is best For Counter=0 To runcount - 1 ParamKey = GetParmStringForSession(Counter) FindSummResultsCombined(ParamKey) NP = GetSummResultsCombined("NetProfit") DD = GetSummResultsCombined("MAXDRAWDOWN") if Abs(DD)=0 Then Results=-99999999999 Else Results= NP/Abs(DD) End If parmratings[Counter,0]=ParamKey parmratings[Counter,1]=Results If Results>BestResults Then BestResults=Results BestKey=ParamKey End If Next 'OK now lets run out Of sample TrStSetAllSystemRunArguments(BestKey) TrStSetSessionRunLongDates(EndRunDate,LastDate,True) ' Run the session on the out Of sample period SetActiveSession() TrStRunSession() XLSetCellValue("ResultsTable",1,1,"ParmString") XLSetCellValue("ResultsTable",1,2,"Score") XLSetRangeValues("ResultsTable",2,1,runcount,2, parmratings) XLAutoFitColumn("ResultsTable","A") MsgBox("Check Excel, when finish press ok And excel will Close") XLClose() End Sub FILENAME: Code2.txt