Getting Entry Even Through Exit on Same Bar

I have a strategy that is greatly simplified for the purpose of my question. If conditions are met, a stock is purchased at the close. The stock is sold the next day when it has a one-half percent profit. If the profit isn't reached, the stock is sold at the close regardless of the price.

However, regardless of what happens on the day after a stock is bought, I want to buy it again at the close if the conditions are met.

When I run the backtest, the backtest does not provide for an entry on the day of an exit.

I have spent a lot of time trying to figure out how to allow an entry on the day of an exit. It appears to me that most others who have posted have had an issue with avoiding an entry on the day of an exit. But my difficulty is the opposite.

I did go to settings and check the box that states "Allow same bar exist/entry signal." This didn't resolve it. Hopefully, there is something simple that I am missing.

The formula is below. If I run it on IWM, there are entries on 1/27/21 and 1/29/21, but 1/28,21 is not included in the results even though there also would have been an entry on the close that day.

_SECTION_BEGIN ("RG");
//=================================================================================
//Parameters
//=================================================================================

SetOption("AllowSameBarExit", True );
SetOption("priceboundchecking",True);
PositionSize = 100000;
Capital = 2000000;
SetOption("MaxOpenPositions", 10);


BBBot = BBandBot(C,10,1.6);

//=================================================================================
//Entry & Exit
//=================================================================================

Cond1 = C < BBBot ;

LE = Ref(Cond1,0) ;
LEPrice = Close;

//---------------------------------------------------------------------------------
ExitBars = 1;
ProfitFactor = 1.005 ;

//---------------------------------------------------------------------------------
Buy 			= 0;	
Sell 			= 0; 								
PriceAtBuy 		= 0;	
LBIT 			= 0;
ProfitTarget	= Null;	
//=================================================================================
for (j = 1; j < BarCount; j++)														
{													
	if (PriceAtBuy==0 AND LE[j]) 	
	{												
	 Buy[j] = True;										
	 PriceAtBuy = LEPrice[j];						
	 BuyPrice[j] = LEPrice[j];
	 ProfitTarget[j] = PriceAtBuy * ProfitFactor; 												
	 LBIT[j] = 1;																				
	}												
	
	else																												
	if (PriceAtBuy > 0)													 
	{												
	 LBIT[j] = LBIT[j-1]+1;	
	 ProfitTarget[j] = ProfitTarget[j-1];																	
		
		if (LBIT[j] > ExitBars)			 						
		{											
		 Sell[j] = True;									
		 SellPrice[j] = Close[j];						
		 PriceAtBuy = 0;																			
		}
		
		if (LBIT[j]>1 AND H[j] >= ProfitTarget[j-1])								
		{
		 Sell[j] = True;										
		 SellPrice[j] = Max(Open[j],ProfitTarget[j-1]);				
		 PriceAtBuy = 0;										
		}																	
	}												
}							
Short = False;
Cover = False;
//---------------------------------------------------------------------------------
_SECTION_END();

You need to read the manual carefully on backtesting Portfolio-level back testing, especially section titled RESOLVING SAME BAR, SAME SYMBOL SIGNAL CONFLICTS

Thank you for the suggestion. I carefully read the manual and tried various revisions, none of which resolved the issue. I had hired someone several years back to come up with the formula, and it appears that they also missed the issue. I think it is a difficult and complex matter to resolve even for an experienced user.

Did you end up getting a solution to this?

Because I couldn't figure it out by reading the manual and no one else responded, I contacted someone who I was willing to pay and ended up being kind enough to provide the simple fix without requiring payment.

1 Like

I’d like to discuss some mean reversion systems with you, but this forum isn’t the right place for it, and I dont think there is private messaging on this site. Are you on Twitter? I’m 6j7

Just click the person's name and then the Message button to send them a private message.

1 Like

I can’t see the option for messaging? This is what I get when I click on your name
image

Here's what I see when I click on your name. It appears you need to "earn" permission to use the PM features. See this article on Trust Levels within Discourse: Understanding Discourse Trust Levels

image

1 Like

Basic user (Level 1) is not allowed to start private message. Unfortunatelly PM system was abused in the past and now Level 2 is required to post PM.

I don't use Twitter, and not sure how to get in contact with you. I could post an email address, but I suspect the forum won't like that.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.