Bar colour related to ATR

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #159845 quote
    Prodsaaw
    Participant
    New

    I am looking for the code to change the colour of the bar to purple when the close is greater than the ATR * 1,5 . The colour change also applicable on bars of historic charts

    Any suggestions are appreciated.

    #159852 quote
    robertogozzi
    Moderator
    Master

    CLOSE is a price, ATR is a price range (difference in price).

    CLOSE will always be > ATR.

    #159856 quote
    Prodsaaw
    Participant
    New

    Thanks a lot for your quick reply.

    Actually what I should have written:

    When (high – low) > (ATR * 1,5) colour of bar to  change to purple.

    Thanks.

    #159865 quote
    robertogozzi
    Moderator
    Master

    There you go:

    MyAtr = AverageTrueRange[14](close) * 1.5
    IF Range > MyATR THEN
       DrawCandle(Open,High,Low,Close) coloured(180,82,205,255)
    ENDIF
    RETURN

    add it to the price chart (not below).

    Choose colours at http://cloford.com/resources/colours/500col.htm.

    Prodsaaw thanked this post
    #159871 quote
    Prodsaaw
    Participant
    New

    Fantastic, much appreciated,

    #159998 quote
    coenw
    Participant
    New

    I realise now that due to the change of the colour of the bar, I am not able to see whether it is a bullish or a bearish bar.
    Would it be possible to add a marker above the bar in the event of a bullish bar or a marker below the bar in the event of a bearish bar.

    Thanks a lot in advance.

    Coen

    #160002 quote
    robertogozzi
    Moderator
    Master

    There you go:

    MyAtr = AverageTrueRange[14](close) * 1.5
    IF Range > MyATR THEN
       DrawCandle(Open,High,Low,Close) coloured(180,82,205,255)
       If close > open then
          DrawText(“*”,barindex,high + range)
       Else
          DrawText(“*”,barindex,low - range)
       Endif
    ENDIF
    RETURN

    if bullish “*” will be plotted above the candle, below otherwise.

    coenw thanked this post
    #160020 quote
    coenw
    Participant
    New

    Thanks a lot, works great!

    #175001 quote
    efahmy
    Participant
    Average

    Hi Rob,

    Could you please check the below code, its similar to the above mentioned one but more detailed.

    AGBAR1 = AverageTrueRange[14](close) * 0.75

    AGBAR2 = AverageTrueRange[14](close) * 1

    AGBAR3 = AverageTrueRange[14](close) * 1.5

    IF Range > AGBAR1 AND close > open THEN

    DrawCandle(Open,High,Low,Close) coloured(0,255,0,255)

    IF Range > AGBAR2 AND close > open THEN

    DrawCandle(Open,High,Low,Close) coloured(0,205,0,255)

    IF Range > AGBAR3 AND close > open THEN

    DrawCandle(Open,High,Low,Close) coloured(0,139,0,255)

    ENDIF

    ELSIF Range > AGBAR1 AND close < open THEN

    DrawCandle(Open,High,Low,Close) coloured(255,193,193,255)

    ELSIF Range > AGBAR2 AND close < open THEN

    DrawCandle(Open,High,Low,Close) coloured(255,48,48,255)

    ELSIF Range > AGBAR3 AND close < open THEN

    DrawCandle(Open,High,Low,Close) coloured(139,26,26,255)

    ELSE DrawCandle(Open,High,Low,Close) coloured(234,234,234,255)

    ENDIF

    RETURN

    #175004 quote
    robertogozzi
    Moderator
    Master

    How can it work for you?

    There are two errors:

    • after ELSE there cannot be anything, so the DRAWCANDLE has to start on a new line
    • the final ENDIF (just before RETURN) is missing.
    #175008 quote
    efahmy
    Participant
    Average

    It’s working now, thanks mate

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

Bar colour related to ATR


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Prodsaaw @prodsaaw Participant
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by efahmy
4 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/29/2021
Status: Active
Attachments: No files
Logo Logo
Loading...