Volatility Trigger Index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ExpensiveJok
// This indicator calculates the standard deviation of the rate of change. The purpose of the scrip is only educational.
//@version=5

indicator("Volatility Trigger Index", shorttitle = "Vol.Trig.Index", overlay = false)
//-------------------------- TIPS -----------------------------
length_tip = "Number of candles to lookback."
zone_b_tip = "Value of the index in which we look for lower values to enter the market."
zone_s_tip = "Value of the index in which we look for higher values to exit the market."
bg_zone_tip= "It allows the script to colour the background."
//-------------------------- INPUTS --------------------------
length = input.int(title = "Length", defval = 20, minval = 1, tooltip = length_tip, group = "INDEX")
//Zone_b = Zone of buys. Zone_s = Zone of sells.
zone_b = input.float(title = "Low lvl", defval = 0.4, tooltip = zone_b_tip, group = "INDEX")
zone_s = input.float(title = "High lvl", defval = 0.6, tooltip = zone_s_tip, group = "INDEX")
    //------ VISUAL
bg_zone = input.bool(title = "Background", defval = true, tooltip = bg_zone_tip, group = "VISUAL")

//----------------------- PROCESS ---------------------------
roc = ta.roc(close, length)
vol = ta.stdev(roc, length)

zone_col = vol <= zone_b ? #14ff00 : vol >= zone_s ?  #ff9800 : #3c78d8
breakoutFillColor = vol >= zone_s ? color.new(#ff9800, 90) : vol <= zone_b ? color.new(#14ff00, 90) : color.new(color.white, 100)

//----------------------------- PLOTS ---------------------------------------------
bgcolor(bg_zone ? breakoutFillColor : color.new(color.white, 100))
plot(vol, title="VR", color= zone_col)