//Unequal Step Optimization in AmiBroker by ThaiQuants.com
//Please study amibroker.thaiquants.com/optimization
SetOption("InitialEquity", 1000000);
{//Main code of this post
//Create an array holding unequal step values
mop[0] = 10; // 100/10 = 10% of Equity
mop[1] = 20; // 100/20 = 5%
mop[2] = 25; // 100/25 = 4%
mop[3] = 50; // 100/50 = 2%
//Set optimized parameter
_mop = Optimize("_mop", 1, 0, 3, 1);
maxOpenPositions = mop[_mop];
//Use it
SetOption("MaxOpenPositions", maxOpenPositions);
//Don't forget to apply it in other related code.
//In this example, MaxOpenPositions and PositionSize are related.
SetPositionSize(100/maxOpenPositions, spsPercentOfEquity);
}
SetTradeDelays(1, 1, 0, 0);
BuyPrice = SellPrice = Open;
Buy = Cross(MACD(), Signal()) AND C > 2;
Sell = Cross(Signal(), MACD());
PositionScore = C*V;