Persistency of X

Hello,

I’m looking to establish Persistency (PS) of certain criteria over a set amount of time, for example 20 day PS of Money Flow Index > 50 would indicate that the MFI has been over 50 for more than 20 days or essentially any indicator you’re looking at above or below whatever threshold for more than whatever period. I’ve tried TIMESINCESIGNAL using the reverse thinking but not sure what to do with the repeats after the initial trigger.

Hi,

I would use the BarsTrue() function to find the point where MFI has been above 50 for 20 bars, then use switch to keep the value true until the MFI crosses below 50.

//Set Money Flow Index
V1 = MFI() ;
//Is MFI Higher than 50
V2 = V1 > 50;
//MFI crosses below 50
V3 = V1 CrossesBelow 50;
//MFI has been higher than 50 for 20 days
V4 = BARSTRUE(V2, LOOKBACK=20) == 20;
//MFI higher than 50 for 20 bars, switch to false after MFI crosses below 50
SWITCH(V4,V3)

Chart example:

Ex6

This is excellent, thanks a lot