Consolidation Channels + MMA 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mohammed_Khan

//@version=5
indicator("Consolidation Channels + MMA", overlay=true)


// =============================================================================
// ||||||||||||||||||||||||||||||||-CHANNEL-||||||||||||||||||||||||||||||||||||
// =============================================================================

lookback        = input.int(200, "Lookback")
band_multiplier = input.float(2.5, "Band Multiplier")

channel(lookback) =>
    x = 0.0
    for i = 1 to lookback
        x += (open[i] + close[i]) / 2 
    x := x / lookback

upper_channel = channel(lookback) + ((channel(lookback) / 100) * band_multiplier)
lower_channel = channel(lookback) - ((channel(lookback) / 100) * band_multiplier)

plot(upper_channel, color=color.orange, style=plot.style_circles)
plot(channel(lookback), color=color.red, style=plot.style_circles)
plot(lower_channel, color=color.yellow, style=plot.style_circles)

// =============================================================================
// |||||||||||||||||||||||||||-MEAN MOVING AVG-|||||||||||||||||||||||||||||||||
// =============================================================================

period          = input.int(20, "Period")
method          = input.string("OHLC", "Method", options=["High | Low", "Open | Close", "OHLC"])

mean_moving(period, method) =>
    mean = 0.0
    for i = 1 to period
        mean := switch method
            "High | Low"    => mean += (high[i] + low[i]) / 2
            "Open | Close"  => mean += (open[i] + close[i]) / 2
            "OHLC"          => mean += (open[i] + high[i] + low[i]+ close[i]) / 4
    
    mean := mean / period
            
plot(mean_moving(period, method), color=color.white)
    


