Here is my rendition of the Expectancy Score from [I][COLOR=#810081]Trade Your Way to Financial Freedom[/COLOR][/I] by Van K. Tharp. The basis of this optimization is found in this link:
https://www.unicorn.us.com/trading/expectancy.html
which states in part:
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
where AW = average winning trade (excluding maximum win) PW = probability of winning (PW = <wins> ⁄ NST
where <wins> is total wins excluding maximum win) AL = average losing trade (negative, excluding scratch losses) |AL| = absolute value of AL PL = probability of losing (PL = <non-scratch losses> ⁄ NST) Opportunity = NST × 365 ⁄ studydays (opportunities to trade in a year) where - 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
This code atttempts to duplicate this algebraic information in NT7 eese.
Enjoy!
Gordo
Version 2 cleaned up a few coding errors.
I also added a new optimizer type which is just called expectancy. It does not include opportunity. Take a look. Join us on this link for a discussion on expectancy.
Enjoy!
Gordo
Category NinjaTrader 7 Miscellaneous
|
|
|