Flow of Range
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingMentalist

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

sidein2     = input(500, step=100, title='Range')
side1       = (close[1] + close[sidein2]) / 2
side2       = close[1] - close[sidein2] 
side3       = side2 / side1
truncate(number, decimals) =>
    factor = pow(10000, decimals)
    int(number * factor) / factor
side3pc= truncate(side3, 2) 
side3in=10000
flowofrange=side3pc*side3in
flowbuy=flowofrange < -150
flowsell= flowofrange > 150
flowbuy2=flowofrange < -100
flowofrangeavg= sma(flowofrange,100)
flowofrangeavg2= sma(flowofrange*2,1000)


plot(flowofrangeavg2, 
  style=plot.style_area,
  color=flowofrangeavg2 > 0 ? color.new(#9DFAF8,60) : color.new(#707CFA,60),
  linewidth=1)

plot(flowofrangeavg, 
  style=plot.style_area,
  color=flowofrangeavg > 0 ? color.new(#4EC5C7,60) : color.new(#707CFA,60))

