Moving Average RSI Hybrid Line
Forums › ProRealTime English forum › ProBuilder support › Moving Average RSI Hybrid Line
- This topic has 8 replies, 3 voices, and was last updated 7 years ago by juanj.
-
-
09/24/2017 at 12:36 PM #47126
Good Day
I only recently started playing around coding and more specifically graphing indicators.
I am looking to create a simple indicator that works and functions exactly like a standard moving average line except the color of the line is dependent on the position of the RSI2 period.
Variables should be as follows:
RSI Period: i.e. 2
Moving Average Period: i.e. 21
Moving Average Type: i.e. 2 (Exponential)
RSI Top Threshold: 90
RSI Bottom Threshold: 10Thus as long as the RSI Period is within the threshold, the moving average line is black.
If the RSI is above the threshold the line is red and if below blue.09/24/2017 at 2:00 PM #4713609/24/2017 at 2:32 PM #4713909/24/2017 at 3:04 PM #47142You can do it with just your one line, just use an if statement to define the 3 variables r, g, b according to your various rsi thresholds so that each set of r,g,b defines each of the 3 colours you want, and then use them in the color definitions in your return line “return myma coloured (r,g,b)”
1 user thanked author for this post.
09/24/2017 at 3:20 PM #4714409/24/2017 at 4:49 PM #47148Excellent idea Noobywan. A little related problem I had 2 days ago. If i use drawhline to draw a line and then I want it to disappear again. How can this be done? Just painting over with white doesn’t work since the background of PRT is not white. :-S
09/24/2017 at 5:19 PM #47152In the context of being able to keep some graphic objects drawn on previous bars while deleting some others, I haven’t found a way to selectively make lines disappear because of background as you said, however if keeping previous graphic elements doesn’t matter, then adding at the beginning of the code the line:
1defparam drawonlastbaronly=truewill allow you to keep only the horizontal line you’ve defined on the last bar (and so it needs to be defined at each bar even if it doesn’t move), but it will delete anything else drawn on previous bars
1 user thanked author for this post.
09/24/2017 at 9:41 PM #4716109/24/2017 at 9:51 PM #47164Thanks, Guys, implemented it as follows:
123456789101112131415161718192021222324252627282930313233//variables to add://RSIPeriod (Default: 2)//MAPeriod (Default: 21)//MAType (Default: 2)//RSIUpperThreshold (Default: 95)//RSILowerThreshold (Default: 5)myrsi=RSI[RSIPeriod](close)myma=Average[MAPeriod,MAType](close)if myrsi>RSIUpperThreshold thenr=255g=0b=0Elsif myrsi<=RSIUpperThreshold and myrsi > 50 thenr=0//255g=0//145b=0//164elsif myrsi<RSILowerThreshold thenr=0g=255b=0Elsif myrsi>RSILowerThreshold and myrsi < 50 thenr=0//173g=0//255b=0//47Elsif myrsi = 50 thenr=0g=0b=0endifreturn myma coloured(r,g,b) as "Hybrid MA" -
AuthorPosts
Find exclusive trading pro-tools on