Access DateTime of signal bar within a custom backtest

Hello,

within a custom backtest I iterate through all bars:

SetCustomBacktestProc("");
if( Status("action") == actionPortfolio )  {
	
	bo = GetBacktesterObject(); 
	bo.PreProcess();
	
	for (i = 0; i < BarCount; i++) {
		for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i)) {
			if (sig.IsEntry()) {
                              currentEntryDateTime = sig.EntryDateTime;

How can I get the DateTime of the bar?
sig.EntryDateTime causes the error:
Error 20.
COM method/function EntryDateTime does not exist

Regards
Detöev

EntryDateTime is property of trade object but not of signal object.
https://www.amibroker.com/guide/a_custombacktest.html

SetPositionSize( 1, spsShares );

period = 20;
m = MA( Close, period ); 
Buy = Cross( Close, m ); 
Sell = Cross( m, Close ); 

StaticVarSet( "Date_" + Name(), DateTime() );

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

	/// @link https://forum.amibroker.com/t/access-datetime-of-signal-bar-within-a-custom-backtest/9346
	for (i = 0; i < BarCount; i++) {
		for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i)) {
			if (sig.IsEntry()) {
				sig_dt = StaticVarGet( "Date_" + sig.Symbol );
				currentEntryDateTime = sig_dt[i];
				_TRACEF( "Sig Entry Date (%s): %s", sig.Symbol, DateTimeToStr( currentEntryDateTime ) );
			}
		}
        
		bo.ProcessTradeSignals( i );
	}
    
	bo.PostProcess();
}
1 Like

Thank you ever so much!
It's working.