Why Do I Need to Know the Strategy Optimization Pass Number?

There are two very useful purposes served by knowing the strategy optimization iteration or pass number during optimization:

  • When Outputting Optimization Results of Each Pass.   Some parameters that are output need to be calculated only once for each optimization pass.  Having the Optimization Pass Number available to your code allows you to perform these calculations only once per optimization (When the Optimization Pass Number = 1).
  • When Calculating parameters independent of the variables being optimized.  These calculations need only be done once per optimization run (When the Optimization Number = 1).

Important Points when Using the Optimization Number Function

  • EL Collections for EasyLanguage must be installed for this function to work. A link is provided below for obtaining the code and documentation.
  • The TempFile location defined in the variable definition as TempFile(“E:/temp/temp.txt”) may be modified by the user.Keep in mind that some versions of Windows prohibit the creation of files in protected directories, such as some areas of Drive C under Windows Vista or Windows 7. If you receive a “file can not be created” error message, it may be for this reason.
  • Although FastFileAppend is generally faster than FileAppend, I have found it does not consistently create new files on my system. Therefore I have reverted to using FileAppend in this function.


The following code placed within your strategy may be used to call this function, which will return the optimization pass number:

vars: OptPassNr(0);

once begin
        OptPassNr = _OptimizationPassNr;

Note that the function needs to be called only once per strategy iteration and therefore is bracketed by once begin …. end statements.

Alternatively, the following variable definition will self-initialize at the start of each optimization run placing the optimization pass number in the variable OptPassNr:

vars: OptPassNr(_OptimizationPassNr);

In this case, no once begin …. end statement is needed and the function does not need to be explicitly called in the body of the strategy code.


Initially posted version:  03/31/10

Latest Update:  03/31/10

*.ELD files are compiled for TS 8.7

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:

Function OptimiationPassNr

Optimization Pass Number Example using OOP

The code and documentation for EL Collections for EasyLanguage may be visualized here: