Using Signal After In A Custom Color Script

Hi,

I am trying to color an RSI plot. I want the plot to show green when RSI is above or at 40, after the plot was at or above 70. I have the following script, but I cannot get it work as a custom color script or as a show bar. I have tried it with and without the last 2 lines. I have tried deleting the period amount from the signalafter line. Please advise. Thank you.

//Define the 1st signal 
V1 = RSI(Week(PERIODAMOUNT=1)) >= 70 ; 
//Define the signal 2nd signal 
V2 = RSI(Week(PERIODAMOUNT=1)) >= 40 ; 
//Color the bar when V2 is true after V1 occurs 
V3 = SIGNALAFTER(V1, V2, Week(PERIODAMOUNT=1)) ; 
V4 = IF(V3, 2, 1) ; 
V4 == 2

Hi,

From what i understand you want the plot to be one colour once the RSI crosses above 70, then stay that way until the plot crosses above 40? Then it stays green until it goes back above 70 again?

If so, this script would work:

V1 = RSI();
SIG1 = V1 CrossesAbove 70;
SIG2 = V1 CrossesAbove 40;
SWITCH(Sig2,Sig1)

Here’s a chart example.

Ex4

If the plot always has to be above 40 to be green, even if it hasn’t crossed above 70 again, this script would work:

V1 = RSI();
SIG1 = V1 CrossesAbove 70;
SIG2 = V1 CrossesAbove 40;
SWITCH(Sig2,Sig1) and V1 > 40

Chart example:

Ex5

Hi Matthew. Thank you for these options. I am sorry that I was not clear. Please let me try again.

If the RSI plot touches 70 or greater, the RSI plot should be green as long as it remains above 40, so in the range of 40 to 100.
If the RSI plot touches 30 or less, the RSI plot should be red as long it remains below 60, so in the range of 0 to 60.

I want the RSI plot to be green if the range has been between 40 and 100 and to be red if the range has been between 0 and 60.

I hope this makes more sense now. Thank you.

Hi,

You’d need two scripts, using the same setup as my original reply with the SWITCH() function.

  • One for the Green colour rules (Trigger 1 crossing above 70, Trigger 2 crossing below 40).
  • One for the Red colour rules (Trigger 1 crossing below 30, Trigger 2 crossing above 60).
The end result would be an RSI with 3 colour states. Green, Red (using the rules above), and black for when neither rule is met.

Ex8

Green Script:

V1 = RSI();
SIG1 = V1 CrossesAbove 70;
SIG2 = V1 CrossesBelow 40;
SWITCH(Sig1,Sig2)

Red Script

V1 = RSI();
SIG1 = V1 CrossesBelow 30;
SIG2 = V1 CrossesAbove 60;
SWITCH(Sig1,Sig2)

Now we’re getting closer. This is it, except I want to eliminate the black and just have it always either green or red.

It is green if between 40 and 100 after being at 70 or above, or it is red if between 0 and 70 after being at 30 or below.

Hi,

What colour are you expecting to see after the RSI line crosses above 70, then drops below 40 while we wait for the second rule to come into place (crossing below 30)? From what I can see there is an undefined range between 39 - 31 in that scenario that would still be black.

Should the rule be Green if between 30 and 100 after being at 70 or above?

Touche’ Matthew. You are a clever man. You have given me the scrips to do exactly what I asked. I didn’t realize there would be that undefined range before the 2nd rule triggers. This will work. Thank you for following up.