trade.entryBar?

Hi Forum,

I would like to add to BackTesting a gap column.
My problem is to know which bar belongs to trade.

How can i implement this? How can i ask the BarIndex() or the trade.entryBar during backtesting?

Thx in advance, Zoltan.

SetCustomBacktestProc("");

/* Now custom-backtest procedure follows */
if( Status(“action”) == actionPortfolio )
{
bo = GetBacktesterObject();

bo.Backtest(1); // run default backtest procedure 

for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) 
{
	trade.AddCustomMetric("Commission", trade.GetCommission());
	trade.AddCustomMetric("Commission / PositionValue", trade.GetCommission() / trade.GetPositionValue(), 8);
	//SetForeign( trade.Symbol );

	/*
	***************************************************
	* I am interesting of the bar in case of trading. *     
	* Similar as trade.entryBar                   *
	* myTradeEntryBar = trade.EntryBar;               *
	***************************************************
	*/
	myTradeEntryBar = 1000;
	
	trade.AddCustomMetric("todayOpen", O[myTradeEntryBar] ); 
	trade.AddCustomMetric("yesteradyClose", C[myTradeEntryBar - 1] ); 
	trade.AddCustomMetric("GapFromClose", O[myTradeEntryBar] / C[myTradeEntryBar - 1] - 1 ); 
} 

bo.ListTrades(); 

}

fast = Optimize(“fast”, 12, 5, 20, 1 );
slow = Optimize(“slow”, 26, 10, 25, 1 );
Buy=Cross(MACD(fast,slow),Signal(fast,slow));
Sell=Cross(Signal(fast,slow),MACD(fast,slow));
Short = Cover = False;

Try something like this:

entryBar = Lookup(BarIndex(),trade.entrydatetime,0);
1 Like

Perfect.
Thank you for quick help!!!

BR, Zoltan.