Page 1 of 1

indicator for measuring the average bar size?

Posted: Wed Feb 24, 2021 10:07 pm
by dusktrader
Hello, is there an indicator that can tell me the current average bar size? Say for example the last 20 bars on my chart in the timeframe I'm on?

I'm working on a strategy that currently involves a bit of a dynamic stop. The stop is relative to the size of the prior bar on entry, which means in fast moving markets the stop will be wider.

I am going to research some similar indicators like Parabolic SAR, but I think it would be great if I had a way to get the average bar size for last X bars.

Ideally, as a manual-trading strategy, what I want is an indicator that will calculate the correct stop and position size. This will be constantly changing based on the volatility of the market, so I need i calculated in realtime. I'm sure I can build the indicator but currently I'm not sure how to get the average bar size.

Thanks!

Re: indicator for measuring the average bar size?

Posted: Fri Feb 26, 2021 8:55 pm
by kmarryat
Hi dusktrader,
A common indicator for dynamic stops is ATR (Average True Range), check it out.
Generally a multiple of ATR is used. IE. 2*ATR for Target, 1.5 * ATR for Stop.

Here's a short code snippet to compare a simple average of bar ranges with ATR.

Code: Select all

//@version=4
study("Range",overlay=false)

Range=abs(high-low)
AvgRange=avg(Range[1],Range[2],Range[3],Range[4],Range[5])
plot(AvgRange,color=color.blue)

ATR=atr(5)
plot(ATR,color=color.red)
 
Hope it helps. Good Luck!

Re: indicator for measuring the average bar size?

Posted: Fri Feb 26, 2021 11:50 pm
by dusktrader
Hey thanks! I will give that a try. I am currently using Parabolic SAR and it seems to be working good manually (I am still learning how to code it).

But my strategy requires the SAR from a lower timeframe. I use this for dynamic stop. Currently trying to determine how to gain access to a different timeframe in my pine script. I see the sar reference book entry, but it doesn't mention how to access it on a different timeframe.

Re: indicator for measuring the average bar size?

Posted: Sat Feb 27, 2021 12:07 am
by dusktrader
Btw I think I found the answer to my own question here - this explains how to access an indicator value from a different timeframe:
https://www.tradingview.com/blog/en/new ... ion-18479/