Sell signal generation difference between backtest of 1 recent day(s) and explore with last bar(s)

I am using Explore in the Analysis window to open and close positions in Interactive Brokers using Range of 1 recent bar(s). At the moment it is only connected to IB's paper trading account.
At the end of each trading day, I also run a backtest using range of 1 recent day(s) to compare the day's results.

In my code, I use the Filter function to check whether conditions hold true for a buy or sell signal as well as all relevant values/conditions that leads to a buy or sell signal.

Problem:
I noticed that in forward testing, my positions seemed to remain open for far longer than expected. I went and specifically chose a symbol where on the close of the trading day should generate a sell signal. On Explore, the values/conditions that lead to a positive sell signal indicated that a sell signal should have been generated but no sell signal was given. On backtesting for the day on that same symbol, a position was opened and more specifically exited on the last bar of the chart as was expected.

I am struggling to understand why the sell signal worked in backtesting using the last day range but did not trigger during Explore of the last bar during forward testing. If anyone could shed some light on how to rectify it so that sell signals generate in the same way for backtesting and explore, I would greatly appreciate it.

@juliev, without your code, we can only really guess.

Are you using the same afl for explore and backtest?

If you are using an Exploration, you should be able to show all of the conditions, and see if it all works as you expect.

My GUESS is that you are either running two different afl's (and they are out of sync), or you have accidentally recalculated something in the different code areas between your backtest and exploration.

Thanks for your response, snoopy.pa30.
I do use Exploration to also show all of the conditions that lead to a buy or sell signal.
I run the Exploration on a portfolio of equities. I have just gone over the last Exploration for the day. Some of the equities showed that the conditions held true for a sell signal which resulted in a sell signal but for others even though the conditions held true, no sell signal was given. It is this anomaly I am trying to resolve.
Could you give me a bit more detail about what you mean that the afl's are out of sync?
I use the ExRem() function to prevent duplicate trades in my backtesting afl but not for my forward testing so I am not expecting the afl to be out of sync.
Many thanks.

@juliev, The "out of sync" only applies if you have different code for backtest and for exploration.

The best thing you can do is post your code. Remember to use code tags as per forum rules.

We can't guess what the coding error is. We need to see the code and try it ourselves.

If you have something that is "proprietary", then you will have to make a simpler version, that shows the same issue and let us work with that code.

Snoopy

Thanks, Snoopy. The code is "proprietary" so I will work on recreating the error with different code and post again.

I have managed to create another piece of code that generates the same issue. Here is the code below.

StopLossPC = Param( "Stoploss Percentage", 1, 1, 30, 1 );		
kPeriod = Param("Stochastic kPeriod", 5, 3, 50, 1);
kSlowing = Param("Stochastic kSlowing", 3, 2, 20, 1);
dPeriod = Param("Stochastic dPeriod", 3, 2, 20, 1);

MaxPositions = 10;
DefaultPositionSize = 1;
RoundLotSize = 1;
SetOption("MaxOpenPositions", MaxPositions);
SetOption("AllowSameBarExit", True);
BuyPrice = Open;
SellPrice = Close;
ShortPrice = Open;
CoverPrice = Close;
SetPositionSize(DefaultPositionSize, spsShares);


//Logic for buy/sell signals
TimeFrameSet(in15Minute);
FifteenBuy = StochK(kPeriod, kSlowing) <= 35;
TimeFrameRestore();

StochasticBuy = StochK(kPeriod, kSlowing) <= 20 AND StochD(kPeriod, kSlowing, dPeriod) < StochK(kPeriod, kSlowing);

BuySignalOne = StochasticBuy AND TimeFrameExpand(FifteenBuy, in15Minute);

ExitLongSignal = StochK(5,3) >= 55;

//LONG POSITION
Buy = Ref(BuySignalOne, -1);
Sell = Ref(ExitLongSignal, -1);


//Stop loss
ApplyStop( stopTypeLoss, stopModePercent, StopLossPC, 1, True);
Equity( 1, 0 ); // eval stops 


Filter = 1;
AddColumn( IIf( Buy, 'B', 'E' ), "BuySignal", formatChar );
AddColumn( IIf( Sell, 'S', 'E' ), "SellSignal", formatChar );
AddColumn(Ref(ExitLongSignal, -1), "exit long signal");
AddColumn(Ref(BuySignalOne, -1), "BuySignalOne");

It doesn't generate a SellSignal even though the ExitLongSignal indicates that the logic holds true during forward testing using Explore. Analysis settings Periodicity is set to 5 minutes with AutoRepeat set to 5minutes.
Thanks in advance for any suggestions to elliminate this issue.