N-bar exit with excess entry signals

Finally making progress with Seetu. However, hitting an issue with excess short signals. Let’s say I enter a short position, have some exit signals, but want to cover the position no matter what in 20 minutes (trading intraday on 1 minute bars).

No problem. I simply add to my cover:
OR BarsSince(Short) == 20

That should do it, yes? Well, yes, except let’s say there is a second Short signal at the 10 minute mark. In Amibroker, using the standard backtester, those extra entry signals are removed. However, in Seetu that doesn’t seem to be happening, and I’m getting trades that last way more than 20 bars, as the BarsSince(Short) keeps resetting to 0 due to a new Short signal while I’m still in the original trade.

My next thought was to use ExRemSpan(Short,20), but that’s both obsolete in Amibroker and not implemented in Seetu.

How can I backtest (and then send signals to an actual trading system) that cap at a certain duration (e.g. 20 bars) no matter what? Any help is appreciated.

I should add that the same problem is blowing up my profit target and stop loss in backtesting, as they are based on the ValueWhen(Short,Open)… but then additional Short signals happen prior to a Cover signal and the profit target and stop loss get based on the new Short signal bar.

How is it done in Amibroker? Yes, extra EXIT signals are removed. But ENTRY signals? I think it can happen only - say - you do not have cash or something like that. Or is there some setting for that there?

I think you need to clear unwanted entry signals in your code somehow.

Does not ExRem help?

BUY = ExRem( BUY, SELL );
SELL = ExRem( SELL, BUY );

and/or

SHORT = ExRem( SHORT, COVER);
COVER = ExRem( COVER, SHORT );

Good questions… first off, regarding Amibroker, see the description here.
https://www.amibroker.com/guide/afl/setbacktestmode.html

And the picture here that shows how the arrays / signals work.

But more importantly, the ApplyStop allows you to set non-volatile price points and durations using its various modes.
https://www.amibroker.com/guide/afl/applystop.html

So I guess the question is how to implement ApplyStop in the code. Your ExRem example doesn’t work if the Cover signal has a dependency on the Short signal. Let’s use a Stop Loss as an example.

Stop Loss = Short price (the Open of the short signal bar)

Coding a 3-point Stop Loss looks something like this.
myBarsSinceShort = BarsSince(Short);
myStopLoss = ref(Open-3,-myBarsSinceShort);
Cover = High >= myStopLoss;
CoverPrice = myStopLoss;

But now imagine each bar goes up 1 point, and every other bar generates a new Short signal. Every second bar ends up recalculating the myStopLoss based on the reset myBarsSinceShort and you never hit the Stop Loss… it gets higher and higher.

If you use ExRem, it does no good, because the values of the myStopLoss array are already calculated… even if you remove signals, the values remain unchanged. And you can’t remove those signals until you calculate the Cover signals… which never hit.

Make sense? Not sure what to do. I’ve betting the actual trade signals will work, as they will make the Stop Loss and Profit Target static. But that won’t let me do an N-bar stop, and I can’t test any of it. I’ve tested it in Amibroker, but I need to test it here to make sure it is behaving as expected.

Well, the Amibroker picture shows that EXIT signals are removed. Not ENTRY signals.

I think that the trick would be to not allow to generate the excessive SHORT signals at all.

Something like: Short = [your Short logic] AND BarsSince(Short) > 20;

Does it make sense?

Yes. I’ve been testing that approach since I posted. The main issue I’m trying to overcome is that I end up losing a lot of good entry signals. I have a very tight profit target, so most trades are pretty quick. When I use the longer barssince, everything works but I have far fewer total trades. Still working on it.

How about “less than”?
[Cover logic ] OR ( BarsSince(Short) < 21 )

or not to close too fast:

( [Cover logic ] AND (BarsSince(Short) > 5)) OR BarsSince(Short) <= 20 ??