OMX_F_GPF (Series Function)
Previous  Top  Next

Summary:
OMX_F_GPF is a customizable fitness function that measures and combines several fitness components into a compound value. Call this function in the Epilog to compute a fitness value.


 
clip0008Ease-of-use Tip  
Sample code for using this function is available within TradeStation in strategies OMX_CutAndPaste and OMX_Sample1_C. Simply open one of those strategies and cut and paste the sample code into your own strategy to use.  
 
 

Prototype:
 
OMX_Fitness = OMX_F_GPF(   
   OMX_IterationNum,          { The Optimax Iteration Number                                    }  
   PrintInfo,                 { 1=print detail info to the output window, 2=\GPF.txt 0=don't    }  
   SendVarsToOMX,             { true=call OMX_SendVar for each of the intermediate values       }  
   RejectNegNetProfit,        { Always reject a negative net profit value?                      }  
   PeriodType,                { 1 = day, 2 = week, 3 = month                                    }  
   InvestmentCapital,         { Available Investment Capital (in $)                             }  
                              {--- Avg Number of Trades Per Period                            --}  
   ATP_Tgt,                   { Target # of trades per period                                   }  
   ATP_Wgt,                   { Weighting factor                                                }  
   ATP_Rng,                   { Acceptable +/- Range                                            }  
   ATP_Bal,                   { Balance between SSDev and Proximity (1 to 0)                    }  
   ATP_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   ATP_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   ATP_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Pct Profitable Trades                                      --}  
   PPT_Tgt,                   { Target Pct Profitable trades per period 1 = 1%, 80 = 80%        }  
   PPT_Wgt,                   { Weighting factor                                                }  
   PPT_Rng,                   { Acceptable Range                                                }  
   PPT_Bal,                   { Balance between SSDev and Proximity (1 to 0)                    }  
   PPT_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   PPT_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   PPT_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Average Bars Per Trade                                     --}  
   ABT_Tgt,                   { Target number of bars per trade                                 }  
   ABT_Wgt,                   { Weighting factor                                                }  
   ABT_Rng,                   { Acceptable +/- Range                                            }  
   ABT_Bal,                   { Balance between SSDev and Proximity (1 to 0)                    }  
   ABT_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   ABT_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   ABT_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Bars Per Winning Trade/Bars Per Losing Trade Ratio         --}  
   BTR_Tgt,                   { Target ratio of bars per winning trade to bars per losing trade }  
   BTR_Wgt,                   { Weighting factor                                                }  
   BTR_Rng,                   { Acceptable +/- Range                                            }  
   BTR_Bal,                   { Balance between SSDev and Proximity (1 to 0)                    }  
   BTR_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   BTR_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   BTR_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Avg % of Capital Invested Per Period                       --}  
   ACI_Tgt,                   { Target avg % of capital invested                                }  
   ACI_Wgt,                   { Weighting factor                                                }  
   ACI_Rng,                   { Acceptable +/- Range                                            }  
   ACI_Bal,                   { Balance between SSDev and Proximity (1 to 0)                    }  
   ACI_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   ACI_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   ACI_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Max % of Capital Invested Per Period (can use for margin)  --}  
   MCI_Tgt,                   { Target max % of capital invested                                }  
   MCI_Wgt,                   { Weighting factor                                                }  
   MCI_Rng,                   { Acceptable +/- Range                                            }  
   MCI_Bal,                   { Balance between SSDev and Proximity (1 to 0)                    }  
   MCI_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   MCI_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   MCI_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Average Win / Avg Loss Ratio - maximized                   --}  
   AWL_Wgt,                   { Weighting factor                                                }  
   AWL_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   AWL_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   AWL_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- Profit Factor - maximize                                   --}  
   PRF_Wgt,                   { Weighting factor                                                }  
   PRF_TLT,                   { Time-line Scaling Type (1=Linear, 2=Exponential)                }  
   PRF_TLW,                   { Time-line Scaling Weighting factor (0 to +/-N.N)                }  
   PRF_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
                              {--- NetProfit to MaxDrawdown Ratio                             --}  
   NMR_Wgt,                   { Weighting factor                                                }  
   NMR_Pos,                   { Use positive values only? (Ignore negatives?)                   }  
 
   bDoComputation,            { Only compute when this value is True. usually LastBarOnChart    }  
 
   PeriodReturn,              { Equity Return in each period                                    }  
   PeriodTrades,              { Number of trades in each period                                 }  
   PeriodWins,                { Number of wins in each period                                   }  
   PeriodLosses,              { Number of losses in each period                                 }  
   PeriodPctPft,              { Percent profitable by period                                    }  
   PeriodGrossProfit,         { Gross profit by period                                          }  
   PeriodGrossLoss,           { Gross loss by period                                            }  
   PeriodProfitFactor,        { Profit Factor by period                                         }  
   PeriodEvenBars,            { Total bars in even trades by period                             }  
   PeriodWinBars,             { Total bars in winning trades by period                          }  
   PeriodLosBars,             { Total bars in losing trades by period                           }  
   PeriodTotalTrades,         { Total number of trades by period                                }  
   PeriodABT,                 { Period average bars per trade                                   }  
   PeriodAWL,                 { Avg Win/Loss per period                                         }  
   PeriodBTR,                 { AB Win/AB Loss ratio per period                                 }  
   PeriodACI,                 { Avg % of capital invested per period                            }  
   PeriodMCI ;                { Max % of capital invested per period                            }  

Parameters:

Name
Type
Possible Values
Description
OMX_IterationNum
NumericSimple
Any integer
The Optimax iteration number
PrintInfo
NumericSimple
0,1,2
When 1, this function prints detailed information about the internal computations to the TradeStation Output Print Log window. This information is useful for tuning the weighting parameters and for determining the optimum size of the input arrays. When 2, the same information is printed to file \GPF.txt (in the root directory,) instead. When 0, no information is printed.
SendVarsToOMX
TrueFalseSimple
True/False
When True, this function sends information about internal computations to the Optimax Performance Detail Report. This information is useful for tuning the weighting parameters.
RejectNegNetProfit
TrueFalseSimple
True/False
When True, equity curves which end with a negative Net Profit will always have a negative fitness value. When False, only the potential for generating positive equity across the entire curve determines the sign of the return value, not the final value of the equity.
PeriodType
NumericSimple
1, 2, 3
The length of period to use for internal consistency measurements. 1=daily, 2=weekly, 3=monthly
InvestmentCapital
NumericSimple
any positive value
The amount of capital available to invest, in dollars. Used for computing the ACI and MCI component values.
ATP_Tgt
NumericSimple
any positive value
The average number of trades per period that you would like to target during optimization.
ATP_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the ATP component relative to all other components.
ATP_Rng
NumericSimple
0 to any number
The acceptable size of the range on either side of the ATP_Tgt.
ATP_Bal
NumericSimple
1.0 to 0.0
The balance between SSDev and Proximity importance.
ATP_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
ATP_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
ATP_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
PPT_Tgt
NumericSimple
any positive value
The average percent profitable trades per period that you would like to target during optimization.
PPT_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the PPT component relative to all other components.
PPT_Rng
NumericSimple
0 to any number
The acceptable size of the range on either side of the PPT_Tgt.
PPT_Bal
NumericSimple
1.0 to 0.0
The balance between SSDev and Proximity importance.
PPT_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
PPT_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
PPT_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
ABT_Tgt
NumericSimple
any positive value
The average bars per trade per period that you would like to target during optimization.
ABT_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the ABT component relative to all other components.
ABT_Rng
NumericSimple
0 to any number
The acceptable size of the range on either side of the ABT_Tgt.
ABT_Bal
NumericSimple
1.0 to 0.0
The balance between SSDev and Proximity importance.
ABT_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
ABT_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
ABT_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
BTR_Tgt
NumericSimple
any positive value
The average per period of winning bars per trade to losing bars per trade that you would like to target during optimization.
BTR_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the BTR component relative to all other components.
BTR_Rng
NumericSimple
0 to any number
The acceptable size of the range on either side of the BTR_Tgt.
BTR_Bal
NumericSimple
1.0 to 0.0
The balance between SSDev and Proximity importance.
BTR_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
BTR_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
BTR_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
ACI_Tgt
NumericSimple
any positive value
The average percentage of capital invested per period that you would like to target during optimization.
ACI_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the ACI component relative to all other components.
ACI_Rng
NumericSimple
0 to any number
The acceptable size of the range on either side of the ACI_Tgt.
ACI_Bal
NumericSimple
1.0 to 0.0
The balance between SSDev and Proximity importance.
ACI_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
ACI_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
ACI_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
MCI_Tgt
NumericSimple
any positive value
The maximum percentage of capital invested on average per period that you would like to target during optimization.
MCI_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the MCI component relative to all other components.
MCI_Rng
NumericSimple
0 to any number
The acceptable size of the range on either side of the MCI_Tgt.
MCI_Bal
NumericSimple
1.0 to 0.0
The balance between SSDev and Proximity importance.
MCI_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
MCI_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
MCI_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
AWL_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the Average Win/Loss ratio (AWL component factor) relative to all other components.
AWL_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
AWL_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
AWL_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
PRF_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the profit factor (PRF component value) relative to all other components.
PRF_TLT
NumericSimple
1,2
The Time-line scaling type. 1=Linear, 2=Exponential
PRF_TLW
NumericSimple
+/-n.n
The Time-line scaling weighting factor.
PRF_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
NMR_Wgt
NumericSimple
0 to any number usually 0 to 1.0
The weighting factor (importance) of the net profit to intraday drawdown ratio (NMR component value) relative to all other components.
NMR_Pos
TrueFalseSimple
True/False
Use positive values only, meaning convert negative values to 0, so that they do not subtract from the fitness of other components.
bDoComputation
TrueFalseSimple
True/False
When true, compute the return (fitness) value. Usually passed a variable that is true on the final bar of analysis - usually LastBarOnChart
PeriodReturn
NumericArrayRef
Output only
Equity Return in each period
PeriodTrades
NumericArrayRef
Output only
Number of trades in each period
PeriodWins
NumericArrayRef
Output only
Number of wins in each period
PeriodLosses
NumericArrayRef
Output only
Number of wins in each period
PeriodPctPft
NumericArrayRef
Output only
Percent profitable by period
PeriodGrossProfit
NumericArrayRef
Output only
Gross profit by period
PeriodGrossLoss
NumericArrayRef
Output only
Gross loss by period
PeriodProfitFactor
NumericArrayRef
Output only
Profit Factor by period
PeriodEvenBars
NumericArrayRef
Output only
Total bars in even trades by period
PeriodWinBars
NumericArrayRef
Output only
Total bars in winning trades by period
PeriodLosBars
NumericArrayRef
Output only
Total bars in losing trades by period
PeriodTotalTrades
NumericArrayRef
Output only
Total number of trades by period
PeriodABT
NumericArrayRef
Output only
Period average bars per trade
PeriodAWL
NumericArrayRef
Output only
Period average win/loss ratio
PeriodBTR
NumericArrayRef
Output only
Avg Bars Win/Avg Bars Loss ratio per period
PeriodACI
NumericArrayRef
Output only
Avg % of capital invested per period
PeriodMCI
NumericArrayRef
Output only
Max % of capital invested per period
 


 
Function Type: Series
This is a series function - it executes at the end of the every bar.

Returns (Double)
This function returns a floating-point value which can be negative or positive, with values above 0 indicating desirable fitness and values 0 or below indicating undesirable fitness.

Description and Use
This function creates a compound, comprehensive fitness value from several discrete components. It is compatible with any type of strategy. Use it when you want to achieve fitness objectives other than a simple maximum net profit.

Notes  
·Within this document the term GPF refers to this function and the output from it.  
·Be sure to read the Period Arrays section below before attempting to use this function.  
 
Introduction  
This is not a "black box" fitness function as most are. This function is parametric, meaning it requires you to specify several input parameters. The output value depends upon the input parameter settings. In order to use this function successfully and to obtain the desired results, you are required to understand the correct use of the inputs. So instead of using many different fitness functions that contain components in a predefined static configuration, this one is flexible in that you can customize it by specifying parameter combinations to emphasize varying aspects of fitness and so customize the function according to the type of chart, type of strategy and your personal fitness goals.  
 
Parameters and Components  
Within this function are discrete internal computations, known as internal components. Input parameters control this internal fitness components, and are as follows:  
 
Component (per period)
Specifiable Parameters
Number of Trades Per Period
Target value, Weight, Range, Timeline Scaling, Pos-Only
Percent Profitable Trades
Target value, Weight, Range, Timeline Scaling, Pos-Only
Number of Bars per Trade
Target value, Weight, Range, Timeline Scaling, Pos-Only
Win/Loss Trade Bars Ratio
Target value, Weight, Range, Timeline Scaling, Pos-Only
Avg % of Capital Invested
Target value, Weight, Range, Timeline Scaling, Pos-Only
Max % of Capital Invested
Target value, Weight, Range, Timeline Scaling, Pos-Only
Avg Win/Avg Loss Ratio
Weight, Timeline Scaling, Pos-Only (value is always maximized)
Profit Factor
Weight, Timeline Scaling, Pos-Only (value is always maximized)
NetProfit to Max IDD Ratio
Weight, Timeline Scaling, Pos-Only (value is always maximized)
 
 
The final GPF value is the sum of the internal component values, as shown here:  
 
GPF = ATP + PPT + ABT + AWL + BTR + ACI + MCI + PRF + NMR  
where:  
ATP   is Average Number of Trades per period  
PPT   is Percent Profitable Trades  
ABT   is Average number of bars per trade  
AWL   is Average Win/Average Loss ratio  
BTR   is Win Bars Per Trade/Loss Bars per Trade Ratio  
ACI   is Avg % of Capital Invested  
MCI   is Max % of Capital Invested  
PRF   is Profit Factor  
NMR   is NetProfit to Max IDD Ratio  
GPF   is the output value from this fitness function  
 
Subcomponents  
Each component is built from several subcomponents, as follows:  
 
·The raw component value  
·The weighting factor you specify for the component  
·The proximity to the target you specify for the component  
·The measure of uniformity of the raw component values on a per-period basis (This is referred to the SSDev value in the subsequent documentation.)  
 
GPF combines subcomponent values together to obtain a final component value, according to the following equation:  
 
CFinal = ( ( CRaw * (1-CBal) * CProximity ) + ( CRaw * CBal * CSSDev) ) * CWeight  
 
where:  
CFinal   is the final value for the component  
CRaw   is the raw (average per period) subcomponent value  
CBal      is the balance between the importance of the SSDev and Proximity subcomponents  
CProximity   is the proximity to target subcomponent value  
CSSDev   is the SSDev (measure of uniformity) subcomponent value  
CWeight   is the weighting specified by you for the subcomponent  
 
For example, to obtain the Percent Profitable Trades component final value:  
 
PPT_Final = ( XOrNegProduct( PPT_Raw * (1-PPT_Bal), PPT_Proximity ) + XOrNegProduct( PPT_Raw * PPT_Bal, PPT_SSDev) ) * PPT_Weight  
 
This calculation takes a portion of the Raw value and weights it by proximity. It then takes the remaining portion of the Raw value and weights it by uniformity per period. It adds the two weighted portions together and then weights the entire sum by the weighting factor you specified for the subcomponent. A perfect score for a subcomponent is 1, provided the maximum weighting value you use is 1.  
 
If you specify a balance (PPT_Bal) value of 0.5, then the proximity to target is equally as important as the uniformity per period. You can adjust this by altering the balance value. For example, setting balance to 0.8 causes 80% of the importance to be placed on the uniformity, and only 20% on the proximity to target. Setting balance to 1 causes only uniformity to be considered. Setting it to 0 causes only proximity to target to be considered.  
 
If either the Raw or the Proximity value or BOTH are negative, the result of the multiplication is negative. This is accomplished via the XOrNegProduct function. This also holds true for the Raw and SSDev values. This unique treatment of the product of values ensures that a negative portion of the component remains negative; if it didn't it would incorrectly increase the value of the subcomponent.