#chat79_fvg_mtf
#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123506
#theYaniac
#I have tried to write a script that counts Fair Value Gaps on whatever time frame the aggregation period is set to. The code is returning a few errors and I can't seem to figure out how to get rid of the errors. Any help or guidance woiuld be greatly appreciated. The code is posted below with my notes for each section:
#ThinkScript for FVG label to count like a sequence counter
#Counts consecutive positive or negative, when the direction changes the previous direction resets to zero
#There are still errors in this code that I am trying to chase down
# Inputs default at daily chart
#For 1 minute chart change to timeframe = AggregationPeriod.MIN
#For 5 minute chart change to timeframe = AggregationPeriod.FIVE_MIN
#For 1 day chart change to timeframe = AggregationPeriod.DAY
input timeframe = AggregationPeriod.MIN;
input fairValue = 0.0;
# Calculate Fair Value Gap
def high1 = high(period = timeframe)[1];
def low1 = low(period = timeframe)[1];
def high3 = high(period = timeframe)[3];
def low3 = low(period = timeframe)[3];
def fairValueGap = if high1 < low3 then 1 else if low1 > high3 then -1 else 0;
# Track Consecutive Positive and Negative Gaps
def consecutivePositiveGaps = if fairValueGap == 1 then Max(1, consecutivePositiveGaps[1] + 1) else 0;
def consecutiveNegativeGaps = if fairValueGap == -1 then Max(1, consecutiveNegativeGaps[1] + 1) else 0;
# Plot Rectangle and Label with Sequence Counter
def isPositiveGap = fairValueGap == 1;
def isNegativeGap = fairValueGap == -1;
#def positiveGapLabel = "+FVG " + consecutivePositiveGaps;
#def negativeGapLabel = "-FVG " + consecutiveNegativeGaps;
AddLabel(1, "+FVG " + consecutivePositiveGaps, Color.YELLOW);
AddLabel(1, "-FVG " + consecutiveNegativeGaps , Color.YELLOW);
#AddChartBubble(isPositiveGap, low3, positiveGapLabel, Color.GREEN, no);
#AddChartBubble(isNegativeGap, high3, negativeGapLabel, Color.RED, no);
AddChartBubble(isPositiveGap, low3, consecutivePositiveGaps, Color.GREEN, no);
AddChartBubble(isNegativeGap, high3, consecutiveNegativeGaps, Color.RED, no);
#AddVerticalLine(isPositiveGap, low3, high1, Color.GREEN, Curve.SHORT_DASH);
#AddVerticalLine(isNegativeGap, high3, low1, Color.RED, Curve.SHORT_DASH);
# AddVerticalLine ( visible, text, color, stroke);
AddVerticalLine(isPositiveGap, high1, Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(isNegativeGap, low1, Color.RED, Curve.SHORT_DASH);
#AddCloud(isPositiveGap, low3, high1, Color.GREEN, Color.LIGHT_GRAY);
#AddCloud(isNegativeGap, high3, low1, Color.RED, Color.LIGHT_GRAY);
AddCloud(isPositiveGap, low3, Color.GREEN, Color.LIGHT_GRAY);
AddCloud(isNegativeGap, high3, Color.RED, Color.LIGHT_GRAY);
#