March 1, 2022 at 2:34 am #67613
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.12345678910//Define the 1st signalV1 = RSI(Week(PERIODAMOUNT=1)) >= 70 ;//Define the signal 2nd signalV2 = RSI(Week(PERIODAMOUNT=1)) >= 40 ;//Color the bar when V2 is true after V1 occursV3 = SIGNALAFTER(V1, V2, Week(PERIODAMOUNT=1)) ;V4 = IF(V3, 2, 1) ;V4 == 2March 1, 2022 at 11:05 am #67616
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:123456V1 = RSI();SIG1 = V1 CrossesAbove 70;SIG2 = V1 CrossesAbove 40;SWITCH(Sig2,Sig1)
Here’s a chart example.
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:123456V1 = RSI();SIG1 = V1 CrossesAbove 70;SIG2 = V1 CrossesAbove 40;SWITCH(Sig2,Sig1) and V1 > 40
March 1, 2022 at 12:14 pm #67619
- This reply was modified 3 months ago by Matthew.
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.March 1, 2022 at 12:52 pm #67620
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.
Green Script:123456V1 = RSI();SIG1 = V1 CrossesAbove 70;SIG2 = V1 CrossesBelow 40;SWITCH(Sig1,Sig2)
Red Script123456V1 = RSI();SIG1 = V1 CrossesBelow 30;SIG2 = V1 CrossesAbove 60;SWITCH(Sig1,Sig2)
1 user thanked author for this post.March 1, 2022 at 1:12 pm #67621
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.March 1, 2022 at 1:49 pm #67622
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?March 1, 2022 at 2:11 pm #67623
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.
- You must be logged in to reply to this topic.