Inside Candle Viewer
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Fab_Coin_

//@version=5
indicator("Inside Candle", overlay = true, timeframe = '')

// HMI inputs

// Vars
var incount     = 1
var inside      = false
var topinside   = 0.0
var lowinside   = 0.0

// Draw any insidebar
InsideBAR           = (high < high[1] and low > low[1]) ? color.new(#d7d7d7, 0) : na
barcolor(InsideBAR)

// Locate and track inside bars
if high < high[1] and low > low[1] and not inside
    inside      := true
    topinside   := high[1]
    lowinside   := low[1]

if inside and (close > high[incount] or close < low[incount])
    incount     := 1
    inside      := false
    topinside   := 0
    lowinside   := 0
else if inside
    incount     := incount + 1

// Plot stuff
plot(topinside == 0 ? na : topinside, 'top value', ta.change(topinside) ? na : color.new(color.blue, 30), linewidth = 2)
plot(lowinside == 0 ? na : lowinside, 'low value', ta.change(lowinside) ? na : color.new(color.blue, 30), linewidth = 2)



// ...TheEnd...