Adding Optimax Calls Manually
Previous  Top  Next

The strategy code must first be prepared for use with Optimax by inserting OMX function calls. In this section we describe how to do it manually.

The following table gives you an overview of the code of an Optimax-converted strategy:

Before  
After  

OMX Preamble  
Inputs  
Converted Inputs  

OMX Prolog Code  
Your Strategy Code  
Your Strategy Code  

OMX Epilog Code  


Here is a sample strategy we will use in this chapter:

 
inputs:  
   Len1( 15 ),  
   Len2( 20 );  
 
if AverageFC( c, Len1 ) crosses over AverageFC( c, Len2 ) then  
   buy next bar at market ;  
if AverageFC( c, Len1 ) crosses under AverageFC( c, Len2 ) then  
   sell all shares next bar at market ;  
 

 
Here is the same strategy modified for use with Optimax. The added code is highlighted in pale green

 
{_____OMX PREAMBLE______}  
vars:  
OMX_Init( 0 ),  
OMX_Temp( 0 ),  
OMX_Fitness( 0 ) ;  
 
inputs:  
OMX_IterationNum( 0 ),  
OMX_Generation( 0 ),  
OMX_Individual( 0 ),  
OMX_StreamNum( 2 ),  
OMX_EquityResolution( 100 ) ;  
 
{_____CONVERTED INPUTS__}  
inputs:  
I_Len1( 15 ),  
I_Len2( 20 );  
 
Vars:  
Len1( 15 ),  
Len2( 20 );  
 
{_____OMX PROLOG________}  
If BarNumber = 1 Then begin  
if OMX_IterationNum = 0 and ( OMX_Generation = 0 or OMX_Individual = 0 ) then begin  
Len1 = I_Len1;  
Len2 = I_Len2;  
End  
else begin  
OMX_Init = OMX_InitPass( OMX_IterationNum, OMX_Generation, OMX_Individual ) ;  
If OMX_Init = 1 Then begin  
Len1 = OMX_GetParm( "Len1" ) ;  
Len2 = OMX_GetParm( "Len2" ) ;  
end ;  
end ;  
end ;  
If OMX_Init = 1 Then begin  
OMX_Temp = OMX_PriceModX( OMX_StreamNum, OMX_IterationNum, OMX_Generation, OMX_Individual ) ;  
end ;  
If OMX_IterationNum = 0 Or OMX_DateOk Then begin  
 
{_____YOUR STRATEGY_____}  
if AverageFC( c, Len1 ) crosses over AverageFC( c, Len2 ) then  
buy next bar at market ;  
if AverageFC( c, Len1 ) crosses under AverageFC( c, Len2 ) then  
sell all shares next bar at market ;  
 
{______OMX EPILOG_______}  
end ;  
If OMX_Init = 1 And OMX_IterationNum > 0 Then begin  
OMX_Temp = OMX_BarInfo( OMX_EquityResolution, OMX_IterationNum ) ;  
If OMX_LastBarInWalk Then begin  
OMX_Fitness = Div( NetProfit, absvalue(MaxIDDrawDown) ) ;  
OMX_Temp = OMX_EndPass( OMX_Fitness, OMX_IterationNum, OMX_FirstCalcDate, OMX_FirstCalcTime ) ;  
end ;  
end ;  



The following topics will cover each code segment in detail.