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”
JSParticipant
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"
Many thanks mate,
but can I change the other bars to light gray instead of dark blue using “lightgray”
JSParticipant
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”)