% Per Bar
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sainsley2500

// This script compute the average price swing per bar (between High and low)
// It does not include gaps between bars in the calcul


//@version=5
indicator("% Per Bar", overlay = false)

var LabelString = ""
var Label = label.new(0, 0, "", color= color.black, textcolor=color.white, yloc=yloc.price)

HighLowPercent =  math.abs((high-low)/low *100)

SMA10 = ta.sma(HighLowPercent, 10)
SMA100 = ta.sma(HighLowPercent, 100)
SMA1000 = ta.sma(HighLowPercent, 1000)

plot(HighLowPercent, title = "High - Low", color = color.black)

if barstate.islast 
    label.set_xy(Label, bar_index, SMA10)
    LabelString := "Average on last 10 Bars: " + str.format("{0,number,#.####}", SMA10) + "%\n"
    LabelString := LabelString + "Average on last 100 Bars: " + str.format("{0,number,#.####}", SMA100) + "%\n"
    LabelString := LabelString + "Average on last 1000 Bars: " + str.format("{0,number,#.####}", SMA1000) + "%\n"
    label.set_text(Label, LabelString)
