Strategy Optimization Pass Number Function

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 Pass Number = 1).

Important Points when Using the Optimization Pass 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.

Usage

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;
end;

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.

Downloads

Initially posted version: 03/31/10

Latest Update: 03/31/10

*.ELD files are compiled for TS 8.7

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: