TradersStudio®

  • Home
  • Store
  • Products
    • TradersStudio®® Turbo 800% faster
    • TradersStudio®® Turbo Upgrade
    • TradersStudio®® Professional
    • Trend Harmony
  • Free Demo
  • Why TradersStudio®
  • Blog
  • Tutorials
  • Traders Resources
    • Equity Curve Feedback
    • Stock and ETF Trading Systems
    • Walk Forward Testing in TradersStudio®®
  • Contact Us

Optimizing your trend following system with Money Management

January 18, 2015 by

The best set of parameters on a one lot of each market for a trend following portfolio system is often not the best set of parameters when it comes to trading a balanced risk portfolio, for example your are trading one Natural gas and 5 corn because that give you the same dollar risk based on volatility. Doing this analysis is almost impossible in other backtesting and trading software but it’s very easy in TradersStudio. TradersStudio understands that when trading real money it’s important to optimize your trend following system with your money management rules included.

Let’s first start with a triple moving average crossover system

‘********************************

‘ Simple three moving average crossover system

‘ TradersStudio(r) 2004-2015 , All rights reserved

Sub ThreeMACrossover(SLen As Integer,MLen As Integer,LLen As Integer)

Dim ShortAve As BarArray

Dim LongAve As BarArray

Dim MedAve As BarArray

ShortAve = Average(Close, SLen,0)

MedAve=Average(Close,MLen,0)

LongAve = Average(Close, LLen,0)

If ShortAve > MedAve And MedAve>LongAve Then

Buy(“BuyEnt”,1,0,Market,Day)

End If

If ShortAve < MedAve And MedAve<LongAve Then

Sell(“SellEnt”,1,0,Market,Day)

End If

End Sub

This is our normal system which we would optimize parameters on a one lot basis at the session level. We can make a simple change then be able to optimize at the risk adjusted money management level.

‘********************************

‘ Simple three moving average crossover system optimize at tradeplan level

‘ TradersStudio(r) 2004-2015 , All rights reserved

Sub ThreeMACrossoverTP_Opt()

Dim ShortAve As BarArray

Dim LongAve As BarArray

Dim MedAve As BarArray

Dim SLen ,MLen ,LLen

SLen=thissession.SessionVar(“SLen”)

MLen=thissession.SessionVar(“MLen”)

LLen=thissession.SessionVar(“LLen”)

ShortAve = Average(Close, SLen,0)

MedAve=Average(Close,MLen,0)

LongAve = Average(Close, LLen,0)

If ShortAve > MedAve And MedAve>LongAve Then

Buy(“BuyEnt”,1,0,Market,Day)

End If

If ShortAve < MedAve And MedAve<LongAve Then

Sell(“SellEnt”,1,0,Market,Day)

End If

End Sub

You can see the this session. SessionVar calls , these retrieve the parameters from the trade plan. Let’s look at the trade plan below. It will use my dynamic margin calculation to do the sizing.

‘ TradersStudio(r) (c) 2006-2015 all rights reserved

Sub DynMarginPlan_TPOptim(Percent,SLen,MLen,LLen)

Dim M As Integer

Dim S As Integer

Dim DollarsPerMarket

Dim StartAccount

Dim DollarsPerTrade

Dim Ceiling

Dim DynMargin

Dim ActiveCount

Dim Curdate

Ceiling=1000

TradePlan.Session(0).UnitSize = 1

DollarsPerMarket=Tradeplan.SummEquity/TradePlan.MarketCount

‘ Take parameters from tradeplan and pass to session variable for session to use.

TradePlan.Session(0).SessionVar(“SLen”)=SLen

TradePlan.Session(0).SessionVar(“MLen”)=MLen

TradePlan.Session(0).SessionVar(“LLen”)=LLen

For M = 0 To TradePlan.Session(0).MarketCount – 1

DynMargin=DynamicMargin(TradePlan.Session(0).Market(M),40,7)

If DollarsPerMarket>DynMargin Then

If (DollarsPerMarket*Percent/100)/ DynMargin>=1 Then

TradePlan.Session(0).Market(M).EntryNumUnits =Min(Floor((DollarsPerMarket*Percent/100)/ DynMargin),Ceiling)

Else

If (DollarsPerMarket*Percent/100)/ DynMargin>.7 Then TradePlan.Session(0).Market(M).EntryNumUnits=1

End If

Else

TradePlan.Session(0).Market(M).EntryNumUnits=0

End If

TradePlan.Session(0).Market(M).ExitNumUnits=TradePlan.Session(0).Market(M).NumContractsHeld

ActiveCount=tradeplan.Session(0).Market(M).ActiveOrderCount

Next

End Sub

You can see the trade plan takes the parameters used by the system at the session level and passes them though the trade plan interface though Session variables to the system. We also have variable we can use at the market by market level.

Let’s walk though this we will first create a session TripleMAOptimize Plan. We will pick the following markets CT,FN,JN,ZN. We will run from 1/3/1991 to 1/9/2015. The session will not product any trades on it’s own because without the tradeplan to feed it all the parameters are 0. We will use 50.00 for slippage and commission. Next we need to create a tradeplan. We will use DynMarginPlan_TPOptim and change maxbars back at the tradeplan level to 200. We will make account size $1,000,000 and we will optimize the tradeplan as follows:

Optimize Trend Screen 1
Click to Enlarge This Screenshot

 

In Turbo, we will run these tradeplan in parallel. This will give us 567 combinations to test and on my six core Intel based computer we are running 12 trials at a time. We will see our results in the optimization grid and then be able to sort our optimize using the sort button using many different factors such as MAR, which is compound annual growth rate/maximum drawdown. The default sort is by net profit.

Optimize Trend Screen 2
Click to Enlarge This Screenshot

We can now use the sort box and sort by MAR, which is compound annual growth rate divided by maximum drawdown.

Optimize Trend Screen 3
Click to Enlarge This Screenshot

We see above the results sorted by MAR. Let’s select the top set of parameters and see that .

Optimize Trend Screen 5
Click to Enlarge This Screenshot

You can see that max contracts held is 37, that is because we now optimized using position sizing based on our Dynamic margin which is an ATR based sizing.

Optimize Trend Screen 6
Click to Enlarge This Screenshot

We can see the compound Annual Growth rate and Percent drawdown on the Equity Report. This show how we can optimize a system based on the best trade/risk management properties and not just at the session level using this trick.

 

HYPOTHETICAL PERFORMANCE RESULTS HAVE MANY INHERENT LIMITATIONS, SOME OF WHICH ARE DESCRIBED BELOW. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFITS OR LOSSES SIMILAR TO THOSE SHOWN. IN FACT, THERE ARE FREQUENTLY SHARP DIFFERENCES BETWEEN HYPOTHETICAL PERFORMANCE RESULTS AND THE ACTUAL RESULTS SUBSEQUENTLY ACHIEVED BY ANY PARTICULAR TRADING PROGRAM.

ONE OF THE LIMITATIONS OF HYPOTHETICAL PERFORMANCE RESULTS IS THAT THEY ARE GENERALLY PREPARED WITH THE BENEFIT OF HINDSIGHT. IN ADDITION, HYPOTHETICAL TRADING DOES NOT INVOLVE FINANCIAL RISK, AND NO HYPOTHETICAL TRADING RECORD CAN COMPLETELY ACCOUNT FOR THE IMPACT OF FINANCIAL RISK IN ACTUAL TRADING. FOR EXAMPLE, THE ABILITY TO WITHSTAND LOSSES OR TO ADHERE TO A PARTICULAR TRADING PROGRAM IN SPITE OF TRADING LOSSES ARE MATERIAL POINTS WHICH CAN ALSO ADVERSELY AFFECT ACTUAL TRADING RESULTS. THERE ARE NUMEROUS OTHER FACTORS RELATED TO THE MARKETS IN GENERAL OR TO THE IMPLEMENTATION OF ANY SPECIFIC TRADING PROGRAM WHICH CANNOT BE FULLY ACCOUNTED FOR IN THE PREPARATION OF HYPOTHETICAL PERFORMANCE RESULTS AND ALL OF WHICH CAN ADVERSELY AFFECT ACTUAL TRADING RESULTS. canada goose online shop canada goose online shop

Trade Like The Pros

Did you find this tutorial interesting? These tutorials require TradersStudio to run.

TradersStudio Bundle
TradersStudio Bundle: Turbo + Genetic Optimizer



TradersStudio Bundle
CSI Data


Download the Demo

Interested in trying TradersStudio? Please download our demo and take TradersStudio out for a 30-day test drive!

Site Menu

  • Home
  • Store
  • Products
    • TradersStudio®® Turbo 800% faster
    • TradersStudio®® Turbo Upgrade
    • TradersStudio®® Professional
    • Trend Harmony
  • Free Demo
  • Why TradersStudio®
  • Blog
  • Tutorials
  • Traders Resources
    • Equity Curve Feedback
    • Stock and ETF Trading Systems
    • Walk Forward Testing in TradersStudio®®
  • Contact Us

Copyright © 2014-2015 TradersStudio, Inc. All rights reserved. TradersStudio® is a registered trademark of TradersStudio, Inc.

No portion of this site may be copied without the express permission of the author.