Hi,
I wanted to eliminate all signals if a given bar has generated Signals for both calls and put. I've coded the following 2 snippets which is serving the purpose but throwing different performance statistics. Please guide me which one is correct.
//Snippet 1
SetOption( "UseCustomBacktestProc", True );
SetCustomBacktestProc( "" );
function Opt_Type( Sym )
{
OptType = StrRight( Sym, 2 );
return OptType;
}
if( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject(); // Get backtester object
bo.PreProcess(); // Do pre-processing (always required)
for( i = 0; i < BarCount; i++ ) // Loop through all bars
{
//Reset Counter at every bar
CE_count = 0;
PE_count = 0;
for( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
{
if( sig.IsEntry() )
{
IsType = Opt_Type( sig.Symbol);
Sym_Type_CE = (IsType == "CE");
Sym_Type_PE = (IsType == "PE");
if( Sym_Type_CE ) CE_count ++;
if( Sym_Type_PE ) PE_count ++;
}
**if( CE_count > 0 AND PE_count > 0 )**
** {**
** sig.Price = -1 ; // ignore entry signal if given bars has multiple and opposite signals**
** }**
}
bo.ProcessTradeSignals( i ); // Process trades at bar (always required)
}
bo.PostProcess(); // Do post-processing (always required)
}
Following is the second way which is also eliminating all signals at a given bar if having for both CE and PE.
SetOption( "UseCustomBacktestProc", True );
SetCustomBacktestProc( "" );
function Opt_Type( Sym )
{
OptType = StrRight( Sym, 2 );
return OptType;
}
if( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject(); // Get backtester object
bo.PreProcess(); // Do pre-processing (always required)
for( i = 0; i < BarCount; i++ ) // Loop through all bars
{
//Reset Counter at every bar
CE_count = 0;
PE_count = 0;
for( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
{
if( sig.IsEntry() )
{
IsType = Opt_Type( sig.Symbol);
Sym_Type_CE = (IsType == "CE");
Sym_Type_PE = (IsType == "PE");
if( Sym_Type_CE ) CE_count ++;
if( Sym_Type_PE ) PE_count ++;
**if( CE_count > 0 AND PE_count > 0 )**
** {**
** sig.Price = -1 ; // ignore entry signals if given bars has multiple and opposite signals**
** }**
}
}
bo.ProcessTradeSignals( i ); // Process trades at bar (always required)
}
bo.PostProcess(); // Do post-processing (always required)
}
I am quite weak with loop and yet to get grip on custom backtester, guidance would be appreciated. Thanks in advance.