Custom Backtest Interface Exit Trade Reason numbering

@Tomasz I am attempting to study the Custom Backtest Interface and write codes for a CBT. During the de-bugging of a simple mean reversion system, I noticed on the _Trace statements that my regular exits were given as “Reason = 1”. But in the User Guide the REASON specs show 0-regular exit, 1-max loss, 2-profit, etc.

Upon further review the reasons under the EXITTRADE method were displace by one. See screen captures from on-line user guide,
https://www.amibroker.com/guide/a_custombacktest.html

Is there a mistake I am making? Is the user guide confused?
And out of curiosity why is one value a long integer and the other a short integer?
image

The above also appears confirmed in this article,
http://www.amibroker.com/kb/2016/01/20/number-of-stopped-out-trades-as-a-custom-metric/

But later in the User Guide,

image

Image from Dbgview,
image

The Trace statement are from this code,

for( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) )
    {
        if( sig.IsExit() )
        {
            if( doTrace ) _TRACE( WriteVal( dt[bar], formatDateTime ) + ": Exiting trade for " + sig.Symbol + " Reason = " + sig.Reason );

            bo.ExitTrade( bar, sig.Symbol, sig.Price, sig.Reason );
        }
    }

This https://www.amibroker.com/guide/a_custombacktest.html is correct, so Reason = 1 is for regular exit.

It is not long integer. In ExitTrade call it is VARIANT type, which is required for optional parameter (VARIANTs can be skipped, not provided). If provided, variant is internally converted to short int.

1 Like