Instead of doing this
useInd1 = Optimize("Use Indicator 1", 1, 0, 1, 1);
useInd2 = Optimize("Use Indicator 2", 1, 0, 1, 1);
useInd3 = Optimize("Use Indicator 3", 1, 0, 1, 1);
Buy = IIf( useInd1, Cross( C, MA( C, 50 ) ), True ) AND
IIf( useInd2, Cross( 30, RSI() ), True ) AND
IIf( useInd3, Cross( MACD(), Signal() ), True );
Sell = 0;
Short = Cover = 0;
(I mean, what if you have 100 indicator conditions, would you seriously write 200 lines of code (100 Optimize() lines and 100 IIf() lines??)
So since we don’t like over-complication and code inflation (do we?)…
It is more appropriate to use looping for repetitive actions.
Then you only have to write your indicator logic and rest is taken care of by those loop iterations. And you only have just one Optimize variable.
/// @link http://forum.amibroker.com/t/optimization-using-multiple-indicators/3690/10
/// code response suggestion by fxshrat
condnum = 3;// number of conditions to be combined.
comb = Optimize("CombinationNum", 1, 1, 2^condnum, 1);
Buy1 = Cross( C, MA( C, 50 ) );
Buy2 = Cross( 30, RSI() );
Buy3 = Cross( MACD(), Signal() );
BuySum = 0;
for (n = 0; n < condnum; n++)
BuySum += IIf((comb & 2^n), VarGet("Buy" + (n+1)), 1);
Buy = BuySum == condnum;
Sell = 0;
Short = Cover = 0;
And best of all analysis results are the same ones.