Page 1 of 1

Detect if a condition happened within last 5 bars

Posted: Thu May 16, 2024 5:00 am
by anon
We are attempting to develop a script that basically
says : If there was a RSI(C,2) cross of 25 level within the last 5 bars,
continue to conditions 2.

I have been attempting this with the BACKSET
command which compiles but does generate
any signals and shows NaN in the event window.
backsetquestion.png
backsetquestion.png (105.9 KiB) Viewed 1581 times
Any suggestions?

Thanks

Re: Detect if a condition happened within last 5 bars

Posted: Thu May 16, 2024 5:06 am
by Chris White
You could use BARSSINCE. Here’s an example:

Code: Select all

rsicross: CROSS(RSI(C,2), 25);
bscross: BARSSINCE(rsicross);

cond1: bscross < 5;
barssinceexample.png