Laylabrador
New member
is there a script that automatically shows the unfilled gaps on tos charts?
thanks
thanks
Here you go.is there a script that automatically shows the unfilled gaps on tos charts?
thanks
# TS_GapFill
# [email protected]
# Last Update 28 Jan 2010
# Last Update 16 Jan 2019 by Jerry Investor
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.Pink, Color.Pink);
AddLabel(yes, Concat(percentRemaining, " % Gap Remaining" ),if percentRemaining > 0 then Color.RED else Color.GREEN);
I'm not clear on what exactly you want to see. If you were starting from scratch, without this code already written, what is it you'd be asking for?
input minGapPercent = 2;
def buffer = close[2] * minGapPercent / 100;
def gapUp = open[1] > close[2] + buffer;
def gapUpFilled =
Between(close[2] + .01, low[1], high[1])
or Between(close[2] + .01, low, high)
;
def gapDown = open[1] < close[2] - buffer;
def gapDownFilled =
Between(close[2] - .01, low[1], high[1])
or Between(close[2] - .01, low, high)
;
plot scan = (gapUp and !gapUpFilled) or (gapDown and !gapDownFilled);
sorry but nothing is coming up, I have it set to D and just ran it this morning. I have several stocks that have gapped up two days in a row or gapped down 2 days in a row and nothing is coming up. I copied and pasted it as a custom study and ran it with D aggregation
input minGapPercent = 2;
def buffer = close[1] * minGapPercent / 100;
def gapUp = open > close[1] + buffer;
def gapUpFilled = Between(close[1] + .01, low, high);
def gapDown = open < close[1] - buffer;
def gapDownFilled = Between(close[1] - .01, low, high);
plot scan =
(gapUp and gapUp[1] and !gapUpFilled and !gapUpFilled[1])
or
(gapDown and gapDown[1] and !gapDownFilled and !gapDownFilled[1])
;
YES!!!! It works now.. this is exactly what I was looking for! you are awesome thank you!.. question. the lower I chaange the minigap the more results I get as you stated. What does that minigap figure do? I had do go do to .5 for example to have XOM show up. I assume its the percentage of the gap left is that correct? if it is and I want min 20% left then would it be set to .2? if it's something else then let me know.Oh, I see. I didn't realize you want both days to gap. I thought you meant you want a gap and then 2 days not filled. This should be what you want.
Ruby:input minGapPercent = 2; def buffer = close[1] * minGapPercent / 100; def gapUp = open > close[1] + buffer; def gapUpFilled = Between(close[1] + .01, low, high); def gapDown = open < close[1] - buffer; def gapDownFilled = Between(close[1] - .01, low, high); plot scan = (gapUp and gapUp[1] and !gapUpFilled and !gapUpFilled[1]) or (gapDown and gapDown[1] and !gapDownFilled and !gapDownFilled[1]) ;
YES!!!! It works now.. this is exactly what I was looking for! you are awesome thank you!.. question. the lower I chaange the minigap the more results I get as you stated. What does that minigap figure do? I had do go do to .5 for example to have XOM show up
minGapPercent
input defines how far apart the previous close and the next open need to be for you to consider it a gap you want to know about. If it's just a few cents apart on a stock over $100 technically it's a gap but it's not meaningful in a trade decision. A $1 gap on AMZN isn't really meaningful. Adding this filter as a % of price prevents you from getting lots of meaningless results in the scan. You can tweak it to whatever makes sense for your trading and you can use decimals if you want, such as 0.5, if 1% is too big of a limit. Try setting it to something very small like .01 and you'll see your eyes don't even detect a gap on some of the results.Perfect. If I want to be able to switch to look lets say 3 days ago or 4 days ago would this code work the way I have it just by changing the daysback figure?You're welcome. TheminGapPercent
input defines how far apart the previous close and the next open need to be for you to consider it a gap you want to know about. If it's just a few cents apart on a stock over $100 technically it's a gap but it's not meaningful in a trade decision. A $1 gap on AMZN isn't really meaningful. Adding this filter as a % of price prevents you from getting lots of meaningless results in the scan. You can tweak it to whatever makes sense for your trading and you can use decimals if you want, such as 0.5, if 1% is too big of a limit. Try setting it to something very small like .01 and you'll see your eyes don't even detect a gap on some of the results.
Perfect. If I want to be able to switch to look lets say 3 days ago or 4 days ago would this code work the way I have it just by changing the daysback figure?
input minGapPercent = .2;
def daysback=5;
def buffer = close[1+daysback] * minGapPercent / 100;
def gapUp = open[daysback] > close[1+daysback] + buffer;
def gapUpFilled = Between(close[1+daysback] + .01, low[daysback], high[daysback]);
def gapDown = open[daysback] < close[1+daysback] - buffer;
def gapDownFilled = Between(close[1+daysback] - .01, low[daysback], high[daysback]);
plot scan =
(gapUp[daysback] and gapUp[1+daysback] and !gapUpFilled[daysback] and !gapUpFilled[1+daysback])
or
(gapDown[daysback] and gapDown[1+daysback] and !gapDownFilled[daysback] and !gapDownFilled[1+daysback])
;
Hi there again, can you please help add to the script when it's 3 days gap up/down and gap not filled? Thank you in advanceYes, that looks like it should work.
#########################################################################
# BWD_GapFillTrader ToS Study
#
# Heavily modified 'crash' code.
# Author: BigWaveDave.
# [email protected]
#
# Version: 2.6
# Release Date: 09/19/13
# Found a bug? Send it to me: [email protected]
#
# Redesigned for the /es and 15min or smaller aggregation periods
# but not tick charts
#
# No guarantees as to accuracy expressed or implied
# Use at your own discretion
#
# Version 2.6 Enhancements/Fixes:
# + Added config. option to turn off the vertical 'GapFill Trader' separator
#
# Version 2.5 Enhancements/Fixes:
# + Removed old debug code showing in 'Full Gap Filled!' bubble.
#
# Version 2.4 Enhancements/Fixes:
# + TOS upgrade caused double bubbles to be displayed. Fixed.
#
# Version 2.3 Enhancements/Fixes:
# + Fixed bug where Pro Gap condition was not resetting for the next day.
#
# Version 2.2 Enhancements/Fixes:
# + Fixed bug where Rollover hint displays before every OpEx instead of
# once per quarter.
#
# Version 2.0 Enhancements/Fixes:
# + Fixed bug with autohide when in Gap Down situation
# + GapTrader will now correctly AutoHide in a Progap situation
# + Added 'HalfGap' plot as user selectable option
# + Added 'GlobexPivot' plot as user selectable option
# Same as PivotPoint but uses 4:15 close instead of 4PM
# + Added user option to generate alerts based on gap fill occurrence
# + Cleaned up code and fixed inumerable drawing problems
# + Added 'Trading Day Hints' with GapFill Odds (user-configurable)
# + Trading Day Hints supports notification of Rollover and OpEx days
# + Trading Day Hints work on tick aggregation period charts
# + Added Trading Day Odds. Displays gapfill odds (in red if 'No Gapfill expected' day)
# + Contrary to prior claims, gapfill detection only works for current day
#
# Version 1.0 Enhancements:
# + Works on all timeframes <= 15min in the 'time' aggregationPeriod mode
#
# Note:
# The 'GapTrader' tool rules are based on the gapfill rules posted
# on eminiaddict.com.
#
# For best results, set 'Right bars' to at least 200 on a 15min chart
#
#
# ORIGINAL HEADER BELOW
#
########################################################################
# Emini Addict
# Half Gap Fill, Full Gap Fill, and
# Trading Hours only Pivot Point (9:30a - 4:00p).
# This study is intended for the 15 minute chart only.
# No warranties or guarantees. Modify at your own risk.
########################################################################
########################################################################
# Get things all setup. Get some settings values and calculate some #
# useful things for later. #
########################################################################
# Display all unfilled gaps in expanded 'right bars' area
input EnableGapTrader = {"No" , default "Yes"};
input ShowVerticalSeparator = {"No", default "Yes"};
input ShowGapTraderHints = {"No", default "Yes"};
input ShowTradingDayHints = {"No", default "Yes"};
input ShowTradingDayOdds = {"No", default "Yes"};
input AutoHideWhenGapFills = {"No", default "Yes"};
input EnableGapAlerts = {"No", default "Yes"};
input DisplayGapTraderFrom = 0700;
input DisplayGapTraderUntil = 1615;
input ShowPriceBubbles = {"No", default "Yes"};
input ShowBubbleIfGapFills = {"No", default "Yes"};
input ProGapAndGoLevel = 10;
input MinimumGapFillLevel = 5;
input MondayGapFillOdds = 53;
input TuesdayGapFillOdds = 67;
input WednesdayGapFillOdds = 71;
input ThursdayGapFillOdds = 65;
input FridayGapFillOdds = 82;
input ShowHalfGap = {default "No", "Yes"};
input ShowGlobexPivot = {default "No", "Yes"};
# Market Open and Close times in EST.
input NYSEOpenTime = 0930;#dmo maybe hard code these 2...
input NYSECloseTime = 1600;
def GlobexCloseTime = 1615;
# Only show gap and pivot for today?
input ShowTodayOnly = {default "No", "Yes"};
# Only need to calc this once on the very last 'real' bar, then
# just bring it forward... indicates if we are in the timeframe
# the user requested to display the gaptrader...
rec DisplayGapTraderWindow = If (!IsNaN(close), If ((EnableGapTrader and ((SecondsTillTime(DisplayGapTraderFrom) <= 0) and (SecondsTillTime(DisplayGapTraderUntil) > 0))), 1, 0), DisplayGapTraderWindow[1]);
# well, is it?
def isToday = GetDay() == GetLastDay();
# Friday's return the next day at 4:15pm, that's a problem cuz we need it to be 1AM
def isNextDay = (GetDay() != GetDay()[1]) and (GetDayOfWeek(GetYYYYMMDD()[1]) != 5);
# what bar number are we? Might be more efficient to call this once... who know's?
def barNumber = BarNumber();
# Are we in a valid aggregation time period? Can't do Tick charts or > 15min
def thePeriod = GetAggregationPeriod();
def ValidAggregation = If ((thePeriod == AggregationPeriod.MIN) or
(thePeriod == AggregationPeriod.TWO_MIN) or
(thePeriod == AggregationPeriod.THREE_MIN) or
(thePeriod == AggregationPeriod.FOUR_MIN) or
(thePeriod == AggregationPeriod.FIVE_MIN) or
(thePeriod == AggregationPeriod.TEN_MIN) or
(thePeriod == AggregationPeriod.FIFTEEN_MIN), 1, 0);
# well then, will we try to draw it?
def DrawPlotDataToday = If (isToday and ValidAggregation, 1, If (!ShowTodayOnly and
ValidAggregation, 1, 0));
# Is this bar inside of normal trading hours?
def bMarketOpen = (SecondsTillTime(NYSEOpenTime) <= 0);
def bMarketClosed = (SecondsTillTime(NYSECloseTime) <= 0);
def bGlobexClosed = (SecondsTillTime(GlobexCloseTime) <= 0);
def isMarketOpen = bMarketOpen and !bMarketClosed;
# Gather up some bits for use later...
def MinutesPerCandle = (GetAggregationPeriod() / 1000) / 60;
def CandlesInADay = (24 * 60) / MinutesPerCandle;
def NYSEOpenMinutes = (Floor(NYSEOpenTime / 100) * 60) + (NYSEOpenTime % 100);
def NYSECloseMinutes = (Floor(NYSECloseTime / 100) * 60) + (NYSECloseTime % 100);
# How many bars during the NYSE session?
def NYSESessionCandleCount = (NYSECloseMinutes - NYSEOpenMinutes) / MinutesPerCandle;
# Are we processing the current bar?
def isLastValidBar = If (!IsNaN(close) and IsNaN(close[-1]) , 1, 0);
rec ValidLastBar = CompoundValue(1, if (isLastValidBar, barNumber, ValidLastBar[1]), 0);
# Figure out where the 'right expansion area' starts and nudge it a little.
def BarPadding = 2;
def BarNudge = 2;
#rec DrawingZoneBarNumber = CompoundValue(1, If (isLastValidBar, barNumber + BarNudge,
rec DrawingZoneBarNumber = CompoundValue(1, If (isLastValidBar, ValidLastBar + BarNudge, DrawingZoneBarNumber[1]), 0);
# Calling 'LowestAll' prevents 'live' updates of right bar area on each tick
# I don't know why, but it appears to be a TOS bug
#LowestAll(if IsNaN(close[-1]) then (barNumber + BarNudge) else double.nan);
def DrawingZonePaddedBarNumber = DrawingZoneBarNumber + BarPadding;
def bFirstTradingBarofSession = (bMarketOpen and !bMarketOpen[1]);
def bLastTradingBarofSession = (bMarketClosed and !bMarketClosed[1]);
def bLastTradingBarofGlobexSession = bGlobexClosed and !bGlobexClosed[1];
rec FirstBarNumber = CompoundValue(1, If (bFirstTradingBarofSession, barNumber, FirstBarNumber[1]), Double.NaN);
rec NYSEActiveSessionCandlesRemaining = CompoundValue(1, If (isLastValidBar and isMarketOpen, NYSESessionCandleCount - (barNumber - FirstBarNumber) - BarPadding - BarNudge - 1, NYSEActiveSessionCandlesRemaining[1]), If (!isMarketOpen, NYSESessionCandleCount, 0));
rec NYSESessionCandlesRemaining = CompoundValue(1, NYSESessionCandlesRemaining[1], NYSESessionCandleCount);
########################################################################
# Caculate and store everything that we're going to draw later #
# #
########################################################################
rec staticIsMarketOpen = CompoundValue(1, If (isMarketOpen and !IsNaN(close), 1, If (bLastTradingBarofSession and !IsNaN(close[1]), 0, staticIsMarketOpen[1])), 0);
# After the session open, we no longer recommend taking any trades into the gapfill
def ShowTradeEntryHints = If (!staticIsMarketOpen, ShowGapTraderHints, 0);
# set some stuff up for live updates (at the completion of each bar)...
# Get the close value of the last valid bar
rec ActiveBarClose = CompoundValue(1, If (isLastValidBar, close, ActiveBarClose[1]), Double.NaN);
# For each unique trading session of a day, store the daily high, low, and close...
# store the highest value of then NYSE session and carry it forward
rec marketHoursHigh = CompoundValue(1,
If (((high > marketHoursHigh[1]) and isMarketOpen) or bFirstTradingBarofSession, high, marketHoursHigh[1]), high);
# store the lowest value of then NYSE session and carry it forward
rec marketHoursLow = CompoundValue(1, If (((low < marketHoursLow[1]) and isMarketOpen) or bFirstTradingBarofSession, low, marketHoursLow[1]), low);
# store the open value of the day
rec marketHoursOpen = CompoundValue(1, if bFirstTradingBarofSession then open else marketHoursOpen[1], open);
# Ok, so basically, for the 'close' values we want to start grabbing them
# on the last bar of the day. But only when we are in fact actually trading
# right at the last bar, not when we happen to be at the close time barwise
# but nowhere near it in actual time
def GetTheValues = bLastTradingBarofSession and !IsNaN(close[1]);
def GetGlobexValue = bLastTradingBarofGlobexSession and !IsNaN(close[1]);
# want to suppress getting values if above true, but day not over yet...
# If the last bar of the day, store the close, otherwise carry it forward
# this is the value that we will draw the next day...
rec valueAtClose = CompoundValue(1, if GetTheValues then close[1] else valueAtClose[1], close);
rec prevClose = CompoundValue(1, if GetTheValues then valueAtClose else prevClose[1], close);
# store the high in here
rec prevHigh = CompoundValue(1, if GetTheValues then marketHoursHigh[1] else prevHigh[1], high);
# store the low in here
rec prevLow = CompoundValue(1, if GetTheValues then marketHoursLow[1] else prevLow[1], low);
# for globex pivot
rec valueAtGlobexClose = CompoundValue(1, if GetGlobexValue then close[1] else valueAtGlobexClose[1], close);
rec globexClose = CompoundValue(1, if GetGlobexValue then valueAtGlobexClose else globexClose[1], close);
# All this work, just to calculate these 3 little values
def thePivot = (prevClose + prevHigh + prevLow) / 3;
def theGlobexPivot = If (ShowGlobexPivot, (globexClose + prevHigh + prevLow) / 3, Double.NaN);
def theGap = prevClose;
def theHalfGap = If (ShowHalfGap, prevClose + (marketHoursOpen - prevClose) / 2, Double.NaN);
# Perform tests for gapfill/halfgapfill during market hours and ProGap only on the opening print of the day
# Reset all carry forward values at the dawn of a new day
rec GapHasFilled = CompoundValue(1, If (isMarketOpen and ((marketHoursLow <= (theGap + .25) and (marketHoursHigh >= (theGap + .25))) or ((marketHoursHigh >= (theGap - .25))) and (marketHoursLow <= (theGap - .25))), 1, If (isMarketOpen, GapHasFilled[1], 0)), 0);
rec FullGapHasFilled = CompoundValue(1, If (IsNaN(GapHasFilled), FullGapHasFilled[1], If (isNextDay, 0, GapHasFilled)), 0); #reset for next day
rec HalfHasFilled = CompoundValue(1, If (isMarketOpen and ((marketHoursLow <= (theHalfGap + .25) and (marketHoursHigh >= (theHalfGap + .25))) or ((marketHoursHigh >= (theHalfGap - .25))) and (marketHoursLow <= (theHalfGap - .25))), 1, If (isMarketOpen, HalfHasFilled[1], 0)), 0);
rec HalfGapHasFilled = CompoundValue(1, If (IsNaN(HalfHasFilled), HalfGapHasFilled[1], If (isNextDay, 0, HalfHasFilled)), 0); #reset for next day
rec ProGapped = CompoundValue(1, If (bFirstTradingBarofSession and ((marketHoursOpen > (theGap + ProGapAndGoLevel)) or ((marketHoursOpen < (theGap - ProGapAndGoLevel)))), 1, If
(isMarketOpen, ProGapped[1], 0)), 0);
rec ItProGapped = CompoundValue(1, If (IsNaN(ProGapped), ItProGapped[1], If (isNextDay, 0, ProGapped)), 0); # reset for next day
# This logic is critical for drawing routines... no touchy, it'll break.
rec DisplayGapTrader = If (!IsNaN(close), If (DisplayGapTraderWindow and ValidAggregation and !(AutoHideWhenGapFills and (FullGapHasFilled or ItProGapped)), 1, 0), DisplayGapTrader[1]);
# Alerts
Alert(EnableGapAlerts and DisplayGapTraderWindow and ValidAggregation and FullGapHasFilled and (FullGapHasFilled != FullGapHasFilled[1]), Concat("Full Gap Has Filled At: ", theGap), Alert.BAR, Sound.Ding);
Alert(EnableGapAlerts and DisplayGapTraderWindow and ValidAggregation and HalfGapHasFilled and (HalfGapHasFilled != HalfGapHasFilled[1]), Concat("Half Gap Has Filled At: ", theHalfGap), Alert.BAR, Sound.Ding);
Alert(EnableGapAlerts and DisplayGapTraderWindow and ValidAggregation and ItProGapped and (ItProGapped != ItProGapped[1]), Concat("Professional Gap & Go At: ", ProGapAndGoLevel), Alert.BAR, Sound.Ding);
########################################################################
# Do all of our fancy drawing... #
# #
########################################################################
# give the user some color choice for the labels and things
DefineGlobalColor("FullGap Label", Color.GREEN);
DefineGlobalColor("HalfGap Label", Color.LIME);
DefineGlobalColor("Pivot Point Label", Color.MAGENTA);
DefineGlobalColor("Globex Pivot Label", Color.PINK);
DefineGlobalColor("ProGap Label", Color.RED);
DefineGlobalColor("GapFill Entry Zone", Color.DARK_GREEN);
DefineGlobalColor("GapFill No Entry Zone", Color.DARK_RED);
DefineGlobalColor("GapTrader Seperator", Color.DARK_ORANGE);
DefineGlobalColor("GapTrader Hints", Color.DARK_ORANGE);
# Define the valid bars for drawing within the GapTrader area
def ExtensionLength = 3;
# the (DrawingZoneBarNumber > 0) test below is required because this value isn't
# known until after all previous bars have been processed the first time through
# This gets set to a valid non-zero bar number right before the right bars
# area gets processed the first time
# These ranges define where we paint our gaptrader plots
def DrawGapFillTraderZoneSansAutohide = If ((DrawingZoneBarNumber > 0) and DisplayGapTraderWindow and DrawPlotDataToday and ((barNumber >= DrawingZonePaddedBarNumber) and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining))), 1, 0);
def DrawGapFillTraderZone = If (DrawGapFillTraderZoneSansAutohide and DisplayGapTrader, 1, 0);
def DrawGapFillTraderZoneExt = If ((DrawingZoneBarNumber > 0) and DisplayGapTrader and DrawPlotDataToday and DisplayGapTrader and ((barNumber >= DrawingZonePaddedBarNumber) and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining + ExtensionLength))), 1, 0);
# specify the exact bar numbers at which we'll paint our bubbles, etc.
def WantToDrawFirstPosition = If (DrawGapFillTraderZone and (barNumber == DrawingZonePaddedBarNumber), 1, 0);
def WantToDrawHalfPosition = If (DrawGapFillTraderZone and (barNumber == (DrawingZonePaddedBarNumber + Floor(NYSESessionCandlesRemaining / 2))), 1, 0);
def WantToDrawLastPosition = If (DrawGapFillTraderZone and (barNumber == (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining)), 1, 0);
def WantToDrawLastPositionExt = If (DrawGapFillTraderZoneExt and (barNumber == (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining + ExtensionLength)), 1, 0);
# Do we draw a bubble if gaptrader is hidden? Only do it for 'today'
def DrawBubblesToday = ((DrawingZoneBarNumber > 0) and !DisplayGapTrader and DrawPlotDataToday and ShowBubbleIfGapFills and ((barNumber < DrawingZoneBarNumber + CandlesInADay - If (isMarketOpen, NYSESessionCandleCount, 0))) and bLastTradingBarofSession[-1]);
# If user asked for the assistance, let him have it.
# Vertical bar is in a special location.... so... figure it out
AddVerticalLine(If (ShowVerticalSeparator and DisplayGapTrader and ValidAggregation and (barNumber == DrawingZoneBarNumber), 1, 0), "GapFill Trader", GlobalColor("GapTrader Seperator"), Curve.FIRM);
#Pivot Point Plot
plot Pivot_Point = If (DrawGapFillTraderZone or (isMarketOpen and (!IsNaN(close) or (!DisplayGapTrader and (((barNumber < DrawingZoneBarNumber + CandlesInADay - If (staticIsMarketOpen, NYSESessionCandleCount, 0))))) or (DisplayGapTrader and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining))))) and DrawPlotDataToday, thePivot, Double.NaN);
Pivot_Point.SetStyle(Curve.FIRM);
Pivot_Point.SetLineWeight(2);
Pivot_Point.SetDefaultColor(Color.MAGENTA);
Pivot_Point.HideTitle();
AddChartBubble(If (WantToDrawLastPosition and ShowPriceBubbles and !FullGapHasFilled and
!ItProGapped, 1, 0), thePivot, Concat("Pivot:" , Round(thePivot)), GlobalColor("Pivot Point Label"), If (thePivot >= theGap, yes, no));
# Globex Pivot Plot
plot Globex_Pivot = If (DrawGapFillTraderZone or (isMarketOpen and (!IsNaN(close) or (!DisplayGapTrader and (((barNumber < DrawingZoneBarNumber + CandlesInADay - If (staticIsMarketOpen, NYSESessionCandleCount, 0))))) or (DisplayGapTrader and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining))))) and DrawPlotDataToday, theGlobexPivot, Double.NaN);
Globex_Pivot.SetStyle(Curve.FIRM);
Globex_Pivot.SetLineWeight(2);
Globex_Pivot.SetDefaultColor(Color.PINK);
Globex_Pivot.HideTitle();
AddChartBubble(If (WantToDrawLastPosition and ShowPriceBubbles and !FullGapHasFilled and !ItProGapped, 1, 0), theGlobexPivot, Concat("GlobexPivot:" , Round(thePivot)), GlobalColor("Globex Pivot Label"), If (thePivot > theGap, no, yes));
# HalfGap
plot Half_GapFill = If ((DrawGapFillTraderZone and isMarketOpen) or (isMarketOpen and (!IsNaN(close) or (!DisplayGapTrader and (((barNumber < DrawingZoneBarNumber + CandlesInADay - If (staticIsMarketOpen, NYSESessionCandleCount, 0))))) or (DisplayGapTrader and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining))))) and DrawPlotDataToday, theHalfGap, Double.NaN);
Half_GapFill.SetStyle(Curve.FIRM);
Half_GapFill.SetLineWeight(2);
Half_GapFill.SetDefaultColor(Color.LIME);
Half_GapFill.HideTitle();
def DisplayHalfGapFilled = HalfGapHasFilled and ShowBubbleIfGapFills;
AddChartBubble(WantToDrawLastPosition and isMarketOpen and (ShowPriceBubbles or DisplayHalfGapFilled) and ShowHalfGap and !ItProGapped,
theHalfGap, if !DisplayHalfGapFilled then Concat("HalfGap: ", theHalfGap) else "HalfGap: Filled!", GlobalColor("HalfGap Label"), If (theGap < theHalfGap, yes, no));
# If gaptrader hidden and user wants gap bubbles
AddChartBubble(DrawBubblesToday and HalfGapHasFilled, theHalfGap, "HalfGap: Filled!", GlobalColor("HalfGap Label"), If (theGap < theHalfGap, yes, no));
# FullGap
plot Full_GapFill = If (DrawGapFillTraderZone or (isMarketOpen and (!IsNaN(close) or (!DisplayGapTrader and (((barNumber < DrawingZoneBarNumber + CandlesInADay - If (staticIsMarketOpen, NYSESessionCandleCount, 0))))) or (DisplayGapTrader and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining))))) and DrawPlotDataToday, theGap, Double.NaN);
Full_GapFill.SetStyle(Curve.FIRM);
Full_GapFill.SetLineWeight(2);
Full_GapFill.SetDefaultColor(Color.GREEN);
Full_GapFill.HideTitle();
# Add a bubble on the last bar of our drawing (these work for pre-NYSESession)
def GapUp = If (ActiveBarClose >= theGap, 1, 0);
def ProGapAndGo = If ((GapUp and (ActiveBarClose > (theGap + ProGapAndGoLevel))) or ((!GapUp and (ActiveBarClose < (theGap - ProGapAndGoLevel)))), 1, 0);
def ProGapAndGoPrice = If (GapUp, theGap + ProGapAndGoLevel, theGap - ProGapAndGoLevel);
AddChartBubble(WantToDrawLastPosition and ShowPriceBubbles and ((!FullGapHasFilled and !ItProGapped) or !ShowBubbleIfGapFills), theGap, Concat("FullGap: ", theGap), GlobalColor("FullGap Label"), If (thePivot < theGap, yes, no));
AddChartBubble(WantToDrawLastPosition and (ShowBubbleIfGapFills and (FullGapHasFilled or ItProGapped)), theGap, if FullGapHasFilled then "FullGap: Filled!" else "ProGap & Go!", GlobalColor("FullGap Label"), If (thePivot < theGap, yes, no));
########
#AddChartBubble(isLastValidBar, theGap + 5, ItProGapped);
AddChartBubble(DrawBubblesToday and (FullGapHasFilled or ItProGapped), theGap, if FullGapHasFilled then "FullGap: Filled!" else "ProGap & Go!", GlobalColor("FullGap Label"), If (thePivot < theGap, yes, no));
plot GapRangeHigh = If (DrawGapFillTraderZone, If (GapUp, theGap + ProGapAndGoLevel,
theGap - ProGapAndGoLevel), Double.NaN);
plot GapRangeLow = If (DrawGapFillTraderZone, If (GapUp, theGap + MinimumGapFillLevel,
theGap - MinimumGapFillLevel), Double.NaN);
plot GapRangeNoTrade = If (DrawGapFillTraderZone, If (MinimumGapFillLevel > 0, theGap, Double.NaN), Double.NaN);
# We draw a red dashed line to denote gap and go level
GapRangeHigh.SetDefaultColor(Color.RED);
GapRangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
GapRangeHigh.HideBubble();
GapRangeHigh.HideTitle();
GapRangeLow.SetDefaultColor(GlobalColor("GapFill Entry Zone"));
GapRangeNoTrade.SetDefaultColor(GlobalColor("GapFill Entry Zone"));
GapRangeLow.Hide();
GapRangeLow.HideBubble();
GapRangeLow.HideTitle();
GapRangeNoTrade.Hide();
GapRangeNoTrade.HideBubble();
GapRangeNoTrade.HideTitle();
# Draw the 'Ok to trade zone'
AddCloud(GapRangeHigh, GapRangeLow, GlobalColor("GapFill Entry Zone"), GlobalColor("GapFill Entry Zone"));
# Draw the 'Not Ok to trade zone'
AddCloud(GapRangeNoTrade, GapRangeLow, GlobalColor("GapFill No Entry Zone"), GlobalColor("GapFill No Entry Zone"));
# Add a bubble on the Gap and Go price"
AddChartBubble(ShowPriceBubbles and WantToDrawLastPosition and !FullGapHasFilled and !ItProGapped, ProGapAndGoPrice, Concat("ProGap: ", ProGapAndGoPrice), GlobalColor("ProGap Label"), If (!GapUp, If (ActiveBarClose <= GapRangeHigh, yes, no), If (ActiveBarClose >= GapRangeHigh, no, yes)));
#closeprice tracker #ShowGapTraderHints
plot CurrentPriceIndicator = If (ShowTradeEntryHints and DrawPlotDataToday and DisplayGapTrader and !(AutoHideWhenGapFills and (FullGapHasFilled or ItProGapped)) and (barNumber >= DrawingZoneBarNumber - BarNudge) and (barNumber <= (DrawingZonePaddedBarNumber + NYSESessionCandlesRemaining) + ExtensionLength), ActiveBarClose, Double.NaN);
CurrentPriceIndicator.SetStyle(Curve.FIRM);
CurrentPriceIndicator.SetDefaultColor(GlobalColor("GapTrader Hints"));
CurrentPriceIndicator.SetPaintingStrategy(PaintingStrategy.LINE);
CurrentPriceIndicator.HideBubble();
CurrentPriceIndicator.HideTitle();
#AddChartBubble(isLastvalidBar and ShowGapTraderHints, close, ActiveBarClose);
#plot an up or down arrow depending on the trade
plot TradeArrowUp = If (ShowTradeEntryHints and (WantToDrawFirstPosition or WantToDrawHalfPosition) and !ProGapAndGo and (!GapUp and (ActiveBarClose < (theGap - MinimumGapFillLevel))), ActiveBarClose, Double.NaN);
TradeArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
TradeArrowUp.SetDefaultColor(GlobalColor("GapFill Entry Zone"));
TradeArrowUp.HideBubble();
TradeArrowUp.HideTitle();
plot TradeArrowDown = If (ShowTradeEntryHints and (WantToDrawFirstPosition or WantToDrawHalfPosition) and !ProGapAndGo and (GapUp and (ActiveBarClose > (theGap + MinimumGapFillLevel))), ActiveBarClose, Double.NaN);
TradeArrowDown.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
TradeArrowDown.SetDefaultColor(GlobalColor("GapFill No Entry Zone"));
TradeArrowDown.HideBubble();
TradeArrowDown.HideTitle();
# Add a bubble on the closeprice tracker "Find a long!"
AddChartBubble(ShowTradeEntryHints and WantToDrawLastPositionExt and !ProGapAndGo and (!GapUp and (ActiveBarClose < (theGap - MinimumGapFillLevel))), ActiveBarClose, "Find a Long Entry!", GlobalColor("GapTrader Hints"), no);
# Add a bubble on the closeprice tracker "Find a short!"
AddChartBubble(ShowTradeEntryHints and WantToDrawLastPositionExt and !ProGapAndGo and (GapUp and (ActiveBarClose > (theGap + MinimumGapFillLevel))), ActiveBarClose, "Find a Short Entry!", GlobalColor("GapTrader Hints"));
# Add a bubble on the closeprice tracker "No Trade Zone!"
AddChartBubble(ShowTradeEntryHints and WantToDrawLastPositionExt and ((!GapUp and (ActiveBarClose >= (theGap - MinimumGapFillLevel))) or ((GapUp and (ActiveBarClose <= (theGap + MinimumGapFillLevel))))), ActiveBarClose, "No Trade Zone!", GlobalColor("GapTrader Hints"), If (!GapUp, no, yes));
# Add a bubble on the closeprice tracker "Professional Gap and Go!"
AddChartBubble(ShowTradeEntryHints and WantToDrawLastPositionExt and ProGapAndGo, ActiveBarClose, "Professional Gap and Go!", GlobalColor("GapTrader Hints"), If (!GapUp, no, yes));
# Ok, gapfill can only happen if market is open... so...
AddChartBubble(isMarketOpen and ShowGapTraderHints and WantToDrawLastPositionExt and GapHasFilled, ActiveBarClose, "Gap Has Filled!", GlobalColor("GapTrader Hints"), If (!GapUp, no, yes));
# Orignal source from TOS Next3dFriday Study... Modified by BigWaveDave
# Designed to show 'hints' about expected gapfill odds based on eminiaddict.com rules
# TD Ameritrade IP Company, Inc. (c) 2007-2012
#
def series = 1;
def CurrentYear = GetYear();
def CurrentMonth = GetMonth();
def IsQuarter = (CurrentMonth % 3) == 0;
def FirstDayofMonth = (CurrentYear * 10000 + CurrentMonth * 100 + 1);
def CurrentDOW = GetDayOfWeek(GetYYYYMMDD());
def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
# We don't expect gapfill on the 1st trading day of the month
def IsFirstTradingDayofMonth = GetYYYYMMDD() == FirstDayofMonth;
def Day1DOW1 = GetDayOfWeek(FirstDayofMonth);
def FirstFridayDOM1 = if Day1DOW1 < 6
then 6 - Day1DOW1
else if Day1DOW1 == 6
then 7
else 6;
def RollDOM = FirstFridayDOM1 + 14;
def ExpMonth1 = if RollDOM > CurrentDOM
then CurrentMonth + series - 1
else CurrentMonth + series;
def ExpMonth2 = if ExpMonth1 > 12
then ExpMonth1 - 12
else ExpMonth1;
def ExpYear = if ExpMonth1 > 12
then CurrentYear + 1
else CurrentYear;
def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
def FirstFridayDOM = if Day1DOW < 6
then 6 - Day1DOW
else if Day1DOW == 6
then 7
else 6;
def ExpDOM = FirstFridayDOM + 14;
# Display warning that it's OpEx week
# If today is actually opex, no gapfill expected on OpEx!
def DaysUntilOpex = DaysTillDate(ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM);
def IsRolloverThursday = (IsQuarter and (DaysUntilOpex == 8));
def IsDayAfterRollover = (IsQuarter and (DaysUntilOpex == 7));
# If week before OpEx and it's on a quarter, then display rollover label
AddLabel(ShowTradingDayHints and IsQuarter and (DaysUntilOpex > 8 and DaysUntilOpex <= 11), Concat(Concat("Futures Rollover in ", DaysUntilOpex - 8), " days"), GlobalColor("GapTrader Hints"));
# If Thurs. or Fri. before OpEx and it's on a quarter, then display rollover label
AddLabel(ShowTradingDayHints and (IsRolloverThursday or IsDayAfterRollover), if IsRolloverThursday then "Today is Rollover: GapFill Less Likely" else "Yesterday was Rollover: GapFill Less Likely", GlobalColor("GapTrader Hints"));
# If OpEx week (and OpEx not today), then display informational label
AddLabel(ShowTradingDayHints and (DaysUntilOpex > 1 and DaysUntilOpex <= 5), Concat(Concat("OpEx in ", DaysUntilOpex), " days"), GlobalColor("GapTrader Hints"));
AddLabel(ShowTradingDayHints and (DaysUntilOpex == 1), "OpEx is Tomorrow!", GlobalColor("GapTrader Hints"));
# show OpEx as a "No Gapfill" day
AddLabel(ShowTradingDayHints and (CurrentDOM == RollDOM), "Today is OpEx: GapFill Less Likely", Color.RED);
# show 1st Trading day of month as a "No Gapfill" day
AddLabel(ShowTradingDayHints and IsFirstTradingDayofMonth, "1st Trading Day of Month: GapFill Less Likely", Color.RED);
def NoGapFillExpected = IsFirstTradingDayofMonth or IsRolloverThursday or IsDayAfterRollover or (CurrentDOM == RollDOM);
#def ShowTheOdds = ShowTradingDayOdds and (DisplayGapTraderWindow and !(AutoHideWhenGapFills and (FullGapHasFilled or ItProGapped)));
# Display historical gapfill percentage for day of week
# If not a high probability gapfill day based on eminiaddict.com rules
# Odds are displayed in 'red' otherwise in the "GapTrader Hints" color (orange by default)
AddLabel(ShowTradingDayOdds,
Concat("GapFill Odds For ",
(if CurrentDOW == 1
then Concat("Mon. ", Concat(MondayGapFillOdds, "%")) else
if CurrentDOW == 2
then Concat("Tues. ", Concat(TuesdayGapFillOdds, "%")) else
if CurrentDOW == 3
then Concat("Wed. ", Concat(WednesdayGapFillOdds, "%")) else
if CurrentDOW == 4
then Concat("Thurs. ", Concat(ThursdayGapFillOdds, "%")) else
if CurrentDOW == 5
then Concat("Fri. ", Concat(FridayGapFillOdds, "%")) else "Unknown")),
if NoGapFillExpected then Color.RED else GlobalColor("GapTrader Hints"));
Hi there again, can you please help add to the script when it's 3 days gap up/down and gap not filled? Thank you in advance
plot scan =
(gapUp and gapUp[1] and gapUp[2] and !gapUpFilled and !gapUpFilled[1] and !gapUpFilled[2])
or
(gapDown and gapDown[1] and gapDown[2] and !gapDownFilled and !gapDownFilled[1] and !gapDownFilled[2])
;
hi i cant fiqure out how to turn into a scan? Do u have a shareable link?There are many profitable gap trading strategies out there. You often hear people mention a stock when it's gapping up or gapping down. This is an indicator based on the Buyable Gap-Up Strategy written here.
Before using the script below, I highly recommend this article as it lay out the process of trading gaps.
thinkScript Code
Rich (BB code):# # Copyright 2014 Scott J. Johnson (http://scottjjohnson.com) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # # BuyableGapUpIndicator # # Based on Gil Morales and Chris Kacher's rules for buyable gaps up. # http://www.traderplanet.com/articles/view/164232-gain-your-stock-edge-buyable-gap-up-strategy/ # # This study doesn't work intraday because the volume used is the actual volume # and not the projected end-of-day volume. Instead, this study is useful # in post-analysis to quickly find buyable gaps up. # # TODO: Add logic to handle the current period gaps up by projecting the full day volume # based on the current time and volume so far. # input AverageTrueRangeTimePeriod = 40; input BuyableGapPercentOfATR = 75; # percent of average true range to qualify for as a gap input AverageVolumeTimePeriod = 50; # calculate 50 day MA volume input BuyableGapUpMinVolumePercent = 150; # 150% of 50 day MA volume def AverageTrueRange = reference ATR(AverageTrueRangeTimePeriod, averageType = AverageType.SIMPLE); def OpeningPriceGap = open - high[1]; def AverageVolume = MovingAverage(AverageType.SIMPLE, volume, AverageVolumeTimePeriod ); def GapUp = (OpeningPriceGap >= AverageTrueRange * BuyableGapPercentOfATR / 100) and (volume > AverageVolume * BuyableGapUpMinVolumePercent / 100); AddChartBubble(GapUp > 0, low, “GU", Color.GREEN, no);
Shareable Link
https://tos.mx/Blt9EB
Gap Up Scanner
If you want to scan for buyable gap ups at market open, add the following code to your indicator.
Rich (BB code):plot GU = GapUp; GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); GU.SetDefaultColor(GetColor(8)); GU.SetLineWeight(2);
Switch over to the Scan tab, add a Study filter, enter your indicator's name then scan for GU within X bars.
Credit:
def AverageTrueRange = reference ATR(40, averageType = AverageType.SIMPLE);
def OpeningPriceGap = open - high[1];
def AverageVolume = MovingAverage(AverageType.SIMPLE, volume, 50 );
def GapUp = (OpeningPriceGap >= AverageTrueRange * 75 / 100) and (volume > AverageVolume * 150 / 100);
plot GU = GapUp;
Hi newbieThere are many profitable gap trading strategies out there. You often hear people mention a stock when it's gapping up or gapping down. This is an indicator based on the Buyable Gap-Up Strategy written here.
Before using the script below, I highly recommend this article as it lay out the process of trading gaps.
thinkScript Code
Rich (BB code):# # Copyright 2014 Scott J. Johnson (http://scottjjohnson.com) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS-IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # # BuyableGapUpIndicator # # Based on Gil Morales and Chris Kacher's rules for buyable gaps up. # http://www.traderplanet.com/articles/view/164232-gain-your-stock-edge-buyable-gap-up-strategy/ # # This study doesn't work intraday because the volume used is the actual volume # and not the projected end-of-day volume. Instead, this study is useful # in post-analysis to quickly find buyable gaps up. # # TODO: Add logic to handle the current period gaps up by projecting the full day volume # based on the current time and volume so far. # input AverageTrueRangeTimePeriod = 40; input BuyableGapPercentOfATR = 75; # percent of average true range to qualify for as a gap input AverageVolumeTimePeriod = 50; # calculate 50 day MA volume input BuyableGapUpMinVolumePercent = 150; # 150% of 50 day MA volume def AverageTrueRange = reference ATR(AverageTrueRangeTimePeriod, averageType = AverageType.SIMPLE); def OpeningPriceGap = open - high[1]; def AverageVolume = MovingAverage(AverageType.SIMPLE, volume, AverageVolumeTimePeriod ); def GapUp = (OpeningPriceGap >= AverageTrueRange * BuyableGapPercentOfATR / 100) and (volume > AverageVolume * BuyableGapUpMinVolumePercent / 100); AddChartBubble(GapUp > 0, low, “GU", Color.GREEN, no);
Shareable Link
https://tos.mx/Blt9EB
Gap Up Scanner
If you want to scan for buyable gap ups at market open, add the following code to your indicator.
Rich (BB code):plot GU = GapUp; GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); GU.SetDefaultColor(GetColor(8)); GU.SetLineWeight(2);
Switch over to the Scan tab, add a Study filter, enter your indicator's name then scan for GU within X bars.
Credit:
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.