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 recent book: The Definitive Guide To Position Sizingpublished 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 );

     TradeArray[3000](0); { TradeArray may be loaded with function _LoadTradeArray }

 if LastBarOnChart then begin
     SQN = SystemQualityNr ( TradeArray ) ;

Code Description

The function uses all in-line code, uses a faster algorithm for calculating Standard Deviation than the 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 referenced below.

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.



Initially posted version:  09/14/09

Latest Update:  09/17/09

*.ELD files are compiled for TS 8.6

All ELD and code text files packaged here:

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

The code may be visualized here:

SystemQualityNr Function

Additional information about the LoadTradeArray Function
may be found in a separate post describing that function:

LoadTradeArray Function