"Show actual trades" differ from backtest trade results

I am observing a weird thing. "Show actual trades" shows trade signals as it should (I am plotting the sell / buy on a separate pane for the sake of clarity). However, only one buy is present in the trade list and it is at the wrong bar! Furthermore, no sells take place for this symbol. The trade is 4498 bars long.

In this thread Show Arrows for Actual Trades ignoring CBT , it is explained that the "Show actual trades" does not take into account the CBT. However, I am NOT using a CBT.

How is this possible? It looks like the backtest was using a different formula but when I set sell=1, all trades are 2 bars long as they should be. Therefore I am sure that I am editing the right file (apart from the correct filename displayed at the top of the window).

"Show actual trades":

"Show current trade arrors":

The sell signal is absent in the detailed log as well:

The answer lies in the response that @Tomasz provided in the post you referenced. Specifically, "Show Actual Trades" displays trade arrows resulting from a single symbol backtest. In many cases, these will not be the same trades taken during a portfolio backtest where there is competition between symbols for capital and available open positions.

Use "Show current trade arrows" option.

1 Like

But how comes that the sell does not trigger? I understand that buys can be not triggered because of insufficient funds or too low position score or whatever. But how is it possible that a sell does not trigger?

As for the buys, it is not a matter of a buy failing to trigger, it is triggered at a wrong bar.

Sample code to reproduce:

Plot_indicators = ParamList("Plot indicators", "buy/sell");

_mfi = Ref(MFI(), -1);
_pvi = Ref(PVI(), -1);

Buy = _mfi < 20;
Sell = int(_pvi) < int(Ref(_pvi, -1));

if (Plot_indicators == "buy/sell") {	   			   		
		Plot(Sell, "sell", colorAqua); 		 		 
		Plot(Buy, "buy", colorYellow);
		PlotGrid(1);   
}

image

To reproduce backtester signals, you should do it like this


_mfi = Ref( MFI(), -1);
_pvi = Ref( PVI(), -1);

Buy = _mfi < 20;
Sell = int(_pvi) < int(Ref(_pvi, -1));

Equity( 1, 0 );

Plot( Sell, "sell", colorAqua ); 		 		 
Plot( Buy, "buy", colorYellow );

This is only lower chart pane code.

In your entire thread you have not shared full formula, to reproduce, you should share your APX file.

You need to understand what this function does. The name is not the luckiest but I did not have better ideas how to name it.

What "show actual trades" function does is to RUN SINGLE SECURITY BACKTEST ON THE FLY and display actual trades from SINGLE SECURITY BACKTEST.

It does NOT show trades from PORTFOLIO backtest.

To display arrows from PORTFOLIO BACKTEST, you should use "Show CURRENT TRADE ARROWS" function

This takes actual trade FROM THE OUTPUT list and displays it.

The difference between PORTFOLIO backtest and SINGLE SECURITY backtest are that in PORTFOLIO backtest, other trades (from other symbols) may BLOCK certain entries for example due to insufficient funds. For example if you invest 100% of funds in "A" and you keep the position open, there will be no trades in "B" at all, even if you have signals on "B".

But side effect of blocking certain entries, is that SOME EXITS might be affected too. Say you have ApplyStops. ApplyStops regardless if they are "max loss", "trailing", "n-bar stop" all depend on ENTRIES (because price / bar of the entry changes when entry date changes). So all exits using stops will be affected. Not only that. If you have any other condition that is essentially CROSS() (like in your Sell statement), or any other impulse-form entry signal, it is also affected by entry, because if entry occurs AFTER that cross, the cross will not trigger (the NEXT cross would)

What "show actual trades" function does is to RUN SINGLE SECURITY BACKTEST ON THE FLY and display actual trades from SINGLE SECURITY BACKTEST.

It does NOT show trades from PORTFOLIO backtest.

Thanks, @Tomasz , you made it perfectly clear.

But I still do not understand why don't the buy and sell conditions work for the code posted in the 5th post in this thread in a portfolio backtest mode. Only one position at the time is taken for the whole available cash and sold later. There are no other trades that could block anything (see the log). There are no stops. There is no CBT. But for some obscure reason, selling still fails on the 4th occasion.

Besides that, the position is taken at the bar for which buy == 0. The buys and sells in the portfolio mode should be a subset of the buys and sells in the single security mode, shouldn't they?

you should share your APX file

I would love to but the user interface of the forum tells me that I can only upload jpg, jpeg, png and gif files.

I wrote you already, PREVIOUS trade blocked the next.

@Tomasz , I am sorry, but I really do not understand. The previous trade was enter FWLT 19.01.2007, exit 12.02.2007. Then there is enter BRL 12.02.2007, remaining long until 14.11.2024.

What blocks an earlier exit from BRL?

How come that the BRL is entered at a bar for which buy==0?

Actually, this seems to be a plotting issue:

_mfi = Ref(MFI(14), -1);
_pvi = Ref(PVI(), -1);

Buy = _mfi < 20;
Sell = int(_pvi) < int(Ref(_pvi, -1));

if (Plot_indicators == "buy/sell") {	   			   		
		Plot(Sell, "sell", colorAqua); 		 		 
		Plot(Buy, "buy", colorYellow);
		PlotGrid(1);   
}

Still wondering why doesn't the Sell trigger.

The failure to sell also happens when the backtest is run against a single symbol and only for some symbols.

image

You original post referenced the symbol BRL, which I believe is actually the delisted symbol that Norgate refers to as BRL-200812. The chart below shows both Buy and Sell signals in February of 2007.

The charts that you showed are for the symbol BLDR, as is the most recent example that you posted. While there are Sell signals on the BLDR chart, there are none in an Exploration or Scan of BLDR when you have Pad & Align enabled. Charts do not use Pad & Align, so this is why your signals differ. More specifically, if you create an Exploration that outputs PVI, and run it with Pad & Align enabled, you will see that the value of PVI() has been -0.00 since the inception of the stock. I'll leave it to you to figure out why this occurs, as I am not familiar with the PVI indicator.

@Tomasz

I isolated a testcase for this effect. Looks like a bug to me. The AB version is 6.93.

The formula:

_mfi = Ref(MFI(14), -1);
_pvi = Ref(PVI(), -1);

Buy = _mfi < 20;
Sell = int(_pvi) < int(Ref(_pvi, -1));

Raw signals:

The current trade arrows:

The result:
image

The data:
2007-03-01,51.25,52.39,50.65,51.56,2128600
2007-02-28,52.35,53.1,52.05,53.0,2201300
2007-02-27,56.42,56.57,54.95,54.95,919200
2007-02-26,56.39,56.66,56.25,56.51,529900
2007-02-23,55.47,55.47,55.4,55.45,500000
2007-02-22,55.34,55.47,55.2,55.47,407700
2007-02-21,54.9,55.44,54.89,55.34,470600
2007-02-20,55.15,55.24,54.84,55.08,459800
2007-02-16,55.0,55.3,54.68,55.0,532100
2007-02-15,54.4,55.21,54.3,55.0,683100
2007-02-14,54.15,54.61,54.12,54.25,482200
2007-02-13,53.7,54.0,52.74,53.93,780600
2007-02-12,53.54,53.64,52.78,53.43,511700
2007-02-09,53.71,53.93,53.32,53.64,375100
2007-02-08,53.3,53.98,53.3,53.75,377600
2007-02-07,53.15,53.63,52.61,53.55,953900
2007-02-06,53.7,53.95,52.8,53.22,553700
2007-02-05,53.8,53.8,53.38,53.73,521400
2007-02-02,54.45,54.63,53.54,53.97,440600
2007-02-01,53.7,54.5,53.65,54.2,481700
2007-01-31,53.6,54.0,53.4,53.52,321200
2007-01-30,54.52,54.75,53.3,53.6,998600
2007-01-29,55.05,55.05,54.25,54.54,648600
2007-01-26,54.8,55.07,54.53,54.77,736200
2007-01-25,55.53,55.54,54.48,54.77,923800
2007-01-24,55.8,56.15,54.9,55.47,1081300
2007-01-23,55.77,55.9,55.47,55.84,778900
2007-01-22,55.85,55.9,55.0,55.52,721500

Please do read @mradtke response. There are no bugs. The fact that you don't understand how feature works, does not constitute bug.

@mradtke , @Tomasz

Thanks, having Pad & Align checked really seems to be the cause of the issue.

[quote="Tomasz, post:16, topic:39780"]The fact that you don't understand how feature works, does not constitute bug.[/quote] No, of course not.

Could not respond earlier, caught the flu.