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.
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?
thank you all for your cooperation