Run a piece of code only once during optimization steps


I need to run a piece of code only once during all optimization steps in Amibroker. Let me know a way to do so.

Thanks in advance !!

Rahul Jain

@rahuiitk try this snippet:

if( Status( "actionex" ) == actionExOptimizeSetup )
    _TRACE( "This code is done ONCE when Optimize() parameters are read (to setup optimization engine)" );
    // your code


emaPeriod = Optimize( "EMA Period", 21, 9, 50, 1 );
emaValues = EMA( C, emaPeriod );
Buy = Cross( C, emaValues );
Sell = Cross( emaValues, C );

If you need to do some specific work only in the optimize setup phase this could be enough.

Thanks a lot @beppe . It helped.