######################################################################### # EminiAddict.com # # BWD_TICKDivergenceIndicator ToS Study # # Author: BigWaveDave (dopdahl). # Version: 2.1 # Release Date: 6/26/12 # Email me with bugs: dopdahl@gmail.com # No guarantees as to accuracy expressed or implied # Use at your own discretion # # Changes for v. 2.1 # ======================= # + Option to abbreviate text # # Changes for v. 2.0 # ======================= # + Figured out how to add user configurable alerts. # + Changed text around a bit # + Added user configurable colors # # Changes for v. 1.7 # ======================= # + Fixed definition of rules. Meaning of bullish and bearish were reversed. # # Changes for v. 1.6 # ======================= # + Added check for 'Today' 1min chart. Displays error if not on 'Today' 1min chart # + Fixed logic related to cancelling divergences with matching high tick and price # # This will only work when added to your $TICK chart # A 'Today' 1min $TICK chart is required. # #declare lower; #Uncomment this line to put it in a lower study # once the us session opens, start tracking high and low ticks # also start tracking high and low /es price # The Rules: # ===================== # Bullish divergence exists if we have a new high price after a high TickofDay # In a bullish divergence we expect the markt to go UP # Bearish divergence exists if we have a new low price after a low TickofDay # In a bearish divergence we expect the markt to go DOWN # Both can exist, or neither can exist. # If we enter or exit a bullish/bearish divergence, alert and display indicator # Market Open and Close times in EST. input DivergenceWindowOpenTime = 1000; input EnableDivergenceActiveAlerts = {"No", default "Yes"}; input EnableDivergenceCancelledAlerts = {"No", default "Yes"}; input TextAbbreviationLevel = {default None, Medium, Maximum}; # Some real 'hocus-pocus' to see if the chart is in 'Today' time mode... rec IsAggregationToday = CompoundValue(1, If (((BarNumber() == 1) and (GetLastDay() == GetDay())), 1, IsAggregationToday[1]), If (((BarNumber() == 1) and (GetLastDay() == GetDay())), 1, 0)); def BadAggregationPeriod = (GetAggregationPeriod() != AggregationPeriod.MIN) or (!IsAggregationToday); # Is this bar inside of normal trading hours? def bWindowOpen = If (SecondsTillTime(DivergenceWindowOpenTime) > 0, 0, 1); def isNextDay = (GetDay() != GetDay()[1]) and (GetDayOfWeek(GetYYYYMMDD()[1]) != 5); def AbbrevLevel; switch (TextAbbreviationLevel) { case None: AbbrevLevel = 0; case Medium: AbbrevLevel = 1; case Maximum: AbbrevLevel = 2; } def tickHigh = high("$TICK"); def tickLow = low("$TICK"); def priceHigh = high("/es"); def priceLow = low("/es"); rec HighTOD = CompoundValue(1, If (tickHigh > HighTOD[1], tickHigh, HighTOD[1]), tickHigh); rec LowTOD = CompoundValue(1, If (tickLow < LowTOD[1], tickLow, LowTOD[1]), tickLow); rec HighPOD = CompoundValue(1, If (priceHigh > HighPOD[1], priceHigh, HighPOD[1]), priceHigh); rec LowPOD = CompoundValue(1, If (priceLow < LowPOD[1], priceLow, LowPOD[1]), priceLow); def bNewHighTICK = HighTOD > HighTOD[1]; def bNewLowTICK = LowTOD < LowTOD[1]; def bNewHighPrice = HighPOD > HighPOD[1]; def bNewLowPrice = LowPOD < LowPOD[1]; # That's about all the info we need to determine our divergence status rec bBullishDivergence = CompoundValue(1, If (((bNewHighTICK and !bNewHighPrice) or (bNewHighTICK and bNewHighPrice)), 0, If (!bNewHighTICK and bNewHighPrice, 1, If (!isNextDay, bBullishDivergence[1], 0))), 0); rec bBearishDivergence = CompoundValue(1, If (((bNewLowTICK and !bNewLowPrice) or (bNewLowTICK and bNewLowPrice)), 0, If (!bNewLowTICK and bNewLowPrice, 1, If (!isNextDay, bBearishDivergence[1], 0))), 0); DefineGlobalColor("Hint Color", Color.DARK_ORANGE); DefineGlobalColor("Bullish Color", Color.GREEN); DefineGlobalColor("Bearish Color", Color.RED); AddLabel(bBullishDivergence and bWindowOpen and !BadAggregationPeriod, if (AbbrevLevel == 0) then "Bullish Divergence" else (if AbbrevLevel == 1 then "Bullish Div." else "Bull D."), GlobalColor("Bullish Color")); AddLabel(bBearishDivergence and bWindowOpen and !BadAggregationPeriod, if (AbbrevLevel == 0) then "Bearish Divergence" else (if AbbrevLevel == 1 then "Bearish Div." else "Bear D."), GlobalColor("Bearish Color")); AddLabel(!bBullishDivergence and !bBearishDivergence and bWindowOpen and !BadAggregationPeriod, "No Divergence!", GlobalColor("Hint Color")); def Minutes = DivergenceWindowOpenTime % 100; def Hours = Floor(DivergenceWindowOpenTime / 100); def Minutes10s = Floor(((DivergenceWindowOpenTime % 100)) / 10); def Minutes1s = ((DivergenceWindowOpenTime % 100) % 10); AddLabel(!bWindowOpen and !BadAggregationPeriod and SecondsTillTime(DivergenceWindowOpenTime) > 0, Concat("Waiting until ", Concat(Hours, Concat(":", Concat(Minutes10s, Concat(Minutes1s, " EST"))))), GlobalColor("Hint Color")); # Doesn't matter when it is... If it's bad, it's bad, let the user know. AddLabel(BadAggregationPeriod, "Switch to 'Today' 1m Chart!", GlobalColor("Hint Color")); # Alerts: We alert on active and cancelled, user selectable Alert(bWindowOpen and EnableDivergenceActiveAlerts and bBullishDivergence and (bBullishDivergence != bBullishDivergence[1]), "Bullish Divergence Now Active!", Alert.BAR, Sound.Ding); Alert(bWindowOpen and EnableDivergenceCancelledAlerts and !bBullishDivergence and (bBullishDivergence != bBullishDivergence[1]), "Bullish Divergence Cancelled!", Alert.BAR, Sound.Ding); Alert(bWindowOpen and EnableDivergenceActiveAlerts and bBearishDivergence and (bBearishDivergence != bBearishDivergence[1]), "Bearish Divergence Now Active!", Alert.BAR, Sound.Ding); Alert(bWindowOpen and EnableDivergenceCancelledAlerts and !bBearishDivergence and (bBearishDivergence != bBearishDivergence[1]), "Bearish Divergence Cancelled!", Alert.BAR, Sound.Ding);