Tuesday, January 06, 2009     | Register
TradersStudio Forums
Subject: limiting position

You are not authorized to post a reply.   
Author Messages
bhh
Posts:17

09-28-2008 12:19 PM Alert 

Does anyone have a tradeplan written that can properly limit positions when using percent risk position sizing?  The key things that really need to be implemented here are:

A) A selection criteria fed to the trade plan via a variable - highest volume, lowest RSI value, etc. 

B) A method for limiting the number of new positions opened in a single day based on the above selection criteria.  The entire portfolio gets looped and ranked based on that variable with only n positions allowed in a single trading day but only IF it does not exceed the amount of capital available.

C) A method for preventing any new positions to be opened if it exceeds the amount of capital available with no use of margin.

There are a few things in Trader's Studio that make this far more difficult to code currently than it should be considering it is a common need but someone must have something implemented?  Developers?

 

murray
Posts:435

09-29-2008 11:56 PM Alert 


'********************************
' Simple Channel Breakout System with Trade Risk
' TradersStudio(r) 2004-2007 , All rights reserved
Sub ChanBreakRisk(SLen)
Dim MinMove
MinMove=GetActiveMinMove()
Buy("ChanBuy",1,Highest(High,SLen,0)+MinMove ,STOP,DAY)
Sell("ChanSell",1,Lowest(Low,SLen,0)-MinMove,STOP,DAY)
' If you are flat then you don't know which way the trade will break
' If you are in a trade then risk is the next entry point -reversal point
' So for this system a good estimate of risk on the next trade if filled for this simple system
' is the size of the channel 
SetTradeRisk(Highest(High,SLen,0)-Lowest(Low,SLen,0))
end sub

TradePlan

Sub TS_PercentRiskPlan(Percent,Ceiling)
    Dim S As Integer
    Dim M As Integer
    Dim DollarPerTrade
    Dim StartAccount
    Dim objMark As TSProcessor.IMarket
    If tradeplan.MarketType=0 Then
    If Tradeplan.SummEquity        MsgBox "not enough money"
        StopRun
    End If

    If Tradeplan.SummEquity< Tradeplan.TotalMarginForPlan Then
        MsgBox "Margin Call Account below minimum margin required"
        StopRun
    End If
    End If
    DollarPerTrade= tradeplan.SummEquity*(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

bhh
Posts:17

09-30-2008 10:55 PM Alert 

Murray,

Thanks for your reply, however the code you posted does not address the problem.  Lets start at the beginning with the first issue.  

I am trading a portfolio of stocks.  On a day where I get multiple signals, I only want to take 2 signals (for example), the ones with the highest volume.  I want to reject the others.  I pass that to the tradeplan with:

MarketVar("MarketVolume")=Vol

Now the tradeplan needs to loops through the data and determine which 2 markets, that get signals, have the highest value for MarketVolume. That market should get the calculated EntryNumUnits whereas the others should get 0. 

What is important is that ALL markets are scanned for signals but only the 2 with the highest volume are allowed to execture.  This is fundamentally different than only allowing the the 2 with highest volume to possibly generate signals, which appears to be the way EQUITYSIZERISKWITHFILTERS works.

bhh
Posts:17

10-01-2008 8:02 PM Alert 
Still no response from tech support...

I am making progress on this by using "MyCustomPerformance" in conjunction with a variation of the TS_StockPlus(MaxOpenPositions) TradePlan that ships with TS2.5.

The problem is that is ranks first, then sets proper position sizing (takes the trade) only if the rank falls within the top nth percentile. What I need is for it to sort ONLY the trades that are generating a signal.

A possible workaround that I am persuing is to pass a variable from the system to the tradeplan using MarketVar("Signal") and then attempting to read that into the "MyCustomPerformance" to do the following:

If Tradeplan.Session(0).Market(count).MarketVar("Signal")=1 Then
CustomPer[count,1]=TradePlan.session(0).Market(count).data(0,"Vol",0)
Else
CustomPer[count,1]=0
End If

What that should do is rank/sort the actual signals higher than thus function how I'd like.
The problem however is that I can not get the variable passed from the Session to the "MyCustomPerformance" ranking. I have tried the above as well as building a bar array and trying to pass it using:

TradePlan.session(0).Market(count).data(0,"Signal",0)

also to no avail. This really should not be that dificult to do. This type of functionality is standard even on low-dollar programs/services like StockFetcher.
You are not authorized to post a reply.



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