Hi All,
I created the an indicator to plot the Fair Value Gaps on intraday charts (mainly 1, 2, 3 min charts). I have everything working as you can see the magenta or green plot lines where the gaps are however I am not able to figure out the following;
1) I can't get the cloud to plot for each of the gaps
2) Once I get the cloud on the chart, I want the cloud to continue to be reduced when future price action trades into it.
I used part of the code from BenTen's post here.
https://usethinkscript.com/threads/...n-for-thinkorswim-highlight-potential-gap.45/
I created the an indicator to plot the Fair Value Gaps on intraday charts (mainly 1, 2, 3 min charts). I have everything working as you can see the magenta or green plot lines where the gaps are however I am not able to figure out the following;
1) I can't get the cloud to plot for each of the gaps
2) Once I get the cloud on the chart, I want the cloud to continue to be reduced when future price action trades into it.
I used part of the code from BenTen's post here.
https://usethinkscript.com/threads/...n-for-thinkorswim-highlight-potential-gap.45/
Code:
input marketOpenTime = 0930;
input marketCloseTime = 1615;
input ATRLength = 28;
input ATRMultiplier = 1.5;
def secondsFromOpen = SecondsFromTime(marketOpenTime);
def secondsTillClose = SecondsTillTime(marketCloseTime);
def marketOpen = if secondsFromOpen >= 0 and secondsTillClose >= 0 then 1 else 0;
def newDay = if GetDay() != GetDay()[1] then 1 else 0;
#FVG Calculations
def FVGbearCondition = close[3] <= high[2] and close[1] <= close[2] and high < low[2];
def FVGbullCondition = close[3] >= low[2] and close[1] >= close[2] and low > high[2];
def priceDiff = high[1] - low[1];
def ATRValue = Average(TrueRange(high, close, low), ATRLength);
def middleCandleVolatilityCondition = priceDiff > ATRValue * ATRMultiplier;
def isUpCandle = close > open;
def isGapClosed = if isUpCandle then high[2] >= low else low[2] <= high;
def isFairValueGap = (FVGbearCondition or FVGbullCondition) and !isGapClosed and middleCandleVolatilityCondition and !isFairValueGap[1];
def gapUp = FVGbullCondition and !isGapClosed and middleCandleVolatilityCondition and !isFairValueGap[1];
def GUhigh = if gapUp then low else GUhigh[1];
def GUlow = if gapUp then high[2] else GUlow[1];
def gapDown = FVGbearCondition and !isGapClosed and middleCandleVolatilityCondition and !isFairValueGap[1];
def GDhigh = if gapDown then high else GDhigh[1];
def GDlow = if gapDown then low[2] else GDlow[1];
def hg = (if gapUp then high[2] + (GUhigh - GUlow) else if gapDown then high[2] + (GDlow - GDhigh) else 0) / 2;
def gapRemaining = if gapUp then GUhigh - GUlow else if gapDown then GDlow - GDhigh else 0;
def percentRemaining = 100 * gapRemaining / if gapUp then AbsValue(GUhigh - GUlow) else if gapDown then AbsValue(GDlow - GDhigh) else 0;
def gapFilled = if percentRemaining == 0 then 1 else 0;
def halfGapFilled = if percentRemaining <= 50 then 1 else 0;
#FVG Plots
plot gH = if (gapUp and marketOpen and !newDay[-1])
then GUhigh else if (gapDown and marketOpen and !newDay[-1])
then GDhigh else Double.NaN;
plot gL = if (gapUp and marketOpen and !newDay[-1])
then GUlow else if (gapDown and marketOpen and !newDay[-1])
then GDlow else Double.NaN;
plot hGF = if !gapFilled and !halfGapFilled and marketOpen and !newDay[-1]
then hg else Double.NaN;
gH.SetPaintingStrategy(PaintingStrategy.DASHES);
gH.AssignValueColor(if gapDown then Color.MAGENTA else Color.DARK_GREEN);
gL.SetPaintingStrategy(PaintingStrategy.DASHES);
gL.AssignValueColor(if gapDown then Color.MAGENTA else Color.DARK_GREEN);
gH.HideBubble();
gL.HideBubble();
AddCloud(gH, gL, Color.VIOLET, Color.VIOLET);
#Troubleshooting Bubbles
AddChartBubble(gapRemaining, high, gapRemaining, Color.ORANGE);
#addchartbubble(gapUp, high, GUhigh +" | " + GUlow, color.green);
#addchartbubble(gapDown, low, GDhigh +" | " + GDlow, color.red);