CBT, how are the signals present in a bar interrogated?

before posting this topic, I read the following documentation
http://www.amibroker.com/guide/a_custombacktest.html
http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
and many posts on the CBT

To try to understand the behavior of the CBT, I wrote a simple ChannelBreakout that never intervenes.
I took H and L and moved them away like image.9857
To get this behavior, I multiplied H * 2
Divided L / 2
If I launch the BackTest on a small basket, in fact there are no operations. Good.

Now I will try to interrogate the signals with this code, applied on a Watchlist containing only 10 symbols

InitialEquity = 100000;
SetOption( "InitialEquity", 100000);
SetPositionSize(1000, spsValue);
SetOption( "MaxOpenPositions", 50 );
SetOption( "CommissionMode"  , 2);
SetOption( "CommissionAmount", 0);
SetOption( "AllowSameBarExit", True);
SetOption( "ReverseSignalForcesExit", True);

RoundLotSize = 1;
TradeDelay = 0;
SetTradeDelays( TradeDelay, TradeDelay, TradeDelay, TradeDelay );

//signal-based backtest, redundant (raw) entry signals are NOT removed, MULTIPLE positions per symbol will 
//   be open if BUY/SHORT signal is true for more than one bar and there are free funds, Sell/Cover exit all 
//   open positions on given symbol, Scale-In/Out work on all open positions of given symbol at once.
SetBacktestMode(backtestRegularRawMulti);	

////////////////////////////////////////////////////
Lev_B_1 = Ref( High, -1)*2;
Lev_S_1 = Ref( Low , -1)/2;

Plot( Lev_B_1, "Lev_B_1", colorAqua  , styleStaircase, Null, Null, 0, 1);
Plot( Lev_S_1, "Lev_S_1", colorRed   , styleStaircase, Null, Null, 0, 1);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

Buy   = High >= Lev_B_1;
Sell  = 1;
Short = Low  <= Lev_S_1;
Cover = 1;

BuyPrice   = Max(Open, Lev_B_1);
ShortPrice = Min(Open, Lev_S_1);
SellPrice  = IIf(Buy AND Short, ShortPrice, Close);		//se candela OutSide
CoverPrice = IIf(Buy AND Short, BuyPrice  , Close);		//se candela OutSide;
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio) {
	bo = GetBacktesterObject();
	bo.PreProcess();
	G_DateT = DateNum();
	Day_Bck = 2;
	for (i = 0; i < BarCount; i++) 	
	{
	
		for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))  			// Loop through all signals at this bar
		{
			if( sig.IsEntry() ) {
				_Trace( 		  "sig.Symbol:"+sig.Symbol + "\t"
								+ "sig.Type:"+sig.Type + "\t"
								+ WriteIf(sig.Type==0,"rank (rotational systems)", WriteIf(sig.Type==1,"Buy  ", WriteIf(sig.Type==2,"Sell ", WriteIf(sig.Type==3,"Short" , WriteIf(sig.Type==4,"Cover", WriteIf(sig.Type==5,"scale-in", WriteIf(sig.Type==6,"scale-out",""))))))) + "\t"
								+ "sig.Reason:"+sig.Reason + "\t"
								+ WriteIf(sig.Reason==0,"regular", WriteIf(sig.Reason==1,"max. loss", WriteIf(sig.Reason==2,"profit", WriteIf(sig.Reason==3,"trail", WriteIf(sig.Reason==4,"N-bar", WriteIf(sig.Reason==5,"ruin","")))))) + "\t"
								+ "sig.PosScore:"+sig.PosScore + "\t"
								+ "sig.PosSize:"+sig.PosSize + "\t"
								+ "sig.Price:"+sig.Price + "\t"
					   );
				
			}
		}
		bo.ProcessTradeSignals(i);
		bo.HandleStops(i); 									// LOW-level method		Handle programmed stops at this bar
		bo.UpdateStats(i, 1); 								// LOW-level method		1 means middle of the bar 
		bo.UpdateStats(i, 2); 								// LOW-level method		2 means end of bar
	}
	bo.PostProcess(); 										// MID-level / LOW-level method		Do post-processing
}

Why does no result appear with _Trace?
yet every day I should load an order with the broker at the H * 2 price of Buy and at the L / 2 price of Short

Where am I doing wrong?
I was convinced that with the CBT the signals could be interrogated, including those that will not be affected.

I tried with ArtificialBar on / off
I tried with

backtestRegular
backtestRegularRaw
backtestRegularRawMulti  //this is what I think is correct

Where am I doing wrong? :thinking:
thank you all for your cooperation

As you have correctly pointed out, you are not generating any entry signals, i.e. Buy and Short are always False. And with all three backtester modes that you tried, AmiBroker removes redundant exit signals. Therefore, you are not seeing any signals in the CBT.

so there is no solution?
before answering you, I also tried

SetBacktestMode(backtestRegularRaw2);
SetBacktestMode(backtestRegularRaw2Multi);

If I understand correctly, considering that I am convinced that, Amibroker allows you to simulate everything, I can not read orders that are not affected? :disappointed_relieved:

@flaviog I agree with @mradtke, but, since I do not understand the above statement. I wonder if you could explain a little more what was your intended Buy/Sell strategy.

This could allow us to suggest some changes to your posted code in order to show the entry/exit signals in the CBT part.

If you want to process "orders" in the CBT, then you have to generate entry signals which correspond to "orders" (often referred to as Setups) rather than actual entries.

I have a double goal
The first, as a trader, is to develop, design, a strategy that every day, issues 10 orders to open positions, and at the same time, to close the position at the end of the day.

With InteractiveBroker I saw that it is possible to transmit orders that close the position during the day. Good.

The second goal is to NOT use the

	if (Status("ActionEx") == actionExplore ) {
		Filter = DateNum() >= 1181003;

to publish the levels to be transmitted to the broker every day, but to write a log file, compatible with Interactivebroker's Basket Order.
In this way, I can load the orders with a few clicks, probably producing few errors.

If I could write a CBT that, every day, I write a file in CSV format, with orders to be transmitted to the broker, I would center a goal.

For the second, obviously I have to do a lot of tests, a lot of research, but the premises are there and they seem interesting.

If there are no other qualifying conditions, then you can simply do this to "place orders" for all symbols in your watchlist:

Buy=True;

You might also wish to add other Setup conditions, and/or to use PositionScore to rank your entry signals. Most importantly, however, it will now be up to your CBT to decide whether the actual price for the day exceeded your limit price, and therefore you should call bo.EnterTrade().

In short, GetFirstSignal()/GetNextSignal return any entry signal only on bars when either Buy or Short variable was True. Your Buy and Sell variables are False because conditions you wrote are never met (i.e. High isn't higher than 2 * prev bar high).

I apologize in advance, but I think I could not properly explain my goal.
A big thank you to Tomasz for intervening in this thread.

I try with an example to explain my goal that probably until now I have not explained correctly because of my modest knowledge of the English language.

I created a whatchlist with 10 tickers, ten very liquid ETFs.
QQQ, GLD, TLT, UCO, DGAZ, SPY, NUGT, JNUG, DUST, JDST
The idea is to write a strategy that is always flat at night. Every day you open a Long or Short position on each ETF and close the position at the end of the day.
In practice I will have to convey to the broker a level, which if hit, will involve the automatic closing of the position at the end of the day, allowing me in this way, to spend the night with zero positions.

To proceed, with the planning, I have to do two jobs.
The first is the most difficult part, that is to write a strategy, with a few lines of code, that is simple, robust, that behaves in a homogeneous way in the time of the historical series.

The second job is to write, develop an AFL tool that will allow me, every day, to write in a CSV file the tickers with the relevant levels to be loaded as BUY or SHORT orders, to be transmitted to the broker, accessorized Close End Of Day.

This second job I do not know how to deal with it.

Excluding the hypothesis of using the "Filter", choosing to use as a solution the writing of a CBT, I do not know how to query the BackTester object to obtain the levels, ordered by ticker, to be transmitted to the broker.

Can anyone please help me understand how to solve this problem?

Even just orienting me with a few lines of code that I will then study by doing some tests with logs, with _Trace?