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();