RSI chart overlay – color questions

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #40032 quote
    AVT
    Participant
    Senior

    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 :

    1. 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).
    2. 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.
    3. 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):

    // --- 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 option
    UpperRSIband1 = RSIupperBorder1 // default: 65 fixed
    UpperRSIband2 = RSIupperBorder2 // default: 75 added
    LowerRSIband1 = RSIlowerBorder1 // default: 35 fixed
    LowerRSIband2 = 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 values
    IF ColorR < 0 OR ColorR > 255 THEN
    ColorR = 128
    ELSE
    ColorR = RGBred
    ENDIF
    IF ColorG < 0 OR ColorG > 255 THEN
    ColorG = 128
    ELSE
    ColorG = RGBgreen
    ENDIF
    IF ColorB < 0 OR ColorB > 255 THEN
    ColorB = 128
    ELSE
    ColorB = RGBblue
    ENDIF
    // === Variables End
    
    // === Calculation Begin
    RSIval = RSI[RSIlength](close) // MUST be close, otherwise a mess with drawsegment
    prevRSI = RSI[RSIlength](close[1]) // drawsegment needs a begin
    // === Calculation End
    
    // === Drawing Begin
    // --- the rsi line
    DRAWSEGMENT(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 above
    DRAWSEGMENT(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 above
    DRAWSEGMENT(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 End
    RETURN
    // === Program End

     

    Thanks for your help.

    #40035 quote
    AVT
    Participant
    Senior

    uuppsss .. above html is missing the end pre statement, should I post the whole stuff again?

    #40036 quote
    Nicolas
    Keymaster
    Master
    1. this setting is in all indicator, since you define RGB values in the code, this controller has no effect, that’s right
    2. 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:

    R = max(1,Red)
    R = min(255,Red)
    
    return variable coloured(R,0,0)

    (not tested!)

    3. solved by the code above?

    AVT thanked this post
    #40039 quote
    AVT
    Participant
    Senior

    2. 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

    IF RGBred < 0 OR RGBred > 255 THEN 
    ColorR = 128
    ELSE
    ColorR = RGBred
    ENDIF
    IF RGBgreen < 0 OR RGBgreen > 255 THEN
    ColorG = 128
    ELSE
    ColorG = RGBgreen
    ENDIF
    IF RGBblue < 0 OR RGBblue > 255 THEN
    ColorB = 128
    ELSE
    ColorB = RGBblue
    ENDIF

    never overestimate a coders code :-))

    #40040 quote
    AVT
    Participant
    Senior

    Thanks, 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

    // --- limit color value to be 0-255 only
    R = 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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

RSI chart overlay – color questions


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
AVT @avt Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by AVT
8 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/07/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...