Painting bars by ATR and VOLUME

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #231172 quote
    efahmy
    Participant
    Average

    I need a code for the indicator, using the following functions and variables:

    ATR: The Average True Range function calculates the true range of the price over a specified period.

    Volume: The Volume function returns the total volume traded over a specified period.

    Average Volume: You’ll need to calculate the average volume over a certain period, such as 14 days.

    Price: The current price of the security.

    Conditions: Create logical conditions based on your requirements.

    Color: Set the color of the bar based on the conditions met.

     

    The logic for the conditions would be as follows:

     

    if ATR > 2 * ATR[14] and Volume > AverageVolume and Price > Price[1]:

    Color = “DarkGreen”

    elif ATR > 2 * ATR[14] and Volume > AverageVolume and Price < Price[1]:

    Color = “DarkRed”

    else:

    Color = “DefaultColor”

    #231173 quote
    JS
    Participant
    Senior

    Hi,

    Try this one:

     

    //ATRPeriod=5
    //AvgATRPeriod=14
    //AvgVolPeriod=14
    
    xATR=AverageTrueRange[ATRPeriod](Close)
    xAvgATR=Average[AvgATRPeriod](xATR)
    xAvgVol=Average[AvgVolPeriod](Volume)
    xVol=Volume
    xPrice=Close
    
    C1=xATR>2*xAvgATR
    C2=xVol>xAvgVol
    C3=xPrice>xPrice[1]
    C4=xPrice<xPrice[1]
    
    If C1 and C2 and C3 then
    DrawCandle(Open,High,Low,Close)Coloured("DarkGreen")
    ElsIf C1 and C2 and C4 then
    DrawCandle(Open,High,Low,Close)Coloured("DarkRed")
    Else
    DrawCandle(Open,High,Low,Close)Coloured("DarkBlue")
    EndIf
    
    Return //xATR as "ATR",xAvgAtr as "AvgATR",xAvgVol as "AvgVol",xVol as "Volume",xPrice as "Price"
    #231176 quote
    efahmy
    Participant
    Average

    Many thanks mate,

    but can I change the other bars to light gray instead of dark blue using “lightgray”

    #231178 quote
    JS
    Participant
    Senior

    If the “other bars” need to be light grey, you can replace “DarkBlue” with “LightGrey”… (or just “Grey” as shown in the screenshot)

    DrawCandle(Open,High,Low,Close)Coloured(“LightGrey”)

    #231195 quote
    efahmy
    Participant
    Average
    Many thanks mate,
    JS thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Painting bars by ATR and VOLUME


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
efahmy @efahmy Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by efahmy
1 year, 10 months ago.

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