DrawingOBForSMC
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © datnt141
//@version=5
indicator("SMC",overlay=true,max_boxes_count=50,max_lines_count=150)
draw_structure = input(defval=true, title='Show MiS',group="Control panel")
draw_supply    = input(defval=true, title='Show Supply',group="Control panel")
draw_demand    = input(defval=true, title='Show Demand',group="Control panel")
var box[] supply_zones = array.new_box()
var box[] demand_zones = array.new_box()
var line[] move_ups    = array.new_line()
var line[] move_downs  = array.new_line()
get_supply()=>
    imb = low[2]-high[0]
    if imb>0
        prev_imb = low[3]-high[1]
        if prev_imb>0
            sup_box = box.new(left=bar_index[2],top=high[1],right=bar_index[0],bottom=low[2])
            box.set_bgcolor(sup_box, color=color.new(color.red,90))
            box.set_border_color(sup_box, color=color.new(color.gray,90))
            array.push(supply_zones,sup_box)
        else
            sup_box = box.new(left=bar_index[2],top=high[2],right=bar_index[0],bottom=low[2])
            box.set_bgcolor(sup_box, color=color.new(color.red,90))
            box.set_border_color(sup_box, color=color.new(color.gray,90))
            array.push(supply_zones,sup_box)
    //Modify boxes//
    if array.size(supply_zones)>0
        for i=array.size(supply_zones)-1 to 0
            sup_box = array.get(supply_zones,i)
            top     = box.get_top(sup_box)
            if high>=top
                array.remove(supply_zones,i)
            else
                box.set_right(array.get(supply_zones,i),bar_index+1)    
    supply_zones
get_demand() =>
    imb  = low[0]-high[2]
    if imb>0
        prev_imb = low[1]-high[3]
        if prev_imb>0
            dm_box = box.new(left=bar_index[2],top=high[2],right=bar_index[0],bottom=low[1])
            box.set_bgcolor(dm_box, color=color.new(color.blue,80))
            box.set_border_color(dm_box, color=color.new(color.gray,80))
            array.push(demand_zones,dm_box)
        else
            dm_box = box.new(left=bar_index[2],top=high[2],right=bar_index[0],bottom=low[2])
            box.set_bgcolor(dm_box, color=color.new(color.blue,80))
            box.set_border_color(dm_box, color=color.new(color.gray,80))
            array.push(demand_zones,dm_box)
    //Modify boxes//
    if array.size(demand_zones)>0
        for i=array.size(demand_zones)-1 to 0
            dm_box = array.get(demand_zones,i)
            bottom  = box.get_bottom(dm_box)
            if low<=bottom
                array.remove(demand_zones,i)
            else
                box.set_right(array.get(demand_zones,i),bar_index+1)    
    demand_zones
//Drawing choch points//
get_move_up() =>
    move_up   = high[0]>high[1] and low[0]>low[1]
    if array.size(move_ups)>0
        most_recent_move = array.get(move_ups,array.size(move_ups)-1)
        x2=line.get_x2(most_recent_move)
        y2=line.get_y2(most_recent_move)
        if x2==bar_index-1
            if high>=y2
                line.set_x2(most_recent_move,bar_index)
                line.set_y2(most_recent_move,high)
        else
            if move_up == true
                if low[2]<low[1]
                    up_move = line.new(x1=bar_index-2,y1=low[2],x2=bar_index,y2=high,color=color.new(color.white,10))
                    line.set_style(up_move,line.style_dashed)
                    array.push(move_ups,up_move)
                else
                    up_move = line.new(x1=bar_index-1,y1=low[1],x2=bar_index,y2=high,color=color.new(color.white,10))
                    line.set_style(up_move,line.style_dashed)
                    array.push(move_ups,up_move)
    else
        if move_up == true
            if low[2]<low[1]
                up_move = line.new(x1=bar_index-2,y1=low[2],x2=bar_index,y2=high,color=color.new(color.white,10))
                line.set_style(up_move,line.style_dashed)
                array.push(move_ups,up_move)
            else
                up_move = line.new(x1=bar_index-1,y1=low[1],x2=bar_index,y2=high,color=color.new(color.white,10))
                line.set_style(up_move,line.style_dashed)
                array.push(move_ups,up_move)
get_move_down() =>
    move_down = low[0]<low[1] and high[0]<high[1]
    if array.size(move_downs)>0
        most_recent_move = array.get(move_downs,array.size(move_downs)-1)
        x2=line.get_x2(most_recent_move)
        y2=line.get_y2(most_recent_move)
        if x2==bar_index-1
            if low<=y2
                line.set_x2(most_recent_move,bar_index)
                line.set_y2(most_recent_move,low)
        else
            if move_down == true
                if high[2]>high[1]
                    down_move = line.new(x1=bar_index-2,y1=high[2],x2=bar_index,y2=low,color=color.new(color.yellow,10))
                    line.set_style(down_move,line.style_dashed)
                    array.push(move_downs,down_move)
                else
                    down_move = line.new(x1=bar_index-1,y1=high[1],x2=bar_index,y2=low,color=color.new(color.yellow,10))
                    line.set_style(down_move,line.style_dashed)
                    array.push(move_downs,down_move)
    else
        if move_down == true
            if high[2]>high[1]
                down_move = line.new(x1=bar_index-2,y1=high[2],x2=bar_index,y2=low,color=color.new(color.yellow,10))
                line.set_style(down_move,line.style_dashed)
                array.push(move_downs,down_move)
            else
                down_move = line.new(x1=bar_index-1,y1=high[1],x2=bar_index,y2=low,color=color.new(color.yellow,10))
                line.set_style(down_move,line.style_dashed)
                array.push(move_downs,down_move)
//Main script//
if draw_supply
    get_supply()
if draw_demand
    get_demand()
if draw_structure
    get_move_up()
    get_move_down()
//End of script//