Hi @SleepyZ ,
I am using the code you posted in post #18 and flipping the retracement in either an uptrend or downtrend doesn't appear to be working if you select No for "Show Today Only". Is it possible to have it flip for the previous time period aggregations? Right now, it flips all of them based on the current timeframe.
That was in response to what BTExpress posted as his latest version of what he was using. That version was not what I had previously posted in post #16. I often only respond to the request posed and the code presented by the requestor. I did not notice that BTExpress's code was diffeerent in post #17 than what I posted in post #16. Sorry for any confusion.
Here is that previous code in post #16, with an adjustment to the def ymd, that I just noticed was needed to account for higher aggregationperiod choices than DAY. The def ymd was part of logic to flip the fibs.
This should work now for your situation and the higher agg choices than DAY. The code in post #16 was revised to the below code.
Thank you
Ruby:# # WalkingBallista & BenTen # https://usethinkscript.com/d/153-high-and-low-with-fibonacci-retracement-indicator-for-thinkorswim input aggregationPeriod = AggregationPeriod.DAY; input ShowTodayOnly = yes; input showBubble = yes; input length = 21; def bn = BarNumber(); def hh = high(period=aggregationPeriod); def ll = low(period=aggregationPeriod); def ymd = if aggregationPeriod == aggregationPeriod.DAY then getday() else if aggregationPeriod == aggregationPeriod.WEEK then getweek() else if aggregationPeriod == aggregationPeriod.MONTH then getmonth() else getyear(); def candles = !IsNaN(close); def capture = candles and ymd != ymd[1]; def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0); def thisDay = (HighestAll(dayCount) - dayCount) + 1 ; addlabel(highestall(thisday)<21, "Chart Time Interval set to " + highestall(thisday) +" days. Chart Time Interval must be set to at least 20 days"); def ph = if thisDay == 21 then hh else if thisDay < 21 and hh > ph[1] then hh else ph[1]; def pl = if bn == 1 then low else if thisDay == 21 then ll else if thisDay < 21 and ll < pl[1] then ll else pl[1]; def phbar = if hh == ph then bn else Double.NaN; def plbar = if ll == pl then bn else Double.NaN; #AddLabel(1, ph + " " + highestall(phbar) + " " + pl + " " + HighestAll(plbar)); def day = GetDay(); def Month = if GetMonth() == GetLastMonth() then 1 else 0; def year = GetYear(); def lastDay = GetLastDay(); def lastmonth = GetLastMonth(); def lastyear = GetLastYear(); def isToday = If(day == lastDay and Month == lastmonth and year == lastyear, 1, 0); def istodaybarnumber = Highest(if isToday then bn else Double.NaN, length); def PO = open(period = aggregationPeriod); def Today = if GetDay() == GetLastDay() then 1 else 0; def Week = if GetWeek() == GetLastWeek() then 1 else 0; def range = ph - pl; input fib = 1.618; input fib1 = 1.272; input fib2 = 0.618; input fib3 = 0.236; input fib4 = 0.382; input fib5 = 0.5; input fib6 = 0.786; input fib7 = 2.618; plot h; plot h1; plot h2; plot h3; plot h4; plot h5; plot h6; plot h7; plot h8; plot h9; plot h10; plot highofline; plot lowofline; if ShowTodayOnly and !IsNaN(close(period = aggregationPeriod)[-1]) then { h = Double.NaN; h1 = Double.NaN; h2 = Double.NaN; h3 = Double.NaN; h4 = Double.NaN; h5 = Double.NaN; h6 = Double.NaN; h7 = Double.NaN; h8 = Double.NaN; h9 = Double.NaN; h10 = Double.NaN; highofline = Double.NaN; lowofline = Double.NaN; } else { if HighestAll(phbar) > HighestAll(plbar) then { h = ph + range * (fib); h1 = ph + range * (fib1); h2 = ph - range * (fib2); h3 = ph - range * (fib3); h4 = ph - range * (fib4); h5 = ph - range * (fib5); h6 = ph - range * (fib6); h7 = ph - range * (fib7); h8 = pl + range * (fib1); h9 = pl + range * (fib); h10 = pl + range * (fib7); highofline = LowestAll(pl); lowofline = HighestAll(ph); } else { h = ph + range * (fib - 1); h1 = ph + range * (fib1 - 1); h2 = ph + range * (fib2 - 1); h3 = ph + range * (fib3 - 1); h4 = ph + range * (fib4 - 1); h5 = ph + range * (fib5 - 1); h6 = ph + range * (fib6 - 1); h7 = ph + range * (fib7 - 1); h8 = pl - range * (fib1 - 1); h9 = pl - range * (fib - 1); h10 = pl - range * (fib7 - 1); highofline = HighestAll(ph); lowofline = LowestAll(pl); } } h.DefineColor("Color", CreateColor(50, 150, 200)); h.AssignValueColor(h.Color("Color")); h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h1.DefineColor("Color", Color.MAGENTA); h1.AssignValueColor(h1.Color("Color")); h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h2.DefineColor("Color", Color.GREEN); h2.AssignValueColor(h2.Color("Color")); h2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h3.DefineColor("Color", Color.RED); h3.AssignValueColor(h3.Color("Color")); h3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h4.DefineColor("Color", Color.GREEN); h4.AssignValueColor(h4.Color("Color")); h4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h5.DefineColor("Color", Color.YELLOW); h5.AssignValueColor(h5.Color("Color")); h5.SetPaintingStrategy(PaintingStrategy.DASHES); h6.DefineColor("Color", Color.RED); h6.AssignValueColor(h6.Color("Color")); h6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h7.DefineColor("Color", CreateColor(100, 100, 200)); h7.AssignValueColor(h7.Color("Color")); h7.SetPaintingStrategy(PaintingStrategy.LINE); h8.DefineColor("Color", Color.MAGENTA); h8.AssignValueColor(h8.Color("Color")); h8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h9.DefineColor("Color", CreateColor(50, 150, 200)); h9.AssignValueColor(h9.Color("Color")); h9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); h10.DefineColor("Color", CreateColor(100, 100, 200)); h10.AssignValueColor(h10.Color("Color")); h10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); highofline.DefineColor("Color", Color.WHITE); highofline.AssignValueColor(highofline.Color("Color")); highofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); lowofline.DefineColor("Color", Color.WHITE); lowofline.AssignValueColor(highofline.Color("Color")); lowofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); input n = 3; def n1 = n + 1; #AddChartBubble(isnan(close[n]) and !IsNaN(close[n1]), h4[n], concat(concat(fib4*100,"%") , concat(" $", round(h4[n1], 2))), color.green, yes); AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), lowofline[n1], Concat(Concat(0, "%") , Concat(" $", Round(lowofline[n1], 2))), Color.WHITE, yes); AddChartBubble( IsNaN(close[n]) and !IsNaN(close[n1]), highofline[n1], Concat(Concat(100, "%") , Concat(" $", Round(highofline[n1], 2))), Color.WHITE, yes); AddChartBubble( IsNaN(close[n]) and !IsNaN(close[n1]), h4[n1], Concat(Concat(fib4 * 100, "%") , Concat(" $", Round(h4[n1], 2))), Color.GREEN, yes); AddChartBubble( IsNaN(close[n]) and !IsNaN(close[n1]), h2[n1], Concat(Concat(fib2 * 100, "%") , Concat(" $", Round(h2[n1], 2))), Color.GREEN, yes); AddChartBubble( IsNaN(close[n]) and !IsNaN(close[n1]), h3[n1], Concat(Concat(fib3 * 100, "%") , Concat(" $", Round(h3[n1], 2))), Color.RED, yes); AddChartBubble( IsNaN(close[n]) and !IsNaN(close[n1]), h5[n1], Concat(Concat(fib5 * 100, "%") , Concat(" $", Round(h5[n1], 2))), Color.YELLOW, yes); AddChartBubble( IsNaN(close[n]) and !IsNaN(close[n1]), h6[n1], Concat(Concat(fib6 * 100, "%") , Concat(" $", Round(h6[n1], 2))), Color.RED, yes);