RSI chart overlay – color questions
Forums › ProRealTime English forum › ProBuilder support › RSI chart overlay – color questions
- This topic has 4 replies, 2 voices, and was last updated 7 years ago by AVT.
-
-
07/07/2017 at 3:33 PM #40032
This puts the RSI into the chart window; works on GDI and DJI (position has still a heavy thinking mistake, I will do this later). I have 2 questions with regard to user color adjustments – maybe they are related :
- What in the code is causing the “color adjustment” (the red mark in the picture). I am defining the RGB values separately and playing with it does not have any effect (kind of useless).
- I made the RGB values separately with this kind of variable: RGBred[128] (type: integer). So far so good but never underestimate what users do, I simulated a user pushing the down-arrow in the adjustment menu for the red color until (the RGB value below zero) – the whole indicator crashed out of the window with “Color parameter outside of expected rang: Red”. Setting the color to default if the RGBred is out of limit did not work.
- I already tried this: simply go without all color statements and the coloured(r,g,b). This results in a “color adjustment” menu for the user but does not have any effect – just like in 1.
Here is the code (sorry for my heavy commenting):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657// --- we want it in the chart, so the zero-line must be somewhere near the bars// !!! TODO: see below// --- does not work: color change of line dependend on RSI exeeding borders// drawsegment begins coloring too early (prev bar to bar), so draw simple line// === Variables Begin// --- variables for calculation// RSIlenth: although strategy fixed (default: 9), added changing option// RSIupperBoder and RSIlowerBorder: fixed by strategy but added optionUpperRSIband1 = RSIupperBorder1 // default: 65 fixedUpperRSIband2 = RSIupperBorder2 // default: 75 addedLowerRSIband1 = RSIlowerBorder1 // default: 35 fixedLowerRSIband2 = RSIlowerBorder2 // default: 30 added// --- variables for painting// RSIzeroLine: MUST be user adjustable, NOT type integer in case it's used for forex// !!! TODO: heavy thinking mistake: just +/- 100 does not work in markets with low price (fx,shares..)// !!! TODO: maybe make it percent of price// --- colors: user must be able to change them (depending on chart background)// !!! this does not help against user crashing with exeeding the valuesIF ColorR < 0 OR ColorR > 255 THENColorR = 128ELSEColorR = RGBredENDIFIF ColorG < 0 OR ColorG > 255 THENColorG = 128ELSEColorG = RGBgreenENDIFIF ColorB < 0 OR ColorB > 255 THENColorB = 128ELSEColorB = RGBblueENDIF// === Variables End// === Calculation BeginRSIval = RSI[RSIlength](close) // MUST be close, otherwise a mess with drawsegmentprevRSI = RSI[RSIlength](close[1]) // drawsegment needs a begin// === Calculation End// === Drawing Begin// --- the rsi lineDRAWSEGMENT(barindex-1,rsiZeroLine+prevRSI,barindex,rsiZeroline+RSIval) coloured(ColorR,ColorG,ColorB)// --- for orientation: zero line and the limit 100 (can not be more than this)// !!! TODO: see aboveDRAWSEGMENT(barindex-1,rsiZeroLine,barindex,rsiZeroline) coloured(ColorR,ColorG,ColorB)DRAWSEGMENT(barindex-1,rsiZeroLine+100,barindex,rsiZeroline+100) coloured(ColorR,ColorG,ColorB)// --- the border lines// !!! TODO: see aboveDRAWSEGMENT(barindex-1,rsiZeroLine+UpperRSIband1,barindex,rsiZeroline+UpperRSIband1) coloured(ColorR,ColorG,ColorB)DRAWSEGMENT(barindex-1,rsiZeroLine+UpperRSIband2,barindex,rsiZeroline+UpperRSIband2) coloured(ColorR,ColorG,ColorB)DRAWSEGMENT(barindex-1,rsiZeroLine+LowerRSIband1,barindex,rsiZeroline+LowerRSIband1) coloured(ColorR,ColorG,ColorB)DRAWSEGMENT(barindex-1,rsiZeroLine+LowerRSIband2,barindex,rsiZeroline+LowerRSIband2) coloured(ColorR,ColorG,ColorB)// === Drawing EndRETURN// === Program EndThanks for your help.
07/07/2017 at 3:42 PM #4003507/07/2017 at 3:42 PM #40036- this setting is in all indicator, since you define RGB values in the code, this controller has no effect, that’s right
- you can try to make something like this:
let’s imagine you have a “red” variable defining the R, set it as an external variable for the user to select the value and put this into your code:
1234R = max(1,Red)R = min(255,Red)return variable coloured(R,0,0)(not tested!)
3. solved by the code above?
1 user thanked author for this post.
07/07/2017 at 4:18 PM #400392. solved, testing the wrong variables: we must test the user adjustable ones with the names “RGBred, RGBgreen, RGBblue” against exeeding values, correct code should be
test exeeding color values123456789101112131415IF RGBred < 0 OR RGBred > 255 THENColorR = 128ELSEColorR = RGBredENDIFIF RGBgreen < 0 OR RGBgreen > 255 THENColorG = 128ELSEColorG = RGBgreenENDIFIF RGBblue < 0 OR RGBblue > 255 THENColorB = 128ELSEColorB = RGBblueENDIFnever overestimate a coders code :-))
07/07/2017 at 4:58 PM #40040Thanks, you were quicker than me (and shorter in code lines, too).
Yep, this works: setting user adjustable (external) R[128] type integer plus G[128] type integer plus B[128] integer.
Then
avoid user crashing colors12345678// --- limit color value to be 0-255 onlyR = max(0,R)R = min(255,R)G = max(0,G)G = min(255,G)B = max(0,B)B = min(255,B)// --- draw whatever you want with coloured(R,G,B)There’s still this useless “color adjustment” – but I can live with that. I guess this is created by simply calling one of the builtin indicators. If I use for example RSI[9] only, I get in the user adjustment area not only the “color adjustment” but also the “price adjustment”. To avoid users playing with the price, I did already explicitly set RSI[9](close) – and got rid of the “price adjustment”.
I will go with your suggestion, short and clean, the way it should be. Thanks a lot.
-
AuthorPosts
Find exclusive trading pro-tools on