Van K. Tharp's System Quality Number Function

Cover of the book The Definitive Guide to Position Sizing by Van K. Tharp

Van K. Tharp proposed a formula for System Quality Number that measured strategy performance and could be used as a custom objective for optimizing strategy parameters.

The formula was presented in his book: The Definitive Guide To Position Sizing, published in August 2008.

SQN = SquareRoot(TotalTrades) * AverageWins / (StdDev of Wins)

Typical Usage

The function is called from a strategy when the LastBarOnChart is reached.

{ calling function from a strategy }
vars: SQN(0);
arrays:
    TradeArray[3000](0);  { TradeArray may be loaded with function _LoadTradeArray }

if LastBarOnChart then begin
    SQN = SystemQualityNr(TradeArray);
end;

Code Description

The function uses all in-line code, uses a faster algorithm for calculating Standard Deviation than TradeStation's built-in StdDev function, and trade information passed to it in an array, TradeArray. It is called once at the end of each strategy run when the LastBarOnChart condition is reached.

The TradeArray may be loaded with all strategy trades using function LoadTradeArray. A description and code for the LoadTradeArray function are in a separate post: Loading Strategy Trades Into An Array.

The System Quality Number value can be output, using FileAppend, along with other strategy performance statistics to optimize strategy input parameters beyond the built-in objective functions that are available within the TradeStation optimizer.

Downloads

Initially posted version: 09/14/09

Latest Update: 09/17/09

*.ELD files are compiled for TS 8.6

Users of earlier versions of TradeStation may compile the code from the text files included in the above *.zip file.

The code may be visualized here:

Related Posts

Was this helpful? Rate it: