# This was developed by myself with very little coding experience, just by copy/pasting, trial and error and a BIG help from Pete Hahn (https://www.hahn-tech.com). Using a base free public ADR code and adapting it to my needs. If you like it please consider sending an email just to say hi to tradergt76@gmail.com or thru tweeter @gtichauer input MarketOpen = 930; input MarketClose = 1600; input ADRLength = 14; input ADR_Calculation_from = {Default "Open" , "Low/High"}; input ShowLabelsADR = yes;# in case you use same Study twice on a chart to avoid same data input ShowLabelsTargets = yes;# in case you only need plots on charts input NumberOfDays = 1; # Consider weekends as one Day input Perc_Target_Multiple_ADR = 100; # Percentage Target of ADR input Plot_After_ADR_Hit = yes; #you cna choose to NOT plot any more after target is hit, or just plot a gray linearRegCh100 at the last level. Targets will NOT keep adjusting to low/high after hit. input Bubbles = no; #---------------------------------------------------------- def na = Double.NaN; def okToPlot = GetLastDay() - numberOfDays <= GetDay() ; def OpenCounter = SecondsFromTime(marketOpen); def CloseCounter = SecondsTillTime(marketClose); def MarketHours = if OpenCounter >= 0 and CloseCounter >= 0 then 1 else 0; #---------------------------------------------------------- #Define High and Low of Day def Today ; def Open = open(period = AggregationPeriod.DAY); rec DailyHigh ; rec DailyLow ; Today = if GetDay() != GetDay()[1] then 1 else 0; DailyHigh = if Today then high else if MarketHours then if high > DailyHigh[1] then high else DailyHigh[1] else high; DailyLow = if Today then low else if MarketHours then if low < DailyLow[1] then low else DailyLow[1] else low; # (1) Today Range, (2) (14) Day Avg Range , (3) % Range Today (4/5) TargetRangeHigh and Low def TodayRange = DailyHigh - DailyLow; def ADR = round((Average((high(period = AggregationPeriod.DAY)[1] - low(period = AggregationPeriod.DAY)[1]), ADRLength)),1); def pctADR = Round((TodayRange / ADR) * 100, 0); def ADR_High; def ADR_Low; def AddLabelFromHighLow; switch (ADR_Calculation_from) { case "Low/High": ADR_High = DailyLow + ADR * Perc_Target_Multiple_ADR/100 ; ADR_Low = DailyHigh - ADR * Perc_Target_Multiple_ADR/100; AddLabelFromHighLow=yes; case "Open": ADR_High = Open + ADR * Perc_Target_Multiple_ADR/100 ; ADR_Low = Open - ADR * Perc_Target_Multiple_ADR/100 ; AddLabelFromHighLow=no; }; #Define Conditions: Both ADR NON hit, or any of Low/High ADR Hit def ADR_High_Hit = DailyHigh > ADR_High ; def ADR_Low_Hit = DailyLow < ADR_Low ; def ADR_Not_Hit = ADR_High > DailyHigh and ADR_Low < DailyLow; #Record Last Value UNTIL AvgDailyRange HIT for the day to stop plotting def LastADR_H = if Today then ADR_High else if ADR_High_Hit then LastADR_H[1] else ADR_High ; def LastADR_L = if Today then ADR_Low else if ADR_Low_Hit then LastADR_L[1] else ADR_Low ; #Plot Target High / Low Levels while ADR not Hit plot Target_ADR_High = if okToPlot and MarketHours and ADR_Not_Hit then ADR_High else na; plot Target_ADR_Low = if okToPlot and MarketHours and ADR_Not_Hit then ADR_Low else na; #Plot AFTER ADR High / Low was HIT plot High_AfterHit = if Plot_After_ADR_Hit and okToPlot and MarketHours and !ADR_Not_Hit then LastADR_H else na; plot Low_AfterHit = if Plot_After_ADR_Hit and okToPlot and MarketHours and !ADR_Not_Hit then LastADR_L else na; #Format Lines ADR Targets Target_ADR_High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); Target_ADR_Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); Target_ADR_High.SetlineWeight (5); Target_ADR_Low.SetlineWeight (5); Target_ADR_High.SetDefaultColor(Color.violeT); Target_ADR_Low.SetDefaultColor(Color.violeT); #Format Lines ADR Targets AFTER HIT High_AfterHit.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); Low_AfterHit.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); High_AfterHit.SetlineWeight (5); Low_AfterHit.SetlineWeight (5); High_AfterHit.SetDefaultColor(CreateColor(220,220,220)); Low_AfterHit.SetDefaultColor(CreateColor(220,220,220)); #Plots Labels on Chart with Color Coding-------------------------------- AddLabel(ShowLabelsADR, "(" + ADRLength + ")" + "ADR " + ADR, Color.VIOLET); AddLabel(ShowLabelsADR, " TODAY " + TodayRange, if pctADR < 80 then Color.GRAY else if pctADR > 100 then Color.DARK_GREEN else Color.LIGHT_GREEN); AddLabel(ShowLabelsADR, pctADR + "% ", if pctADR < 80 then Color.GRAY else if pctADR > 100 then Color.DARK_GREEN else Color.LIGHT_GREEN); AddLabel(ShowLabelsTargets,if AddLabelFromHighLow ==1 then "BASED ON L/H-->" else "BASED ON OPEN-->", if DailyLow < LastADR_L or DailyHigh > LastADR_H then Color.DaRK_GREEN else Color.violeT); AddLabel(ShowLabelsTargets,"LOW= "+ LastADR_L , if DailyLow < LastADR_L then Color.DaRK_GREEN else Color.violeT); AddLabel(ShowLabelsTargets, " HIGH=" + LastADR_H, if DailyHigh > LastADR_H then Color.DaRK_GREEN else Color.violeT); #Code for Bubbles FIXED at 1° bar only for reference. AddChartBubble(Bubbles and oktoplot and today, LastADR_H, "TargetHigh", Color.GREEN, yes); AddChartBubble(Bubbles and oktoplot and today, LastADR_L, "TargetLow", Color.RED, no); #Code for Bubbles on LAST bar with value. You can delete # on lines 95 to 98 to make it work, as well as place the # before the code on lines 91-92. BUT CONSIDER it will be too resource intensefull. #def barNum = if IsNaN( close ) then Double.NaN else barNumber(); #def lastBar = HighestAll( barNum ); #AddChartBubble(barnum == LastBar, LastADR_H, "TargetHigh: "+LastADR_H, Color.VIOLET, yes); #AddChartBubble(barnum == LastBar, LastADR_L, "TargetLow: "+LastADR_L, Color.VIOLET, no); #AddLabel(yes, " LOD=" + DailyLow, Color.RED);--> TESTING PURPOUSES #AddLabel(yes, " LAST_ADR_LOW" + DailyHigh, Color.RED); --> TESTING PURPOUSES