Register Login
Forums    February 9, 2012
TradersStudio Forums
Custom optimization criteria
Last Post 04-06-2008 12:32 PM by Brandon Hicks. 5 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Brandon Hicks
New Member
New Member
Posts:16

--
03-27-2008 11:00 PM

    I am trying to access the following items in an optimization run; Avg. Trade, Avg Loss, and Average # Bars in Winners.  I received the following from tech support:

    Tech support recommended the use of custom optimization criteria but did not elaborate.  Unfortunatly, this is currently beyond my level of expertise with TS.  Would it be possible to point me to a specific section of the documentation or provide a piece of sample code on how to do this?  Thank you.

     

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    03-28-2008 12:00 AM

    This is how to use a custom optimize creteria. ' TradersStudio(r) (c) 2005-2007
    ' Sets optimize factor for custom optimize as Optimal f for a session.
    ' System is channel breakout
    Sub OptimizeFactorExample(SLen)
        Dim MinMove
        Dim Hi, Lo
        Dim OFactor As Double

        MinMove=GetActiveMinMove()
        Hi = Highest(High,SLen,0)+MinMove
        Lo = Lowest(Low,SLen,0)-MinMove

        Buy("ChanBuy", 1, Hi ,Stop, Day)
        Sell("ChanSell", 1, Lo , Stop, Day)
       
        OFactor = CalcOptimalf_Sess(0.05, 20)
        SetOptimizeFactor(OFactor)
    End Sub

    Here how to access what you need. What not documented is you can access all this from a system using the following

     

    Thismarket.Property.

    You now can access all of the stats as you move forward. If you want to do at end of run then do it on the last bar.

     

    ISummary -- Object

    The ISummary object presents results of the Market, Session or TradePlan.  You can use IMarket.Summary, ISession.Summary and ITradePlan.Summary properties to get summary object.

    ISummary has the following properties:

    Property Type Description
    Slippage Double
    Commissions Double
    StartDate Integer
    EndDate Integer
    NetProfit Double
    GrossProfit Double
    GrossLoss Double
    NoTrades Integer
    PctProfit Double
    Wins Integer
    Losses Integer
    LargestWin Double
    LargestLoss Double
    AvgWin Double
    AvgLoss Double
    AvgWinToAvgLoss Double
    AvgTrade Double
    MaxConWin Integer
    MaxConLoss Integer
    AvgWinStreak Double
    AvgLossStreak Double
    MaxDrawDown Double
    ProfitFactor Double
    OpenPosPL Double
    WinBars Double
    LossBars Double
    LNetProfit Double
    LGrossProfit Double
    LGrossLoss Double
    LNoTrades Integer
    LPctProfit Double
    LWins Integer
    LLosses Ingeger
    LLargestLoss Double
    LLargestWin Double
    LAvgWin Double
    LAvgLoss Double
    LAvgWinToAvgLoss Double
    LAvgTrade Double
    LMaxConWin Integer
    LmaxConLoss Integer
    LAvgWinStreak Double
    LAvgLossStreak Double
    LMaxDrawDown Double
    LProfitFactor Double
    LOpenPosPL Double
    LWinBars Double
    LLossBars Double
    SNetProfit Double
    SGrossProfit Double
    SGrossLoss Double
    SNoTrades Integer
    SPctProfit Double
    SWins Double
    SLosses Double
    SLargestWin Double
    SLargestLoss Double
    SAvgWin Double
    SAvgLoss Double
    SAvgWinToAvgLoss Double
    SAvgTrade Double
    SMaxConWin Integer
    SMaxConLoss Integer
    SAvgWinStreak Double
    SAvgLossStreak Double
    SMaxDrawDown Double
    SProfitFactor Double
    SOpenPosPL Double
    SWinBars Double
    SLossBars Double
    MaxContractsHeld Integer
    LMaxContractsHeld Integer
    SMaxContractsHeld Integer

     

    Brandon Hicks
    New Member
    New Member
    Posts:16

    --
    03-28-2008 08:53 AM
    Thank you!
    Brandon Hicks
    New Member
    New Member
    Posts:16

    --
    03-29-2008 08:53 PM
    ok, this helped a lot. thank you and I am very close. I have decided to output the additional info I am looking for as a custom report rather than an optimize factor. I have attempted to increment the CellRow as a Gvalue+1 increment but this seems to reset for each optimization run as the first row is overwritten with the results of the last optimization run. Is there a way to increment cell row in a way that will be mainained across the different variable optimization runs? Is the optimize "Run Order" stored as a system variable that could be used to feed the CellRow?
    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    03-30-2008 11:24 PM
    I am not sure if there is a way to do this from a standard custom report. You could use the Excel interface and create the report in excel and have the last row as a cell in the spreadsheet you could read. We have complete OLE interface to excel.
    Brandon Hicks
    New Member
    New Member
    Posts:16

    --
    04-06-2008 12:32 PM

    I wanted to follow up with the solution to this question for anyone else attempting to do this.  The following code writes a custom report at the end of an optimization run that will give you additional information not presented in the main optimization results.  This code uses two variables and pulls them directly from the system parameters.

    Sub System_Example(Var1,Var2)

    The other thing I realized is that it slows things down a lot when this additional info is calcualted so the following code only calculates this info after the last bar of the last market of each variable run. This can be pasted in at the very end of a system. 

    'CUSTOM OPTIMZAION REPORT

    'Calculate and Store Data
    Dim objNoTrades As Integer
    Dim objWins As Integer
    Dim objGrossProfit As Double
    Dim objGrossLoss As Double
    Dim objMaxDD As Double
    Dim objWinBars As Integer
    Dim AvgWins As Double

    If BarNumber=LastBar Then
       GValue1=Gvalue1+1
       If Gvalue1=thisSession.MarketCount Then
          objNoTrades = thisSession.Summary.NoTrades
          objWins = thisSession.Summary.Wins
          objGrossProfit = thisSession.Summary.GrossProfit
          objGrossLoss = thisSession.Summary.GrossLoss
          objMaxDD = thisSession.Summary.MaxDrawDown
          objWinBars = thisSession.Summary.WinBars

          If objWins > 0 Then 
             AvgWins = objWinBars/objWins
          Else 
             AvgWins = 0
          End If
           
        'Write Custom Report
            Dim CellRow As Integer
            Dim OptimizeCount As TSProcessor.ISession
            OptimizeCount=thisSession.OptimizeCount
            CellRow=OptimizeCount+2
      
            SetTextValue("Variable 1",1,1,10)
            SetTextValue("Variable 2",1,2,10)
            SetTextValue("#Trades",1,3,10)
            SetTextValue("#Wins",1,4,10)
            SetTextValue("GrossProfit",1,5,10)
            SetTextValue("GrossLoss",1,6,10)
            SetTextValue("MaxDD",1,7,10)
            SetTextValue("WinDays",1,8,10)

            SetTextValue(Var1,CellRow,1,10)
            SetTextValue(Var2,CellRow,2,10)
            SetTextValue(objNoTrades,CellRow,3,10)
            SetTextValue(objWins,CellRow,4,10)
            SetTextValue(objGrossProfit,CellRow,5,10)
            SetTextValue(objGrossLoss,CellRow,6,10)
            SetTextValue(objMaxDD,CellRow,7,10)
            SetTextValue(AvgWins,CellRow,8,10)
            Gvalue1=0
        End If
    End If

    You are not authorized to post a reply.


     TradersStudio, Inc. ® Copyright 2004-2012 All Rights Reserved   Terms Of Use  Privacy Statement