Combing Multiple TimeSinceSignal Conditions

I am seeking to define a TimeSinceSignal condition that returns the time since a variable crosses above 3, but remains above 0. I have tried the ScripterBot, but do not get any results. The Offset seems misplaced, but removing that in the script below still does not yield results.

// Define the condition for TimeSinceSignal to be greater than 3
v1 = TimeSinceSignal() > 3; // TimeSinceSignal greater than 3

// Define the condition for TimeSinceSignal to be less than 1
v2 = TimeSinceSignal() < 1; // TimeSinceSignal less than 1

// Create a signal that is true when TimeSinceSignal crosses above 3
signalCrossAbove3 = SIGNALAFTER(v1, v1 AND OFFSET(v1, OFFSET=1) <= 0); // Signal when it crosses above 3

// Create a signal that is true when TimeSinceSignal falls below 1
signalFallBelow1 = v2; // Signal when it falls below 1

// Count the number of days since the signal crossed above 3 and has not fallen below 1
countDays = ACCSINCESIGNAL(signalCrossAbove3, signalFallBelow1); // Count days since the signal crossed above 3

// Output the count of days
countDays; // This will return the number of days since the condition was met

Many thanks in advance,

Eric

Hi Eric,

The condition you are measuring (let’s call it Sig1) has to be within the parentheses ie TimeSinceSignal(Sig1)>3.

If your condition is using a Switch() function between 3 and 0 then maybe you could use that variable in the TimeSinceSignal function?

This example counts how long the switch has been ‘on’ ie the first RSI cross above 70 since being < 30:

Sig1=SWITCH(RSI(BARS=14)<30, RSI(BARS=14)>70);
TIMESINCESIGNAL(Sig1==1)

So it’s been 518 days since $XLC crossed above 70 the first time after being < 30 (and yesterday was the 17th time it has crossed above 70 since then):

Thank you Darren. The Switch condition was the tick I needed.

1 Like