Optimization gives NaN results

I am getting 0 and NaN results in optimization even for a simple code attached below. Analysis settings seem ok. Please advise...

mfast = Optimize( "MACD Fast", 12, 8, 16, 1 ); 
mslow = Optimize("MACD Slow", 26, 17, 30, 1 ); 
sigavg = Optimize( "Signal average", 9, 2, 20, 1 );
Buy = Cover = Cross( MACD( mfast, mslow ) , Signal( mfast, mslow, sigavg ) ); 
Sell = Short = Cross( Signal( mfast, mslow, sigavg ), MACD( mfast, mslow ) );

Analysis%20Settings

Do you have appropriate amount of tick data stored?
How does your chart look like if 100R is set there?
Which TickSize value have you set?

Hi codejunkie, I have tickdata, tick size is 0.05, rangebars of 5 points are properly plotted. Attaching screenshot. I am unable to figure out. Any changes involved in ver 6.30?

Plot( C, "Close", colorDefault, styleCandle); 
mfast = Optimize( "MACD Fast", 12, 8, 16, 1 ); 
mslow = Optimize("MACD Slow", 26, 17, 30, 1 ); 
sigavg = Optimize( "Signal average", 9, 2, 20, 1 );
Buy = Cover = Cross( MACD( mfast, mslow ) , Signal( mfast, mslow, sigavg ) ); 
Sell = Short = Cross( Signal( mfast, mslow, sigavg ), MACD( mfast, mslow ) );
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell, Buy);
Short = ExRem(Short ,Cover);
Cover = ExRem(Cover,Short);
//######################################  PLOTS AND SHAPES #############################################
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorTurquoise, 0, L, Offset=-60);
PlotShapes(IIf(sell, shapeSmallDownTriangle, shapeNone),colorTurquoise, 0,H, Offset=-60);
PlotShapes(IIf(Cover, shapeSmallUpTriangle, shapeNone),colorYellow, 0, L, Offset=-45);
PlotShapes(IIf(short, shapeDownArrow, shapeNone),colorYellow, 0,H, Offset=-45);

100R%20Chart

Rerun with these settings.
Does running backtest result in empty result list too?
Check detailed log of analysis settings - Report and run backtest.

Your symbol's price is above 10000 but you have set initial equity to 10000.
You need to increase Equity.

If it is future then set future mode to true and check out this one https://www.amibroker.com/guide/h_futbacktest.html

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 100000 );
SetOption( "FuturesMode", False );// future yes or no?
SetOption( "AllowPositionShrinking", True );
SetPositionSize(1, spsShares);

TickSize = 0.05;

BuyPrice = SellPrice = CoverPrice = ShortPrice = Open;

mfast = Optimize( "MACD Fast", 12, 8, 16, 1 ); 
mslow = Optimize("MACD Slow", 26, 17, 30, 1 ); 
sigavg = Optimize( "Signal average", 9, 2, 20, 1 );

Buy = Cover = Cross( MACD( mfast, mslow ) , Signal( mfast, mslow, sigavg ) ); 
Sell = Short = Cross( Signal( mfast, mslow, sigavg ), MACD( mfast, mslow ) );

4 Likes

Hi codejunkie, Thank you, you solved my problem...