True is anything other than zero, was: Negative returns for CBT methods?

Hi. I am trying to understand the output of the simple mid-level CBT below. My understanding from the CBT guide was that methods like isEntry(), isExit() etc returned boolean outputs i.e. 1/0. However, for a simple two bar backtest on a single symbol, the code below returns negative 1.000. Can you please help me understand why?
image

Buy = 1;
Sell = 1;
Short = Cover = 0;

SetCustomBacktestProc("");

if (Status("action") == actionPortfolio) 
{
    bo = GetBacktesterObject();	
    bo.PreProcess();	

    for (bar = 0; bar < BarCount; bar++)	
    {
		for (sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) )
		{	
			_TRACE( "Entry =" + NumToStr(sig.IsEntry()) + " Exit =" + NumToStr(sig.IsExit()) );
		}
		
		bo.ProcessTradeSignals( bar );	
	}	
    bo.PostProcess();	
}

@singanuk, the value returned actually are -1 or 0 (your are tricked by the way you wrote your _Trace() call.

Try:

_TRACE( "Entry = " + sig.IsEntry() + " Exit = " + sig.IsExit() );

Since the backtester interface is implemented as a COM object, I think that these results are the one expected for VARIANT_BOOL as explained in this Microsoft article.

Maybe @Tomasz could provide us more accurate technical details.

1 Like

No. True is not necessarily 1. True is any non-zero value.

These are boolean values. Zero is FALSE, anything other than zero is TRUE.

The value of -1 is result of all '1' bits in the int value that acts as boolean in COM.

3 Likes

@Tomasz, I noticed that there is a mistake in one of the code samples in the online documentation in the "Signal object" section, as follows:

    // retrieve the interface to portfolio backtester
    bo = GetBacktesterObject();

    for( sig = bo.GetFirstSignal(); sig; sig = bo.GetNextSignal() )
     {
        if( sig.IsEntry() )
         {
          // handle entry signal
           ....
         }  
     }

since both bo.GetFirstSignal() and bo.GetNextSignal() need to be invoked with a bar number.

Though this example is out of context, as it is, it can confuse some users without the additional loop over the bars.

4 Likes

Thanks for heads up. I added missing bits.

2 Likes