Makuchaku's Trade Tools - Fair Value Gaps
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © makuchaku

//@version=4
study("Makuchaku's Trade Tools - Fair Value Gaps", overlay=true)
boxLength  = input(title="boxLength", type=input.integer, defval=3, group="General", inline="General")
boxTransparency  = input(title="boxTransparency", type=input.integer, defval=95, group="General", inline="General")


isUp(index) =>
    close[index] > open[index]
    
isDown(index) =>
    close[index] < open[index]


isObUp(index) =>
    isDown(index+1) and isUp(index) and (close[index] > high[index+1])
    

isObDown(index) =>
    isUp(index+1) and isDown(index) and (close[index] < low[index+1])



//////////////////// FVG //////////////////
bullishFvg = (low[0] > high[2])
bearishFvg = (high[0] < low[2])
if bullishFvg
    box.new(left=bar_index-2, top=low[0], right=bar_index+boxLength, bottom=high[2], bgcolor=color.new(color.black, boxTransparency), border_color=color.new(color.black, boxTransparency))    
if bearishFvg
    box.new(left=bar_index-2, top=low[2], right=bar_index+boxLength, bottom=high[0], bgcolor=color.new(color.black, boxTransparency), border_color=color.new(color.black, boxTransparency))    
//////////////////// FVG //////////////////