input timeFrame = AggregationPeriod.DAY;
# Get the low of the last 3 periods
def lowN3 = low(period = timeFrame);
# Get the high of the first period 2 periods ago
def highN1 = high(period = timeFrame)[2];
# Check if the price is increasing
def priceIsIncreasing = lowN3 > highN1;
# Calculate the Fractal Vertical Gap (FVG) for increasing prices
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;
# Get the high of the last 3 periods
def highN3 = high(period = timeFrame);
# Get the low of the first period 2 periods ago
def lowN1 = low(period = timeFrame)[2];
# Check if the price is decreasing
def priceIsDecreasing = lowN1 > highN3;
# Calculate the Fractal Vertical Gap (FVG) for decreasing prices
def fvgDecrease = if priceIsDecreasing then lowN1 - highN3 else Double.NaN;
# Determine the highest high (H) and lowest low (L) among the given conditions
def H = if priceIsIncreasing then lowN3 else if priceIsDecreasing then lowN1 else H[1];
def L = if priceIsIncreasing then highN1 else if priceIsDecreasing then highN3 else L[1];
# Alert if the price is increasing or decreasing
alert(priceIsIncreasing or priceIsDecreasing, "", Alert.Bar, Sound.Bell);
# Add labels to display H and L
AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2), if priceIsIncreasing then Color.GREEN else if priceIsDecreasing then Color.red else Color.white);
# Plot H and L
plot H1 = H;
plot L1 = L;
H1.SetHiding(yes);
L1.SetHiding(yes);
# Add cloud to highlight the area between H and L
AddCloud(if priceisincreasing then H1 else double.nan, L1, color1 = Color.LIGHT_GREEN, color2 = Color.LIGHT_GREEN);
AddCloud(if priceisdecreasing then H1 else double.nan, L1, color1 = Color.LIGHT_red, color2 = Color.LIGHT_red);
#