Monday, December 01, 2008     | Register
TradersStudio Forums
Subject: Adjust Account in Trade Plan

You are not authorized to post a reply.   
Author Messages
mac12
Posts:10

07-10-2008 11:20 AM Alert 

Hi Dear

I use the standard TradingPlan "TS_PercentRiskPlan(Percent,Ceiling)". Now I like to add or deduct some amount (new Investors give money/old investors to deduct money) on a daily or monthly basis in the trading account. Knows somebody how I can implement this following: "TradePlanObject.AdjustAccount(Value)" in the existing TradingPlan? I need this feature for calculation the new position size for the next trading session. Or having somebody a good idea?

Kind regards for support.

Markus

murray
Posts:431

07-10-2008 11:10 PM Alert 

' Percent Margin Plan with Taxes , assumes a 30% tax rate as a estimate.
' Shows how to adjust accounts from a trade plan to add or subtract money from it.
' TradersStudio(r) (c) All rights reserved 2005-2007

Sub PerMargPlanWithTaxes(Percent,Ceiling)
    Dim S As Integer
    Dim M As Integer
    Dim DollarPerTrade
    Dim NumberOfMarkets
    Dim DollarsPerMarket
    Dim StartAccount
    Dim prevDateTime As BarArray
    Dim adj 
    Dim SumDeduct As BarArray
    Dim pl
    Dim objS As TSProcessor.ISession
    Dim objM As TSProcessor.IMarket
  
    ' adjust account on first day of the year
   
    If prevDateTime <> 0 And Year(CurDateTime) <> Year(prevDateTime) Then
        pl = LastYearPL
        If pl > 0 Then
            adj = -LastYearPL * 0.3
        Else
            adj = 0
        End If
        TradePlan.AdjustAccount(adj)
        Print "Adjustment: ", CurDateTime, " = ", adj
        SumDeduct=SumDeduct+adj
          Print "Adjustment: ", CurDateTime, " = ", adj,"  ",SumDeduct
       End If

    prevDateTime = CurDateTime
    
      If tradeplan.MarketType<>0 Then
    MsgBox("This trade plan can only be run on a Commodities,Futures")
    StopRun
    End If
     If Tradeplan.SummEquity+ SumDeduct       MsgBox "not enough money"
      StopRun
      End If
     If Tradeplan.SummEquity+ SumDeduct < Tradeplan.TotalMarginForPlan Then
     MsgBox "Margin Call Account below minimum margin required"
     StopRun
     End If
     
    NumberOfMarkets=TradePlan.MarketCount
    DollarsPerMarket=(tradeplan.SummEquity+ SumDeduct)/NumberOfMarkets
   ' Loop though all the sessions
      For S = 0 To TradePlan.SessionCount - 1
        TradePlan.Session(S).UnitSize = 1
      ' For each session Loop though the trading plans.
        For M = 0 To TradePlan.Session(S).MarketCount - 1
        If DollarsPerMarket>TradePlan.Session(S).Market(M).Margin Then
        TradePlan.Session(S).Market(M).EntryNumUnits =Min(Floor((DollarsPerMarket*Percent/100)/ TradePlan.Session(S).Market(M).Margin),Ceiling)
          Else
        TradePlan.Session(S).Market(M).EntryNumUnits=0
        End If
            TradePlan.Session(S).Market(M).ExitNumUnits=TradePlan.Session(S).Market(M).NumContractsHeld
        Next
        Next

End Sub

mac12
Posts:10

07-11-2008 5:21 AM Alert 

Thank you Murray

I try it and will see, that I can adjust it to my needs.

Kind regards

Markus

mac12
Posts:10

07-15-2008 11:50 AM Alert 

Murray

I taken the Trade Plan model I found in TS and tried to modified for my needs but it have no influence on the TradePlan.SummEquity and the order volume for new position size.

See the copy and please tell me what I made wrong for having learning effect.

Thank you very much and kind regrads

Markus

Sub Adjust_Muster_Flagship(Percent,Ceiling,Subscription,Redemption)
    Dim S As Integer
    Dim M As Integer
    Dim DollarPerTrade
    Dim StartAccount
    Dim objMark As TSProcessor.IMarket
    Dim adj
    Dim MoneyIn
    Dim MoneyOut
      
'adjust account on days that Subscriptions/Redemptions come in.
'with this adjustments we can calculate new position size for new orders.

If CurDateTime = LastDateTime Then
MoneyIn=Subscription
MoneyOut=0-Redemption
If MoneyIn > 0 Then
adj = Sum(MoneyIn,MoneyOut)
Else
adj = 0
If MoneyOut < 0 Then
adj = Sum(MoneyIn,MoneyOut)
Else
adj = 0
End If
End If
TradePlan.AdjustAccount(adj)
Print "Subscribtion:   ", CurDateTime, " = ", MoneyIn
Print "Redemption:     ", CurDateTime, " = ", MoneyOut
Print "Adjustment:     ", CurDateTime, " = ", adj
Print "NewTotalEquity: ", CurDateTime, " = ", tradeplan.SummEquity
End If


    If tradeplan.MarketType=0 Then
    If Tradeplan.SummEquity+adj        MsgBox "not enough money"
        StopRun
    End If

    If Tradeplan.SummEquity+adj< Tradeplan.TotalMarginForPlan Then
        MsgBox "Margin Call Account below minimum margin required"
        StopRun
    End If
    End If
    DollarPerTrade=(tradeplan.SummEquity+adj)*(Percent/100)

    For S = 0 To TradePlan.SessionCount - 1
        TradePlan.Session(S).UnitSize = 1

        For M = 0 To TradePlan.Session(S).MarketCount - 1
            objMark = TradePlan.Session(S).Market(M)

            If objMark.TradeRiskSet Then
           

                If objMark.TradeRisk <> 0 Then
                    objMark.EntryNumUnits =Min(Floor(DollarPerTrade/objMark.TradeRisk),Ceiling)
                Else
                    objMark.EntryNumUnits=0
                End If

                objMark.ExitNumUnits = objMark.NumContractsHeld
            Else
                objMark.NumUnits = -1 ' use default
            End If
        Next
    Next
End Sub

murray
Posts:431

07-15-2008 2:38 PM Alert 

It does not effect SummEquity only money out , which can be used as a effect for sizing. This means you need to create custom reports to get performance numbers. 

 

  We might deal with this in upcoming version of TradersStudio to have it adjust SummEquity number.

You are not authorized to post a reply.



ActiveForums 3.6
TradersStudio® Copyright 2004-2008 All Rights Reserved   |  Privacy Statement  |  Terms Of Use