By popular request, here is a study that will display a gap opening and it’s 50% fill line. The plot will dynamically collapse as the gap is filled. It will work on any intraday chart timeframe, 24 hours or regular trading hours so long as the two affected trading days are showing. (Edit: If you would like the % Gap Filled box in the upper left, uncomment out the last line of code by removing the #)
# TS_GapFill # http://www.thinkscripter.com # thinkscripter@gmail.com # Last Update 28 Jan 2010 input marketOpenTime = 0930; input marketCloseTime = 1615; def yesterdaysClose = close(period = "DAY")[1]; def secondsFromOpen = secondsFromTime(marketOpenTime); def secondsTillClose = secondsTillTime(marketCloseTime); def marketOpen = if secondsFromOpen >= 0 and secondsTillClose >= 0 then 1 else 0; rec regularHoursOpen = if (secondsFromOpen >= 0 and secondsFromOpen[1] < 0) or (getDay() != getDay()[1]) then open else regularHoursOpen[1]; def newDay = if getDay() != getDay()[1] then 1 else 0; rec regHoursHigh = if newDay then high else if marketOpen then if high > regHoursHigh[1] then high else regHoursHigh[1] else high; rec regHoursLow = if newDay then low else if marketOpen then if low < regHoursLow[1] then low else regHoursLow[1] else low; def yc = if marketOpen then yesterdaysClose else double.nan; def o = if marketOpen then regularHoursOpen else double.nan; def hg = o + (yc - o) / 2; def gapUp = if yc < o then 1 else 0; def gapDown = if yc > o then 1 else 0; def gapRemaining = if gapUp then Max(regHoursLow - yc, 0) else if gapDown then Max(yc - regHoursHigh, 0) else 0; def percentRemaining = 100 * gapRemaining / AbsValue(yc - o); def gapFilled = if percentRemaining == 0 then 1 else 0; def halfGapFilled = if percentRemaining <= 50 then 1 else 0; plot gH = if (gapUp and !gapFilled and marketOpen and !newDay[-1]) then regHoursLow else if (gapDown and !gapFilled and marketOpen and !newDay[-1]) then yc else double.nan; plot gL = if (gapUp and !gapFilled and marketOpen and !newDay[-1]) then yc else if (gapDown and !gapFilled and marketOpen and !newDay[-1]) then regHoursHigh 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.darK_red else color.dark_green); gL.SetPaintingStrategy(paintingStrategy.DASHES); gL.AssignValueColor(if gapDown then color.darK_red else color.dark_green); hGF.setStyle(curve.LONG_DASH); hGF.SetDefaultColor(color.dark_gray); gH.hideBubble(); gL.hideBubble(); hgF.hideBubble(); AddCloud(gH, gL, color.gray, color.gray); #AddChartLabel(gapUp or gapDown, concat(percentRemaining, " % Gap Remaining"), color.white);






I assume this will not illustrate previous gaps, only from this point forward.
Thanks for this work. The Shinner’s in the mail.
Nice work Eric!
Definitely a handy indicator to have running -
Especially when the gap fill occurred days prior and there were no markers set.
I appreciate your efforts – as always
Keep up the great work.
Peace-
RappidFyre
Great indicator, I really love it. I can’t get the AddChartLabel to work at the top of the screen. It goes red in the script code when I delete the hash tag.
It says that it can only be 3 arguments and not 4 as it is above. Like this (-,-,-) and not (-,-,-,-)
I’m trying to learn how to script on my own. Any help?
Thanks
Greg,
The code has been updated to reflect the new syntax of the AddChartLabel() function.
Eric
Can this be modified, beyond my expertise, to reflect a gap that would exist only between the high/low of a day and the next day open verses the previous close? A Shiner is in the mail.
Thanks
Ron
are times on this one EST or local Eric? TIA
All times are EST.
seems like they are EST, is that correct?
thanks!
This indicator is awesome. ES minis almost always fills atleast half of it’s opening gap within the first hour and usually the rest some time after unless it’s a runner. This indicator makes it so much easier to trade. No calculating numbers, drawing lines…etc … Beautiful for opening gap esmini scalping setup. Thanks so much.
Hi Eric,
Looks like I’m getting the following error messages:
No such variable: gapRemaining at 27:30
calcValue: missing parameter
Also, can I change the timeframe from 0930 and 1615 to 0830 and 1515 (for CST)?
Thanks!
You are probably getting an error from an incorrect cut/paste operation. Either use the one in the current zip file or make sure and use the copy icon in the upper right of the code window above. Times must be entered in EST but will work properly in your time zone.