From the June 01, 2010 issue of Futures Magazine • Subscribe!

Technology & trading: Volatility sizing codes

Codes for Murray Ruggiero's June 2010 Technology & Trading piece, "Money management: Understanding the game."

The below code sets the position size for each market based on each market’s relative size and volatility.

Sub TSPro_PercentDynamicMargin(Percent,Ceiling,RangeLB,DMarginMult)
Dim M As Integer
Dim S As Integer
Dim DollarsPerMarket
Dim StartAccount
Dim DollarsPerTrade
Dim DynMargin

TradePlan.Session(0).UnitSize = 1

‘For each session Loop though the trading plans.

For S = 0 To TradePlan.SessionCount - 1
DollarsPerMarket = (Tradeplan.SummEquity - tradeplan.OpenPandL) / (tradeplan.MarketCount)

‘Print TradePlan.Session(S).Name,” “,tradeplan.SummEquity,” “,Tradeplan.Session(S).MarketCount,” “,DollarsPerMarket

For M = 0 To TradePlan.Session(S).MarketCount - 1
DynMargin = DynamicMargin(TradePlan.Session(S).Market(M),RangeLB,DMarginMult)

If DollarsPerMarket > DynMargin Then
TradePlan.Session(S).Market(M).EntryNumUnits = Min(Floor((DollarsPerMarket*(Percent/100))/ DynMargin),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

Function DynamicMargin(mkt As TSProcessor.IMarket,LBPeriod,MARGINEST)
Dim Arr As Array
Dim SummVal
DIM I
Arr = mkt.DataArray(0, “TrueRange”)
SummVal = 0

For i = 0 To LBPeriod - 1
SummVal = Arr[i] + SummVal
Next

DynamicMargin = ((SummVal/LBPeriod)*mkt.BigPointValue)*MARGINEST
End Function

About the Author
Murray A. Ruggiero Jr.

Murray A. Ruggiero Jr. is the author of "Cybernetic Trading Strategies" (Wiley). E-mail him at ruggieroassoc@aol.com.

Comments
comments powered by Disqus