######################################################################### # BWD_GapFillTrader ToS Study # # Heavily modified 'crash' code. # Author: BigWaveDave. # support@halfwaybacktrading.com # # Version: 2.6 # Release Date: 09/19/13 # Found a bug? Send it to me: dopdahl@gmail.com # # 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 Thanks", default "Absolutely!"}; input ShowVerticalSeparator = {"No", default "Yes"}; input ShowGapTraderHints = {"Nope", default "Yes, please"}; input ShowTradingDayHints = {"No", default "Please do"}; input ShowTradingDayOdds = {"No", default "Yes"}; input AutoHideWhenGapFills = {"No", default "Yes"}; input EnableGapAlerts = {"No", default "Yes"}; input DisplayGapTraderFrom = 0700; input DisplayGapTraderUntil = 1130; 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, show every day", "Yup"}; # 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"));