I am trying to solve an issue relating to overlapping signals and same bar conflicts. The primary issue is shown below as an image:
As highlighted, there are both Buy and Sell signals on 1/12/2021. Amibroker first exits the position from the previous entry (on 1/11/2021), and then enters into another position on the same day. The issue is that I am looking to Buy at the Open and Sell at the Close, thus there is a future leak I am trying to eliminate. To be clear, I do not want the trade highlighted in red to take place.
My code is below (and I have also attached the full analysis file for reference):
As per the first article, I have changed my settings to include a SettlementDelay of 1 and changed the backtest mode to backtestRegularRaw.
As per the second article, Scenario 3 in resolving same bar / same symbol conflicts above addresses part of my issue, however, I would like to retain the ability to exit intraday. I thus do not want to apply SetOption("HoldMinBars", 1 ).
Is there a way to address my issue without using CBT? My apologies in advance if this issue has been covered elsewhere, I have read through the forum and the knowledge base and have not found the answer to my problem.
Thank you for your response. I read through Scenario 3 and I do not believe my scenario is supported as the "trade that was just open can not be closed the same bar". To be clear, I would like trades to exit on the same bar so this does not apply to me.
Looking at Scenario 2, I run into the issue that an entry signal is processed following an exit (as shown in the image above).
In this case, should I rely on CBT in order to address my specific situation?
As you indicated in another post about the use of the Exrem() function and SetBacktestMode( backtestRegular ) it was clear to me that using Exrem() was redundant, since AB were already doing it internally with the SetBacktestMode( backtestRegular ) option.
In my case, I use the Exrem(buy, sell) solution tied to the code I use to mark the signals on the chart.
// DELETING EXTRASIGNAL
Buy = ExRem(Buy, Sell OR Short);
Short = ExRem(Short, Cover OR Buy);
Sell = ExRem(Sell, Buy);
Cover = ExRem(Cover, Short);
// PLOTTING ACTIVATION SIGNALS
distancia = 3*ATR(14);
for(i=0; i<BarCount; i++)
if(Buy[i]) PlotText("buy\n" + BuyPrice[i], i, H[i]-distancia[i], colorGreen);
if(Sell[i] AND !Short[i]) PlotText("sell\n" + SellPrice[i], i, L[i]+distancia[i], colorRed);
if(Short[i]) PlotText("short\n" + ShortPrice[i], i, L[i]+distancia[i], colorRed);
if(Cover[i] AND !Buy[i]) PlotText("cover\n" + CoverPrice[i], i, H[i]-distancia[i], colorGreen);
PlotShapes(IIf(Sell AND !Short,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell AND !Short ,shapeHollowCircle,shapeNone),colorRed,0,SellPrice,0);
PlotShapes(IIf(Cover AND !Buy,shapeUpArrow,shapeNone),colorDarkGreen,0,L,-15);
PlotShapes(IIf(Cover AND !Buy,shapeHollowCircle,shapeNone),colorDarkGreen,0,CoverPrice,0);
If I did not do this, it would display marks when the buy/sell conditions are met (which the backtest does not take into account when using SetBacktestMode( backtestRegular )).
I Signals actually taken by the backtest are displayed
However, if I remove the Exrem() functions from the code, despite the fact that the backtest does not take into account the redundant signals, since it is working with SetBacktestMode( backtestRegular ), they are painted on the graph.
Am I doing it right or should I take some other alternative?