Colour coding the bars

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #79838 quote
    TraderB
    Participant
    New

    Hello,

    Complete noob when it comes to coding (am trying my best to learn!), so any help is greatly appreciated. Is it possible to colour code the bars that close outside the bollinger bands?

    Ex. (Note, my candlestick colour scheme is black/white)

    Candle(s) close outside the upper bollinger band, it gets painted blue.

    Candle(s) close outside the lower bollinger band, it gets painted red.

    Thank you.

    #79839 quote
    robertogozzi
    Moderator
    Master

    There you go. I tested it on EurUsd daily and it worked:

    defparam calculateonlastbars=500
    //  construction of Bollinger Bands
    BBVal      = 20                                      //20   periods
    BBdev      = 2.0                                     //2.0  Deviation
    BBavg      = Average[BBval,0](close)                 //BB mean (middle line)   0=sma
    BollUP     = BBavg + ((std[BBval](close)) * BBdev)   //Bollinger Upper Band
    BollDN     = BBavg - ((std[BBval](close)) * BBdev)   //Bollinger Lower Band
    //  initialize colours to null
    r=0
    g=0
    b=0
    //  set colours when due
    if close > BollUP then
       b=255
    elsif close < BollDN THEN
       r=255
    endif
    //  display candlestick, if above/below BB
    IF (r + g + b) <> 0 THEN
       DRAWCANDLE(open,high,low,close) COLOURED(r,g,b,255) //BORDERCOLOR(0,255,0,255)
    ENDIF
    RETURN
    #79840 quote
    TraderB
    Participant
    New

    Roberto, many many thanks for this!

    Question, if I was to replace bollingers and use the Keltner Channels found here (https://www.prorealcode.com/topic/keltner-channel-2/), would it work the samw?

    #79841 quote
    robertogozzi
    Moderator
    Master

    It is, this is the modified code:

    defparam calculateonlastbars=500
    //  construction of Bollinger Bands
    a = average[20,0](customclose)
    b = AverageTrueRange[20](close)
    co= 1.5
    //mm = a       //middle line
    hi = a + co*b  //Upper Limit
    lo = a - co*b  //Lower Limit
    //  initialize colours to null
    r=0
    g=0
    b=0
    //  set colours when due
    if close > hi then
       b=255
    elsif close < lo THEN
       r=255
    endif
    //  display candlestick, if above/below Channel's limits
    IF (r + g + b) <> 0 THEN
       DRAWCANDLE(open,high,low,close) COLOURED(r,g,b,255) //BORDERCOLOR(0,255,0,255)
    ENDIF
    RETURN
    #79842 quote
    robertogozzi
    Moderator
    Master

    I added line 5.

    #79843 quote
    TraderB
    Participant
    New

    Roberto,  thank you for providing this! This works great!

    #190370 quote
    Radetzky
    Participant
    Senior

    Good evening Roberto:

    is it possibile to get the same system but with the intraday stocastic indicator ???

    specifically smoohed stochastic 5.3.3     80/20

    overbought entry red colored bar    >80

    entry into oversold green colored bar     <20

    THANK YOU

    #190378 quote
    Nicolas
    Keymaster
    Master

    I think that this indicator that color candlesticks based on the chosen oscillator might be of interest to you: 3D Candlesticks (CCI,RSI,Stochastic,Cycle,DI)

    #190679 quote
    Radetzky
    Participant
    Senior

    Thanks Nikolas but i’m not able to edit a script … i’ll ask roberto on the italian forum to specify better.. ..  Tank you

    #190703 quote
    robertogozzi
    Moderator
    Master

    There you go:

    //  Stochastic
    Kline = Stochastic[5,3](close)
    Dline = Average[3](Kline)
    OB    = 80
    OS    = 100 - OB
    //  initialize colours to null
    r=0
    g=0
    b=0
    //  set colours when due
    if Kline > OB then
       r=255
    elsif Kline < OS THEN
       g=255
    endif
    //  display candlestick, if above/below limits
    IF (r + g + b) <> 0 THEN
       DRAWCANDLE(open,high,low,close) COLOURED(r,g,b,255) //BORDERCOLOR(0,255,0,255)
    ENDIF
    RETURN
    #190871 quote
    Radetzky
    Participant
    Senior

    Grazie Roberto  ..fine settimana lo provo

    per l’intanto grazie per la gentilezza

    TANKS ROBERTO !

    #190876 quote
    Radetzky
    Participant
    Senior

    Grazie Roberto ..fine settimana lo provo

    per l’intanto grazie per la gentilezza

    TANKS ROBERTO !

    Gia testato  ok perfetto  … solo un’ultima  richiesta se possibile :

    è possibile invertire  i colori ?  il verde in ipercomprato / rosso in ipervenduto ? Grazie
    ……………

    Already tested ok perfect … just one last request if possible: is it possible to invert the colors? green overbought / red oversold? Thanks

    #190879 quote
    robertogozzi
    Moderator
    Master

    Swap lines 12 and 14.

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

Colour coding the bars


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
TraderB @traderb Participant
Summary

This topic contains 12 replies,
has 3 voices, and was last updated by robertogozzi
3 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/05/2018
Status: Active
Attachments: No files
Logo Logo
Loading...