Van Tharp's Max Expectancy (Page 4) - Psychology and Money Management | futures trading

Go Back

> Futures Trading, News, Charts and Platforms > Psychology and Money Management

Van Tharp's Max Expectancy
Started:July 26th, 2009 (02:13 AM) by caprica Views / Replies:14,762 / 31
Last Reply:January 22nd, 2015 (11:55 AM) Attachments:1

Welcome to

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Thread Tools Search this Thread

Van Tharp's Max Expectancy

Old February 20th, 2014, 02:21 PM   #31 (permalink)
Patient Discipline
Bellingham, WA USA
Futures Experience: Beginner
Platform: NT
Broker/Data: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Favorite Futures: Futures
aventeren's Avatar
Posts: 202 since Mar 2013
Thanks: 426 given, 190 received

gordo View Post
I wrote two optimization types (that work in NT 7 quite nicely) based on the information from this thread and Van Tharp's book. Here are the links:

Expectancy Score (which includes expectancy X opportunity), and

Expectancy (which does not include opportunity).

I use the Expectancy optimization all the time and find it gives me great direction when I am optimizing my stategies.



Thanks for coding the Expectancy Score optimizer.

I'm currently exploring the use of a few optimizers, and I have taken a look at the rationale behind the Expectancy Score, which appears pretty decent. So thanks for coding it up.

I did notice that the Expectancy Score does not appear to take commissions or slippage into account when calculating winsAmount or losesAmount.

Was the exclusion of commission and slippage on purpose?

It seems to me that we should be optimizing to a net expectancy score as opposed to a gross expectancy score.

What are your thoughts?



Here is the code for those that have not downloaded the .cs file.

#region Using declarations
	using System;
	using System.ComponentModel;
	using System.Drawing;
	using NinjaTrader.Cbi;
	using NinjaTrader.Data;
	using NinjaTrader.Indicator;
	using NinjaTrader.Strategy;

namespace NinjaTrader.Strategy
	// Expectany score calculations based on Van K. Tharp's book 'Trade Your Way to Financial Freedom'.
	// Portions of this code borrowed from fluxsmith at (formerly BMT).  Thanks for the start!
	// 4/28/2011.  Gordon Brest.
	[Gui.Design.DisplayName("Expectancy Score")]
    public class ExpectancyScore : OptimizationType
		#region variables
			private int normalizedNumberTradesPerYear;
			private int numberScratchTrades;
			private int numberOfTrades;
			private double studyDays;
			private double averageWinningTrade;
			private double probabilityOfWinning;
			private double averageLosingTrade;
			private double probabilityOfLosing;
			private double nonScratchTrades;
			private double valueScratchTrades;
			private double winsAmount;
			private double winsCount;
			private double losesAmount;
			private double losesCount;
			private double expectancy;
			private double opportunity;
			private double commission;
			private bool init = false;
			private double val;
			public double expectancyScore;
			private DateTime start = new DateTime();
			private DateTime stop = new DateTime();
			private TimeSpan span = new TimeSpan();
		public override double GetPerformanceValue(SystemPerformance systemPerformance)
			#region Logic Description
			EXPECTANCY is how much you expect to earn from each trade for every dollar you risk. Opportunity is how often your strategy trades. 
			You want to maximize the product of both.
			Expectancy = (AW  PW + AL  PL) ⁄ |AL| 
			(expected profit per dollar risked)
			Expectancy score = Expectancy  Opportunity
			AW = average winning trade (excluding maximum win) 
			AL = average losing trade (negative, excluding scratch losses) 
			|AL| = absolute value of AL 
			PW = probability of winning: PW = <wins> ⁄ NST (where <wins> is total wins excluding maximum win) 
			PL = probability of losing: PL = <non-scratch losses> ⁄ NST  
			Opportunity = NST  365 ⁄ studydays   (opportunities to trade in a year) 
			NST = <total trades> − <scratch trades> − 1
			In other words, NST = non-scratch trades during the period under test (a scratch trade loses commission+slippage or less) minus 1 (to exclude the maximum win). 
			studydays = calendar days of history being tested 
			NOTE:  The above verbage from the referenced website has been copied into the code below to explain the code's logic.
			/// Number of trades.
			numberOfTrades = systemPerformance.AllTrades.TradesPerformance.TradesCount;
			normalizedNumberTradesPerYear = (int)(systemPerformance.AllTrades.TradesPerformance.TradesPerDay * 365.0);
			commission = systemPerformance.AllTrades.TradesPerformance.Commission / numberOfTrades * -1;
			// studydays = calendar days of history being tested 
			foreach (Trade allTrades in systemPerformance.AllTrades)
				if (!init)
					init = true;
					start = allTrades.Entry.Time.Date;
				stop = allTrades.Entry.Time.Date;
			span = stop.Subtract(start);
			studyDays = span.TotalDays + 1;
			/// Calculate scratch trades.
			numberScratchTrades = 0;
			valueScratchTrades = 0;
			// NST = <total trades> − <scratch trades> − 1
			// In other words, NST = non-scratch trades during the period under test (a scratch trade loses commission+slippage or less) minus 1 (to exclude the maximum win). 			foreach (Trade myTrade in systemPerformance.AllTrades.LosingTrades)
			foreach (Trade losingTrades in systemPerformance.AllTrades.LosingTrades)
				if (losingTrades.ProfitCurrency >= 1.25 * commission)
					numberScratchTrades ++;
					valueScratchTrades += losingTrades.ProfitCurrency;
			nonScratchTrades = numberOfTrades - numberScratchTrades - 1;
			winsCount = systemPerformance.AllTrades.WinningTrades.Count;
			losesCount = systemPerformance.AllTrades.LosingTrades.Count - numberScratchTrades;
			/// Reject optimizations that do not make any trades.
			if ( normalizedNumberTradesPerYear == 0 )
				return 777;
			/// Reject optimizations that trade less than once a week.
			if ( normalizedNumberTradesPerYear < 50 )
				return 888;
			/// Reject optimizations that do not have any losing trades as unrealistic.
			if ( systemPerformance.AllTrades.LosingTrades.Count == 0 )
				return 999;
			/// Calculate averages.
			// AW = average winning trade (excluding maximum win) 
			winsAmount = systemPerformance.AllTrades.TradesPerformance.GrossProfit - systemPerformance.AllTrades.TradesPerformance.Currency.LargestWinner;
			averageWinningTrade = winsAmount / (systemPerformance.AllTrades.WinningTrades.Count - 1);
			// AL = average losing trade (negative, excluding scratch losses) 
			losesAmount = systemPerformance.AllTrades.TradesPerformance.GrossLoss - valueScratchTrades;
			averageLosingTrade =  losesAmount / (systemPerformance.AllTrades.LosingTrades.Count - numberScratchTrades);
			/// Calculate probabilities.
			// PW = probability of winning: PW = <wins> ⁄ NST (where <wins> is total wins excluding maximum win) 
			probabilityOfWinning = winsCount / nonScratchTrades;
			// PL = probability of losing: PL = <non-scratch losses> ⁄ NST  
			probabilityOfLosing = losesCount / nonScratchTrades;
			/// Final calculations.
			// Expectancy = (AW  PW + AL  PL) ⁄ |AL| where |AL| = absolute value of AL.
			expectancy = (averageWinningTrade * probabilityOfWinning + averageLosingTrade * probabilityOfLosing) / Math.Abs(averageLosingTrade);
			//val = expectancy;
			// Opportunity = NST  365 ⁄ studydays   (opportunities to trade in a year) 
			opportunity = nonScratchTrades * 365 / studyDays;
			// Expectancy score = Expectancy  Opportunity
			expectancyScore = expectancy * opportunity;
			/// Return the final value.
			return expectancyScore;

Last edited by aventeren; February 20th, 2014 at 02:33 PM. Reason: Added code...
Reply With Quote
The following user says Thank You to aventeren for this post:

Old January 22nd, 2015, 11:55 AM   #32 (permalink)
Elite Member
Toronto, Ontario, Canada
Futures Experience: Advanced
Platform: Ninja, MultiCharts
Favorite Futures: ES
Posts: 13 since Feb 2014
Thanks: 25 given, 12 received

@rickt - Replying to your post about dividing by AvgLoss vs. dividing by Std(TradeResults), I think that the latter gives a sense as to the likelihood that the TotalProfit occurred by chance or due to a true edge. This van Tharp approach strikes me as just a variation of the Sharpe Ratio (for good or ill).

In contrast the division by AvgLoss gives you what your results would look like over an extended period in terms of how much better your gains did over your losses, provided your system makes it over that extended period.

I like to analogize this to betting on the race car driver that wins the most races in a season as opposed to the one that is the wildest, fastest driver in the season's first three events but then crashes out in flames.

Reply With Quote

Reply > Futures Trading, News, Charts and Platforms > Psychology and Money Management > Van Tharp's Max Expectancy

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

NinjaTrader 8: Programming Profitable Trading Edges w/Scott Hodson

Elite only

Anthony Drager: Executing on Intermarket Correlations & Order Flow, Part 2

Elite only

Adam Grimes: Five critically important keys to professional trading

Elite only

Machine Learning Concepts w/FIO member NJAMC

Elite only

MarketDelta Cloud Platform: Announcing new mobile features

Dec 1

NinjaTrader 8: Features and Enhancements

Dec 6

Similar Threads
Thread Thread Starter Forum Replies Last Post
Van Tharp Books Dusty909 Psychology and Money Management 22 August 15th, 2016 11:57 AM
Van Tharp's Secrets of Trading Game caprica The Elite Circle 2 March 8th, 2012 10:26 AM
Position Sizing by Van Tharp Laserdan Psychology and Money Management 21 July 8th, 2011 10:37 AM
What Type Trader Are You? - more from Van Tharp Trader.Jon Psychology and Money Management 0 November 12th, 2009 08:47 AM
Van Tharp Trade Your Way to Financial Freedom caprica The Elite Circle 16 October 15th, 2009 05:30 AM

All times are GMT -4. The time now is 01:10 AM.

Copyright © 2016 by All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts

Page generated 2016-10-27 in 0.07 seconds with 20 queries on phoenix via your IP