High and Low with Fibonacci Retracement Indicator for ThinkorSwim

hi @SleepyZ thanks for sharing this script. i have a question i see that one the anchors is the open but where is the other point being anchored? what am i missing? does not seem to line up with any hi or low, sorry i am very new to all this. and thanks again.

The fib extension tool is different than the fib retracement tool.

The fib extension when anchored to the open, then uses the distance of the first part of three legs of the fib extension tool to create the fib levels over that distance.

See the image in the code posted above with the red TOS fib extension tool overlaid on the chart and how those levels align with the code's levels as denoted in the corresponding bubbles.

Screenshot-2023-03-16-075418.png
 
@BenTen Good evening Mr. Ben, Please if you can help to direct me to the right path. I am looking to build an indicator around fibs levels.... is there a way to obtain an Automatic Fib Retracement that uses the time range method so that timerange_begin/timerange_end inputs like prior day, current day, premarket, and custom user time ranges, with the Fibs levels.
For example Pre-market High P_M and Low P_M from 0:00 am to 9:29 am, and plots that on the chart until 11:59 pm?
And the indicator could allow me to switch from Pre-market high 100% to Pre-market low 0% to Pre-market low 100% to Pre-market high 0% and from there plot the retracement levels. (Please see the attached screenshots with the 2 pre-market examples).

I want it to work mainly with the following levels:
0
23.6
38.2
50.0
61.8
78.6
100.0
127.3
144.0
161.8
261.8
423.6

Thank you
Good afternoon @SleepyZ, a few days ago I send a message to @BenTen about an Automatic Fib Retracement Indicator, and he sent me a link where I could find what I needed, I have been reading the posts in this forum, I wanted to thank you for such an excellent job, I have copied the code in the post #25, #27 and #31, which I have tested to see if they do what I need, and the codes take data that doesn't fit what I want to do. In my message to Mr BenTen I explained that I needed the fibo indicator to use the time range method so that timerange_begin/timerange_end inputs like prior day, premarket, and custom user time ranges, with the Fibs levels, using the high and low of the time range.

For example Pre-market High and Pre-Market Low (0:00 am to 9:05 am), especially in the Premarket time range, you can have the option to select the End Time (9:00 am, 9:03 am or 9: 29am) and plots that on the chart, as I said before, the codes in posts #25, #27 and #31 are the closest I have been able to see in my search in the forums about Fib but none allow me the option of taking the high and low of the Pre-market.
In the chart that you shared in post #25 that takes the previous day's high/low and that can flip there are two days in which the important fibo levels go in the opposite direction to the price movement (Monday and Wednesday) that is why when I sent my message to Mr BenTen, I was wondering if a switch could be made to the direction of the levels so that their projections were consistent with the movement of the asset's price.
Thank you very much once again for such an excellent job.

I am attaching the message that I sent to Mr BenTen and the two examples with the fibo levels when the price goes up or down.
 

Attachments

  • Screenshot 2023-06-19 220350 Fibo Levels.png
    Screenshot 2023-06-19 220350 Fibo Levels.png
    131.6 KB · Views: 298
  • Screenshot 2023-06-20 001316 Fibo_Levels_BABA.png
    Screenshot 2023-06-20 001316 Fibo_Levels_BABA.png
    97.8 KB · Views: 280
Good afternoon @SleepyZ, a few days ago I send a message to @BenTen about an Automatic Fib Retracement Indicator, and he sent me a link where I could find what I needed, I have been reading the posts in this forum, I wanted to thank you for such an excellent job, I have copied the code in the post #25, #27 and #31, which I have tested to see if they do what I need, and the codes take data that doesn't fit what I want to do. In my message to Mr BenTen I explained that I needed the fibo indicator to use the time range method so that timerange_begin/timerange_end inputs like prior day, premarket, and custom user time ranges, with the Fibs levels, using the high and low of the time range.

For example Pre-market High and Pre-Market Low (0:00 am to 9:05 am), especially in the Premarket time range, you can have the option to select the End Time (9:00 am, 9:03 am or 9: 29am) and plots that on the chart, as I said before, the codes in posts #25, #27 and #31 are the closest I have been able to see in my search in the forums about Fib but none allow me the option of taking the high and low of the Pre-market.
In the chart that you shared in post #25 that takes the previous day's high/low and that can flip there are two days in which the important fibo levels go in the opposite direction to the price movement (Monday and Wednesday) that is why when I sent my message to Mr BenTen, I was wondering if a switch could be made to the direction of the levels so that their projections were consistent with the movement of the asset's price.
Thank you very much once again for such an excellent job.

I am attaching the message that I sent to Mr BenTen and the two examples with the fibo levels when the price goes up or down.

The code in the following link may help do what you want. https://usethinkscript.com/threads/...vels-indicator-for-thinkorswim.14/post-117068
 
Good evening @SleepyZ, thank you very much for the prompt response, after reviewing different indicators that plot fibo levels automatically, I found an indicator in the link you suggested, I am attaching the link of the indicator that is close to what I need (post #246).
The difference with this indicator is that instead of taking the high and low of the previous day, I need it to take the high and low of the Pre-Market (0:00 am to 9:30 am), maybe it could add this option to the fibo indicator code that is in post #246.
On the other hand, this indicator traces the important fibo levels (from 0 to 2.0) every day as if the price always went up. I comment on this because studying this indicator on days 6-20 and 6-21, the movement of the SPY was downward. and the indicator traced levels 0 to 2.0 up (this is where the indicator would need levels 0 to 2.0 to flip down, I have attached a screenshot of those days). This is where I was analyzing if the logic of the Opening Range Breakout Indicator by Mobius could be used, where using the timeframe of the first 5 or 15 minutes (first bar in one of those timeframes) up to 30 minutes from when the market opens the automatic indicator of fibo levels would have to flip down.
And I don't know if the bubbles of the fibo levels could be set to the left of the chart, so if the time frame is changed on the chart, the bubbles would not have to be moving. Once again thank you so much for your help.
See if this helps. Picture is set to showtodayonly == yes. You can move the bubbles left/right at the bubblemover input.

Link of ORB Indicator by Mobius
 

Attachments

  • Screenshot 2023-07-02 004955_SPY_6-20 and 6-21 Fibo_Levels.png
    Screenshot 2023-07-02 004955_SPY_6-20 and 6-21 Fibo_Levels.png
    152.7 KB · Views: 299
Last edited:
Good evening @SleepyZ, thank you very much for the prompt response, after reviewing different indicators that plot fibo levels automatically, I found an indicator in the link you suggested, I am attaching the link of the indicator that is close to what I need (post #246).
The difference with this indicator is that instead of taking the high and low of the previous day, I need it to take the high and low of the Pre-Market (0:00 am to 9:30 am), maybe it could add this option to the fibo indicator code that is in post #246.
On the other hand, this indicator traces the important fibo levels (from 0 to 2.0) every day as if the price always went up. I comment on this because studying this indicator on days 6-20 and 6-21, the movement of the SPY was downward. and the indicator traced levels 0 to 2.0 up (this is where the indicator would need levels 0 to 2.0 to flip down, I have attached a screenshot of those days). This is where I was analyzing if the logic of the Opening Range Breakout Indicator by Mobius could be used, where using the timeframe of the first 5 or 15 minutes (first bar in one of those timeframes) up to 30 minutes from when the market opens the automatic indicator of fibo levels would have to flip down.
And I don't know if the bubbles of the fibo levels could be set to the left of the chart, so if the time frame is changed on the chart, the bubbles would not have to be moving. Once again thank you so much for your help.


Link of ORB Indicator by Mobius

This is a mod to the link that I referenced above that should work with the time frame input.

The fibs are plotted as TOS fib tool plots them based upon whether the high or low occurs first. I have added a manual_flip input that will reverse those. This many not work exactly how you might want for all fibs, but may allow you to flip the last set of fibs to how you want to view them.

I have added the additional fib levels that you indicated you use. The levels are the same outside 0 to 100, just the naming. For example, the difference from 0 to -618 is the same difference as 100 to 1618


Screenshot 2023-07-02 082719.png

Code:
#Auto_Fibs_TimeRange_Flip_0_100_time_chart_version

input start = 0000;
input end   = 0929;
input showtodayonly  = no;
input bubblemover    = 0;
input showbubbles    = yes;
input extendlines    = yes;
input show_trendline = yes;

def sec1    = SecondsFromTime(start);
def sec2    = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
              (sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
              (sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
                  if isTime1[1] == 0 and isTime1 == 1
                  then 1
                  else if isTime2
                  then 0
                  else aftermarket[1], 0);

def bars   = 100000;
def bn     = BarNumber();
def na     = Double.NaN;

def period = bn - 1;
def count  = CompoundValue(1,
             if aftermarket and period != period[1]
             then (count[1] + period - period[1]) % bars
             else count[1], 0);
def cond   = count < count[1] + period - period[1];

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = bars, "pricePerRow" = PricePerRow.TICKSIZE , "value area percent" = 0);

def hProfile = if aftermarket and IsNaN(vol.GetHighest())
               then hProfile[1]
               else if period != period[1]
               then vol.GetHighest()
               else hProfile[1];
def lProfile = if aftermarket and IsNaN(vol.GetLowest())
               then lProfile[1]
               else if period != period[1]
               then vol.GetLowest()
               else lProfile[1];

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow  = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

def hrange = ProfileHigh;
def lrange = ProfileLow;


input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);


input showtimerange_label = yes;
AddLabel(showtimerange_label, "HL Time Range: " + AsPrice(start) + " to " + AsPrice(end), Color.YELLOW);

input Fpos236 = .236;
input Fpos382 = .382;
input Fpos50  = .5;
input Fpos618 = .618;
input Fpos764 = .764;
input Fpos1618 = 1.618;
input Fneg618  = -0.618;
input Fpos1273 = 1.273;
input Fneg1273 = -0.273;
input Fpos1440 = 1.440;
input Fneg1440 = -0.440;
input Fpos2618 = 2.618;
input Fneg2618 = -1.618;
input Fpos4236 = 4.236;
input Fneg4236 = -3.236;

def range  = AbsValue(hrange - lrange);
def F236   = hrange - (range * Fpos236);
def F382   = hrange - (range * Fpos382);
def F50    = hrange - (range * Fpos50);
def F618   = hrange - (range * Fpos618);
def F764   = hrange - (range * Fpos764);
def F1618   = hrange - (range * Fpos1618);
def F_618   = hrange - (range * Fneg618);
def F1273   = hrange - (range * Fpos1273);
def F_1273  = hrange - (range * Fneg1273);
def F1440   = hrange - (range * Fpos1440);
def F_1440  = hrange - (range * Fneg1440);
def F2618   = hrange - (range * Fpos2618);
def F_2618  = hrange - (range * Fneg2618);
def F4236   = hrange - (range * Fpos4236);
def F_4236  = hrange - (range * Fneg4236);

plot ORH;
plot ORL;
plot Fib50;
plot Fib236;
plot Fib382;
plot Fib618;
plot Fib764;
plot Fib1618;
plot Fib_618;
plot Fib1273;
plot Fib_1273;
plot Fib1440;
plot Fib_1440;
plot Fib2618;
plot Fib_2618;
plot Fib4236;
plot Fib_4236;

def dataCount = CompoundValue(1, if (aftermarket != aftermarket[1]) then dataCount[1] + 1 else dataCount[1], 0);

if showtodayonly and HighestAll(dataCount) - dataCount > 2
then {
    ORH      = Double.NaN;
    ORL      = Double.NaN;
    Fib50    = Double.NaN;
    Fib236   = Double.NaN;
    Fib382   = Double.NaN;
    Fib618   = Double.NaN;
    Fib764   = Double.NaN;
    Fib1618   = Double.NaN;
    Fib_618   = Double.NaN;
    Fib1273   = Double.NaN;
    Fib_1273  = Double.NaN;
    Fib1440   = Double.NaN;
    Fib_1440  = Double.NaN;
    Fib2618   = Double.NaN;
    Fib_2618  = Double.NaN;
    Fib4236   = Double.NaN;
    Fib_4236  = Double.NaN;

} else {
    ORH      = hrange;
    ORL      = lrange;
    Fib50    = F50;
    Fib236   = F236;
    Fib382   = F382;
    Fib618   = F618;
    Fib764   = F764;
    Fib1618  = F1618;
    Fib_618  = F_618;
    Fib1273   = F1273;
    Fib_1273  = F_1273;
    Fib1440   = F1440;
    Fib_1440  = F_1440;
    Fib2618   = F2618;
    Fib_2618  = F_2618;
    Fib4236   = F4236;
    Fib_4236  = F_4236;

}

ORH.SetDefaultColor(Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.DASHES);
ORH.SetLineWeight(2);

ORL.SetDefaultColor(Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.DASHES);
ORL.SetLineWeight(2);

Fib50.SetDefaultColor(Color.WHITE);
Fib50.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib50.SetLineWeight(1);

Fib236.SetDefaultColor(Color.CYAN);
Fib236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib236.SetLineWeight(1);

Fib382.SetDefaultColor(Color.YELLOW);
Fib382.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib382.SetLineWeight(1);

Fib618.SetDefaultColor(Color.YELLOW);
Fib618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib618.SetLineWeight(1);

Fib764.SetDefaultColor(Color.CYAN);
Fib764.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib764.SetLineWeight(2);

Fib1618.SetDefaultColor(Color.YELLOW);
Fib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1618.SetLineWeight(1);

Fib_618.SetDefaultColor(Color.YELLOW);
Fib_618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_618.SetLineWeight(1);

Fib1273.SetDefaultColor(Color.YELLOW);
Fib1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1273.SetLineWeight(1);

Fib_1273.SetDefaultColor(Color.YELLOW);
Fib_1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1273.SetLineWeight(1);

Fib1440.SetDefaultColor(Color.YELLOW);
Fib1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1440.SetLineWeight(1);

Fib_1440.SetDefaultColor(Color.YELLOW);
Fib_1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1440.SetLineWeight(1);

Fib2618.SetDefaultColor(Color.YELLOW);
Fib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib2618.SetLineWeight(1);

Fib_2618.SetDefaultColor(Color.YELLOW);
Fib_2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_2618.SetLineWeight(1);

Fib4236.SetDefaultColor(Color.YELLOW);
Fib4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib4236.SetLineWeight(1);

Fib_4236.SetDefaultColor(Color.YELLOW);
Fib_4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_4236.SetLineWeight(1);

input manual_flip = no;
def mo   = bubblemover;
def mo1  = mo + 1;

def lo1 = if low  == lProfile then 1 else 0;
def hi1 = if high == hProfile then 1 else 0;
def hbar = if aftermarket and hi1 == 1 then bn else hbar[1];
def lbar = if aftermarket and lo1 == 1 then bn else lbar[1];
def last = IsNaN(close[mo + 1]) and !IsNaN(close[mo + 1]);
plot xhbar = if manual_flip then lbar else hbar;
plot xlbar = if manual_flip then hbar else lbar;
xhbar.SetHiding(yes);
xlbar.SetHiding(yes);

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORH[mo + 1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 0 else 100),
ORH.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORL[mo + 1], (if xhbar[mo + 1] > xlbar[mo + 1] then 100 else 0),
ORL.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib50[mo1 + 1],
"50",
Fib50.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 236 else 764),
Fib236.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib382[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 382 else 618),
Fib382.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 618 else 382),
Fib618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib764[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 764 else 236),
Fib764.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1618 else -618),
Fib1618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -618 else 1618),
Fib_618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1273 else -273),
Fib1273.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -273 else 1273),
Fib_1273.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1440 else -440),
Fib1440.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -440 else 1440),
Fib_1440.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 2618 else -1618),
Fib2618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -1618 else 2618),
Fib_2618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 4236 else -3236),
Fib4236.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -3236 else 4236),
Fib_4236.TakeValueColor());


def hbar1 = if (aftermarket or aftermarket[1]) and hi1 == 1 then 1 else 0;
def lbar1 = if (aftermarket or aftermarket[1]) and lo1 == 1 then 1 else 0;

plot xhbar1 = hbar1;
plot xlbar1 = lbar1;
xhbar1.SetHiding(yes);
xlbar1.SetHiding(yes);

plot xline = if show_trendline then if aftermarket and !IsNaN(xhbar1) then hrange else if aftermarket and !IsNaN(xlbar1) then hrange else na else na;
xline.EnableApproximation();
;
 
This is a mod to the link that I referenced above that should work with the time frame input.

The fibs are plotted as TOS fib tool plots them based upon whether the high or low occurs first. I have added a manual_flip input that will reverse those. This many not work exactly how you might want for all fibs, but may allow you to flip the last set of fibs to how you want to view them.

I have added the additional fib levels that you indicated you use. The levels are the same outside 0 to 100, just the naming. For example, the difference from 0 to -618 is the same difference as 100 to 1618
Good evening @SleepyZ, I am very grateful for the excellent indicator that you have made, I really appreciate it very much. I have spent the whole afternoon using the indicator and practicing with different assets, I have a question and excuse my ignorance but I have noticed that in stocks like Meta, Netflix, Tesla the blue vertical line coincides with 0:00 am (Roll Over Line of the platform) and from there draw the Fibo levels; but in the QQQ and SPY the blue line does not coincide with the vertical dotted line of the platform that indicates the Roll Over of these ETFs since these are generated at 1:00 am, I don't know if the indicator code could be adjusted so that draw the blue line coincides with the Roll Over Line of the platform automatically for the ETFs and in another case for the futures, and from there the Pre-Market fibo levels are drawn for the ETFs.
I am attaching screenshots of the SPY where I point out the difference between the blue line and the rollover line, on the other hand, I don't know if it would be possible to create a label that indicates that the Fibo levels are on auto or manual option.
Since the market is closed I don't know where the bubbles of the levels are shown or located when the market is open, in the screenshot I have marked them and I would like the bubbles of the current day to be shown around where the blue line is (Roll Over Line) since the indicator shows the bubbles (levels of the previous day) on the blue line that marks the beginning of the new day and it makes me confused. I apologize if is it a bit too confusing the way I try to explain the changes to the settings for the indicator, I'm just grateful for the help and the excellent work you do @SleepyZ.
 

Attachments

  • Screenshot 2023-07-02 _SPY_BUBBLE_Levels.png
    Screenshot 2023-07-02 _SPY_BUBBLE_Levels.png
    155.6 KB · Views: 265
  • Screenshot 2023-07-02_Fibo_Time_Range_Flip.png
    Screenshot 2023-07-02_Fibo_Time_Range_Flip.png
    224.3 KB · Views: 261
Good evening @SleepyZ, I am very grateful for the excellent indicator that you have made, I really appreciate it very much. I have spent the whole afternoon using the indicator and practicing with different assets, I have a question and excuse my ignorance but I have noticed that in stocks like Meta, Netflix, Tesla the blue vertical line coincides with 0:00 am (Roll Over Line of the platform) and from there draw the Fibo levels; but in the QQQ and SPY the blue line does not coincide with the vertical dotted line of the platform that indicates the Roll Over of these ETFs since these are generated at 1:00 am, I don't know if the indicator code could be adjusted so that draw the blue line coincides with the Roll Over Line of the platform automatically for the ETFs and in another case for the futures, and from there the Pre-Market fibo levels are drawn for the ETFs.
I am attaching screenshots of the SPY where I point out the difference between the blue line and the rollover line, on the other hand, I don't know if it would be possible to create a label that indicates that the Fibo levels are on auto or manual option.
Since the market is closed I don't know where the bubbles of the levels are shown or located when the market is open, in the screenshot I have marked them and I would like the bubbles of the current day to be shown around where the blue line is (Roll Over Line) since the indicator shows the bubbles (levels of the previous day) on the blue line that marks the beginning of the new day and it makes me confused. I apologize if is it a bit too confusing the way I try to explain the changes to the settings for the indicator, I'm just grateful for the help and the excellent work you do @SleepyZ.

The time range can be adjusted at the input screen to start at 0100 if needed. I am not aware of any code in thinkscript to determine which symbols have rollover times.

The bubbles for each time range are on the right side. Bubbles are sometimes tricky to place, especially when flipping the fibs. I found it most reliable plotting them on the right side and decided not to make them available for the left side.
 
The time range can be adjusted at the input screen to start at 0100 if needed. I am not aware of any code in thinkscript to determine which symbols have rollover times.

The bubbles for each time range are on the right side. Bubbles are sometimes tricky to place, especially when flipping the fibs. I found it most reliable plotting them on the right side and decided not to make them available for the left side.
Thank you @SleepyZ for your prompt response, and explanation. It would be possible a label that indicates that the Fibo levels are on auto or manual option?
 
Thank you @SleepyZ for your prompt response, and explanation. It would be possible a label that indicates that the Fibo levels are on auto or manual option?


Add the following to the end of your study

Code:
input show_flip_mode = yes;
AddLabel(show_flip_mode, if manual_flip == yes then "Manual Flip Mode" else "Auto Flip Mode", Color.YELLOW);
 
Add the following to the end of your study
Thank you @SleepyZ it works perfectly.
I keep testing the indicator, to be sure that the levels drawn by the indicator are correct, I have found some divergences when I compare the levels drawn by the indicator with the fibo levels that I draw with the TOS tool, today for example I am attaching a Tesla chart from today where I have deactivated the option of the extension lines of the indicator to be able to compare and validate the fibo levels; As you can see in the chart, the difference is that line 0 (Pre-Market Low) is drawn by not taking the first green candle with the wick (to confirm my Pre-Market low and high I have an indicator that draws only those two levels), I have tried different setups changing the start time to 001, 005, 100, 200, 300 and line 0 remains the same, it does not change that level on the chart, I don't know if the code of the indicator could be adjusted to fix this.
I don't know how to program, but all morning I have tried to add level 786 in the indicator created by you and I have only gotten errors, since the indicator does not allow me to change the level 764 to 786, it seems to me that the values you have are fixed set in the indicator. Level 786 is important for my level plan. Thank you very much for your valuable help, I just hope that these adjustments can be made in the indicator.
 

Attachments

  • Screenshot 2023-07-03  Tesla_07--3-23.png
    Screenshot 2023-07-03 Tesla_07--3-23.png
    117.2 KB · Views: 260
Thank you @SleepyZ it works perfectly.
I keep testing the indicator, to be sure that the levels drawn by the indicator are correct, I have found some divergences when I compare the levels drawn by the indicator with the fibo levels that I draw with the TOS tool, today for example I am attaching a Tesla chart from today where I have deactivated the option of the extension lines of the indicator to be able to compare and validate the fibo levels; As you can see in the chart, the difference is that line 0 (Pre-Market Low) is drawn by not taking the first green candle with the wick (to confirm my Pre-Market low and high I have an indicator that draws only those two levels), I have tried different setups changing the start time to 001, 005, 100, 200, 300 and line 0 remains the same, it does not change that level on the chart, I don't know if the code of the indicator could be adjusted to fix this.
I don't know how to program, but all morning I have tried to add level 786 in the indicator created by you and I have only gotten errors, since the indicator does not allow me to change the level 764 to 786, it seems to me that the values you have are fixed set in the indicator. Level 786 is important for my level plan. Thank you very much for your valuable help, I just hope that these adjustments can be made in the indicator.

This image below shows the wick on the 800 candle is the reason for the zero line today on TSLA 5m chart as far as I can see. I assume that this circled candle may have been adjusted manually on your chart, but did not affect the code, which appears to be working correctly. There are always data clitches or bad data that can affect code.

Please note that for stocks, you should adjust the start time to 0400 for premarket.

I have changed the 764 to 786 for you.

Screenshot 2023-07-03 145755.png
Code:
#Auto_Fibs_TimeRange_Flip_0_100_time_chart_version

input start = 0400;
input end   = 0929;
input showtodayonly  = no;
input bubblemover    = 0;
input showbubbles    = yes;
input extendlines    = yes;
input show_trendline = yes;

def sec1    = SecondsFromTime(start);
def sec2    = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
              (sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
              (sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
                  if isTime1[1] == 0 and isTime1 == 1
                  then 1
                  else if isTime2
                  then 0
                  else aftermarket[1], 0);

def bars   = 100000;
def bn     = BarNumber();
def na     = Double.NaN;

def period = bn - 1;
def count  = CompoundValue(1,
             if aftermarket and period != period[1]
             then (count[1] + period - period[1]) % bars
             else count[1], 0);
def cond   = count < count[1] + period - period[1];

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = bars, "pricePerRow" = PricePerRow.TICKSIZE , "value area percent" = 0);

def hProfile = if aftermarket and IsNaN(vol.GetHighest())
               then hProfile[1]
               else if period != period[1]
               then vol.GetHighest()
               else hProfile[1];
def lProfile = if aftermarket and IsNaN(vol.GetLowest())
               then lProfile[1]
               else if period != period[1]
               then vol.GetLowest()
               else lProfile[1];

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow  = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

def hrange = ProfileHigh;
def lrange = ProfileLow;


input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);


input showtimerange_label = yes;
AddLabel(showtimerange_label, "HL Time Range: " + AsPrice(start) + " to " + AsPrice(end), Color.YELLOW);

input Fpos236 = .236;
input Fpos382 = .382;
input Fpos50  = .5;
input Fpos618 = .618;
input Fpos764 = .786;
input Fpos1618 = 1.618;
input Fneg618  = -0.618;
input Fpos1273 = 1.273;
input Fneg1273 = -0.273;
input Fpos1440 = 1.440;
input Fneg1440 = -0.440;
input Fpos2618 = 2.618;
input Fneg2618 = -1.618;
input Fpos4236 = 4.236;
input Fneg4236 = -3.236;

def range  = AbsValue(hrange - lrange);
def F236   = hrange - (range * Fpos236);
def F382   = hrange - (range * Fpos382);
def F50    = hrange - (range * Fpos50);
def F618   = hrange - (range * Fpos618);
def F764   = hrange - (range * Fpos764);
def F1618   = hrange - (range * Fpos1618);
def F_618   = hrange - (range * Fneg618);
def F1273   = hrange - (range * Fpos1273);
def F_1273  = hrange - (range * Fneg1273);
def F1440   = hrange - (range * Fpos1440);
def F_1440  = hrange - (range * Fneg1440);
def F2618   = hrange - (range * Fpos2618);
def F_2618  = hrange - (range * Fneg2618);
def F4236   = hrange - (range * Fpos4236);
def F_4236  = hrange - (range * Fneg4236);

plot ORH;
plot ORL;
plot Fib50;
plot Fib236;
plot Fib382;
plot Fib618;
plot Fib764;
plot Fib1618;
plot Fib_618;
plot Fib1273;
plot Fib_1273;
plot Fib1440;
plot Fib_1440;
plot Fib2618;
plot Fib_2618;
plot Fib4236;
plot Fib_4236;

def dataCount = CompoundValue(1, if (aftermarket != aftermarket[1]) then dataCount[1] + 1 else dataCount[1], 0);

if showtodayonly and HighestAll(dataCount) - dataCount > 2
then {
    ORH      = Double.NaN;
    ORL      = Double.NaN;
    Fib50    = Double.NaN;
    Fib236   = Double.NaN;
    Fib382   = Double.NaN;
    Fib618   = Double.NaN;
    Fib764   = Double.NaN;
    Fib1618   = Double.NaN;
    Fib_618   = Double.NaN;
    Fib1273   = Double.NaN;
    Fib_1273  = Double.NaN;
    Fib1440   = Double.NaN;
    Fib_1440  = Double.NaN;
    Fib2618   = Double.NaN;
    Fib_2618  = Double.NaN;
    Fib4236   = Double.NaN;
    Fib_4236  = Double.NaN;

} else {
    ORH      = hrange;
    ORL      = lrange;
    Fib50    = F50;
    Fib236   = F236;
    Fib382   = F382;
    Fib618   = F618;
    Fib764   = F764;
    Fib1618  = F1618;
    Fib_618  = F_618;
    Fib1273   = F1273;
    Fib_1273  = F_1273;
    Fib1440   = F1440;
    Fib_1440  = F_1440;
    Fib2618   = F2618;
    Fib_2618  = F_2618;
    Fib4236   = F4236;
    Fib_4236  = F_4236;

}

ORH.SetDefaultColor(Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.DASHES);
ORH.SetLineWeight(2);

ORL.SetDefaultColor(Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.DASHES);
ORL.SetLineWeight(2);

Fib50.SetDefaultColor(Color.WHITE);
Fib50.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib50.SetLineWeight(1);

Fib236.SetDefaultColor(Color.CYAN);
Fib236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib236.SetLineWeight(1);

Fib382.SetDefaultColor(Color.YELLOW);
Fib382.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib382.SetLineWeight(1);

Fib618.SetDefaultColor(Color.YELLOW);
Fib618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib618.SetLineWeight(1);

Fib764.SetDefaultColor(Color.CYAN);
Fib764.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib764.SetLineWeight(2);

Fib1618.SetDefaultColor(Color.YELLOW);
Fib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1618.SetLineWeight(1);

Fib_618.SetDefaultColor(Color.YELLOW);
Fib_618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_618.SetLineWeight(1);

Fib1273.SetDefaultColor(Color.YELLOW);
Fib1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1273.SetLineWeight(1);

Fib_1273.SetDefaultColor(Color.YELLOW);
Fib_1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1273.SetLineWeight(1);

Fib1440.SetDefaultColor(Color.YELLOW);
Fib1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1440.SetLineWeight(1);

Fib_1440.SetDefaultColor(Color.YELLOW);
Fib_1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1440.SetLineWeight(1);

Fib2618.SetDefaultColor(Color.YELLOW);
Fib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib2618.SetLineWeight(1);

Fib_2618.SetDefaultColor(Color.YELLOW);
Fib_2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_2618.SetLineWeight(1);

Fib4236.SetDefaultColor(Color.YELLOW);
Fib4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib4236.SetLineWeight(1);

Fib_4236.SetDefaultColor(Color.YELLOW);
Fib_4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_4236.SetLineWeight(1);

input manual_flip = no;
def mo   = bubblemover;
def mo1  = mo + 1;

def lo1 = if low  == lProfile then 1 else 0;
def hi1 = if high == hProfile then 1 else 0;
def hbar = if aftermarket and hi1 == 1 then bn else hbar[1];
def lbar = if aftermarket and lo1 == 1 then bn else lbar[1];
def last = IsNaN(close[mo + 1]) and !IsNaN(close[mo + 1]);
plot xhbar = if manual_flip then lbar else hbar;
plot xlbar = if manual_flip then hbar else lbar;
xhbar.SetHiding(yes);
xlbar.SetHiding(yes);

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORH[mo + 1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 0 else 100),
ORH.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORL[mo + 1], (if xhbar[mo + 1] > xlbar[mo + 1] then 100 else 0),
ORL.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib50[mo1 + 1],
"50",
Fib50.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 236 else 786),
Fib236.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib382[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 382 else 618),
Fib382.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 618 else 382),
Fib618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib764[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 786 else 236),
Fib764.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1618 else -618),
Fib1618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -618 else 1618),
Fib_618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1273 else -273),
Fib1273.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -273 else 1273),
Fib_1273.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1440 else -440),
Fib1440.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -440 else 1440),
Fib_1440.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 2618 else -1618),
Fib2618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -1618 else 2618),
Fib_2618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 4236 else -3236),
Fib4236.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -3236 else 4236),
Fib_4236.TakeValueColor());


def hbar1 = if (aftermarket or aftermarket[1]) and hi1 == 1 then 1 else 0;
def lbar1 = if (aftermarket or aftermarket[1]) and lo1 == 1 then 1 else 0;

plot xhbar1 = hbar1;
plot xlbar1 = lbar1;
xhbar1.SetHiding(yes);
xlbar1.SetHiding(yes);

plot xline = if show_trendline then if aftermarket and !IsNaN(xhbar1) then hrange else if aftermarket and !IsNaN(xlbar1) then hrange else na else na;
xline.EnableApproximation();
;
input show_flip_mode = yes;
AddLabel(show_flip_mode, if manual_flip == yes then "Manual Flip Mode" else "Auto Flip Mode", Color.YELLOW);
 
This indicator for ThinkorSwim takes the high and low of the previous week or month and add Fibonacci retracement levels to create potential support and resistance levels. You can also use the high and low of the previous day, yearly, etc. Up to you to select the right timeframe to help your trading style.

View attachment 4487

thinkScript Code

Rich (BB code):
#
# WalkingBallista & BenTen
# https://usethinkscript.com/d/153-high-and-low-with-fibonacci-retracement-indicator-for-thinkorswim
input aggregationPeriod = AggregationPeriod.DAY;
input ShowTodayOnly = yes;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
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 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib-1);
plot h1 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib1-1);
plot h2 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib2-1);
plot h3 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib3-1);
plot h4 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib4-1);
plot h5 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib5-1);
plot h6 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib6-1);
plot h7 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib7-1);
plot h8 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib1-1);
plot h9 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib-1);
plot h10 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib7-1);

h.DefineColor("Color", Color.DARK_RED);
h.AssignValueColor(h.color("Color"));
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h1.DefineColor("Color", Color.RED);
h1.AssignValueColor(h1.color("Color"));
h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h2.DefineColor("Color", Color.RED);
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.RED);
h4.AssignValueColor(h3.color("Color"));
h4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h5.DefineColor("Color", Color.RED);
h5.AssignValueColor(h3.color("Color"));
h5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h6.DefineColor("Color", Color.RED);
h6.AssignValueColor(h3.color("Color"));
h6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h7.DefineColor("Color", Color.RED);
h7.AssignValueColor(h3.color("Color"));
h7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h8.DefineColor("Color", Color.RED);
h8.AssignValueColor(h3.color("Color"));
h8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h9.DefineColor("Color", Color.RED);
h9.AssignValueColor(h3.color("Color"));
h9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h10.DefineColor("Color", Color.RED);
h10.AssignValueColor(h3.color("Color"));
h10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot highofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH;
highofline.DefineColor("Color", Color.YELLOW);
highofline.AssignValueColor(highofline.color("Color"));
highofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lowofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL;
lowofline.DefineColor("Color", Color.YELLOW);
lowofline.AssignValueColor(highofline.color("Color"));
lowofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Shareable Link

https://tos.mx/UoIukn

Video Tutorial

Well done! 💯
 
This image below shows the wick on the 800 candle is the reason for the zero line today on TSLA 5m chart as far as I can see. I assume that this circled candle may have been adjusted manually on your chart, but did not affect the code, which appears to be working correctly. There are always data clitches or bad data that can affect code.

Please note that for stocks, you should adjust the start time to 0400 for premarket.

I have changed the 764 to 786 for you.
Good afternoon @SleepyZ, thank you very much for the clarification to adjust the premarket time in the indicator at 0400, that solved the problem I had.
I also want to thank you for the change of the 786 level, when I traced the fibo levels using the TOS tool on the indicator, the level that you marked on your graph as 786 was still 764, only the name had changed, not the position of the level. Since yesterday I was trying to see what I could do to add level 786, and the only thing that occurred to me was to review your code and find logic, I copied part of the code just changing the information for the levels I wanted to add (levels 786 and 214 already If I did not add this last level, the FIBO would not show level 786 when the flip was made), I have attached the screenshot with the levels, as I said, I do not know how to program but I think I reached the Fibo I was looking for, thank you very much for your valuable help.
@SleepyZ one question: is it possible to change the part of the Auto or Manual label by changing the color also, let's say yellow in auto mode and cyan in manual mode? Thank you
 

Attachments

  • Screenshot 2023-07-05 Fibo_Levels_786.png
    Screenshot 2023-07-05 Fibo_Levels_786.png
    148.5 KB · Views: 251
Last edited:
Good afternoon @SleepyZ, thank you very much for the clarification to adjust the premarket time in the indicator at 0400, that solved the problem I had.
I also want to thank you for the change of the 786 level, when I traced the fibo levels using the TOS tool on the indicator, the level that you marked on your graph as 786 was still 764, only the name had changed, not the position of the level. Since yesterday I was trying to see what I could do to add level 786, and the only thing that occurred to me was to review your code and find logic, I copied part of the code just changing the information for the levels I wanted to add (levels 786 and 214 already If I did not add this last level, the FIBO would not show level 786 when the flip was made), I have attached the screenshot with the levels, as I said, I do not know how to program but I think I reached the Fibo I was looking for, thank you very much for your valuable help.
@SleepyZ one question: is it possible to change the part of the Auto or Manual label by changing the color also, let's say yellow in auto mode and cyan in manual mode? Thank you

These were the levels that I pulled from your autofib post and used in the above code.
0
23.6
38.2
50.0
61.8
78.6
100.0
127.3
144.0
161.8
261.8
423.6

I did not see 21.4 in that list, but now I have changed 23.6 to 21.4 in this code.

I also changed the color of the mode label to yellow or cyan.

As far as the 786, it looked correct to me in the code above, so I did not have to change anything. I think you might have been confused by the input Fpos764 and related one's. The Fpos764 was just a name, and since you wanted 786 instead of 764, I changed the input to be Fpos764 = .786. Likewise, when you wanted 21.4 instead of 23.6, Fpos236 was changed to input Fpos236 = .214.

Screenshot 2023-07-05 224753.png
Code:
#Auto_Fibs_TimeRange_Flip_0_100_time_chart_version

input start = 0400;
input end   = 0929;
input showtodayonly  = no;
input bubblemover    = 0;
input showbubbles    = yes;
input extendlines    = yes;
input show_trendline = yes;

def sec1    = SecondsFromTime(start);
def sec2    = SecondsFromTime(end);
def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or
              (sec1 < sec1[1] and sec1 > 0);
def isTime2 = (sec2 > 0 and sec2[1] <= 0) or
              (sec2 < sec2[1] and sec2 > 0) ;
def aftermarket = CompoundValue(1,
                  if isTime1[1] == 0 and isTime1 == 1
                  then 1
                  else if isTime2
                  then 0
                  else aftermarket[1], 0);

def bars   = 100000;
def bn     = BarNumber();
def na     = Double.NaN;

def period = bn - 1;
def count  = CompoundValue(1,
             if aftermarket and period != period[1]
             then (count[1] + period - period[1]) % bars
             else count[1], 0);
def cond   = count < count[1] + period - period[1];

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = bars, "pricePerRow" = PricePerRow.TICKSIZE , "value area percent" = 0);

def hProfile = if aftermarket and IsNaN(vol.GetHighest())
               then hProfile[1]
               else if period != period[1]
               then vol.GetHighest()
               else hProfile[1];
def lProfile = if aftermarket and IsNaN(vol.GetLowest())
               then lProfile[1]
               else if period != period[1]
               then vol.GetLowest()
               else lProfile[1];

def ProfileHigh = if extendlines and !aftermarket then ProfileHigh[1] else if aftermarket then hProfile else na;
def ProfileLow  = if extendlines and !aftermarket then ProfileLow[1] else if aftermarket then lProfile else na;

def hrange = ProfileHigh;
def lrange = ProfileLow;


input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);


input showtimerange_label = yes;
AddLabel(showtimerange_label, "HL Time Range: " + AsPrice(start) + " to " + AsPrice(end), Color.YELLOW);

input Fpos236 = .214;
input Fpos382 = .382;
input Fpos50  = .5;
input Fpos618 = .618;
input Fpos764 = .786;
input Fpos1618 = 1.618;
input Fneg618  = -0.618;
input Fpos1273 = 1.273;
input Fneg1273 = -0.273;
input Fpos1440 = 1.440;
input Fneg1440 = -0.440;
input Fpos2618 = 2.618;
input Fneg2618 = -1.618;
input Fpos4236 = 4.236;
input Fneg4236 = -3.236;

def range  = AbsValue(hrange - lrange);
def F236   = hrange - (range * Fpos236);
def F382   = hrange - (range * Fpos382);
def F50    = hrange - (range * Fpos50);
def F618   = hrange - (range * Fpos618);
def F764   = hrange - (range * Fpos764);
def F1618   = hrange - (range * Fpos1618);
def F_618   = hrange - (range * Fneg618);
def F1273   = hrange - (range * Fpos1273);
def F_1273  = hrange - (range * Fneg1273);
def F1440   = hrange - (range * Fpos1440);
def F_1440  = hrange - (range * Fneg1440);
def F2618   = hrange - (range * Fpos2618);
def F_2618  = hrange - (range * Fneg2618);
def F4236   = hrange - (range * Fpos4236);
def F_4236  = hrange - (range * Fneg4236);

plot ORH;
plot ORL;
plot Fib50;
plot Fib236;
plot Fib382;
plot Fib618;
plot Fib764;
plot Fib1618;
plot Fib_618;
plot Fib1273;
plot Fib_1273;
plot Fib1440;
plot Fib_1440;
plot Fib2618;
plot Fib_2618;
plot Fib4236;
plot Fib_4236;

def dataCount = CompoundValue(1, if (aftermarket != aftermarket[1]) then dataCount[1] + 1 else dataCount[1], 0);

if showtodayonly and HighestAll(dataCount) - dataCount > 2
then {
    ORH      = Double.NaN;
    ORL      = Double.NaN;
    Fib50    = Double.NaN;
    Fib236   = Double.NaN;
    Fib382   = Double.NaN;
    Fib618   = Double.NaN;
    Fib764   = Double.NaN;
    Fib1618   = Double.NaN;
    Fib_618   = Double.NaN;
    Fib1273   = Double.NaN;
    Fib_1273  = Double.NaN;
    Fib1440   = Double.NaN;
    Fib_1440  = Double.NaN;
    Fib2618   = Double.NaN;
    Fib_2618  = Double.NaN;
    Fib4236   = Double.NaN;
    Fib_4236  = Double.NaN;

} else {
    ORH      = hrange;
    ORL      = lrange;
    Fib50    = F50;
    Fib236   = F236;
    Fib382   = F382;
    Fib618   = F618;
    Fib764   = F764;
    Fib1618  = F1618;
    Fib_618  = F_618;
    Fib1273   = F1273;
    Fib_1273  = F_1273;
    Fib1440   = F1440;
    Fib_1440  = F_1440;
    Fib2618   = F2618;
    Fib_2618  = F_2618;
    Fib4236   = F4236;
    Fib_4236  = F_4236;

}

ORH.SetDefaultColor(Color.WHITE);
ORH.SetPaintingStrategy(PaintingStrategy.DASHES);
ORH.SetLineWeight(2);

ORL.SetDefaultColor(Color.WHITE);
ORL.SetPaintingStrategy(PaintingStrategy.DASHES);
ORL.SetLineWeight(2);

Fib50.SetDefaultColor(Color.WHITE);
Fib50.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib50.SetLineWeight(1);

Fib236.SetDefaultColor(Color.CYAN);
Fib236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib236.SetLineWeight(1);

Fib382.SetDefaultColor(Color.YELLOW);
Fib382.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib382.SetLineWeight(1);

Fib618.SetDefaultColor(Color.YELLOW);
Fib618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib618.SetLineWeight(1);

Fib764.SetDefaultColor(Color.CYAN);
Fib764.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib764.SetLineWeight(2);

Fib1618.SetDefaultColor(Color.YELLOW);
Fib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1618.SetLineWeight(1);

Fib_618.SetDefaultColor(Color.YELLOW);
Fib_618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_618.SetLineWeight(1);

Fib1273.SetDefaultColor(Color.YELLOW);
Fib1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1273.SetLineWeight(1);

Fib_1273.SetDefaultColor(Color.YELLOW);
Fib_1273.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1273.SetLineWeight(1);

Fib1440.SetDefaultColor(Color.YELLOW);
Fib1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib1440.SetLineWeight(1);

Fib_1440.SetDefaultColor(Color.YELLOW);
Fib_1440.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_1440.SetLineWeight(1);

Fib2618.SetDefaultColor(Color.YELLOW);
Fib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib2618.SetLineWeight(1);

Fib_2618.SetDefaultColor(Color.YELLOW);
Fib_2618.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_2618.SetLineWeight(1);

Fib4236.SetDefaultColor(Color.YELLOW);
Fib4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib4236.SetLineWeight(1);

Fib_4236.SetDefaultColor(Color.YELLOW);
Fib_4236.SetPaintingStrategy(PaintingStrategy.DASHES);
Fib_4236.SetLineWeight(1);

input manual_flip = no;
def mo   = bubblemover;
def mo1  = mo + 1;

def lo1 = if low  == lProfile then 1 else 0;
def hi1 = if high == hProfile then 1 else 0;
def hbar = if aftermarket and hi1 == 1 then bn else hbar[1];
def lbar = if aftermarket and lo1 == 1 then bn else lbar[1];
def last = IsNaN(close[mo + 1]) and !IsNaN(close[mo + 1]);
plot xhbar = if manual_flip then lbar else hbar;
plot xlbar = if manual_flip then hbar else lbar;
xhbar.SetHiding(yes);
xlbar.SetHiding(yes);

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORH[mo + 1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 0 else 100),
ORH.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
ORL[mo + 1], (if xhbar[mo + 1] > xlbar[mo + 1] then 100 else 0),
ORL.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib50[mo1 + 1],
"50",
Fib50.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 214 else 786),
Fib236.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib382[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 382 else 618),
Fib382.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 618 else 382),
Fib618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib764[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 786 else 214),
Fib764.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1618 else -618),
Fib1618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -618 else 1618),
Fib_618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1273 else -273),
Fib1273.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1273[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -273 else 1273),
Fib_1273.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 1440 else -440),
Fib1440.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_1440[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -440 else 1440),
Fib_1440.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 2618 else -1618),
Fib2618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_2618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -1618 else 2618),
Fib_2618.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then 4236 else -3236),
Fib4236.TakeValueColor());

AddChartBubble(
if !showbubbles
then na
else if extendlines
then ORH[mo + 1] != ORH[mo] or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1])
else IsNaN(ORH[mo]) and !IsNaN(ORH[mo + 1]) or
     IsNaN(close[mo]) and !IsNaN(close[mo + 1]),
Fib_4236[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -3236 else 4236),
Fib_4236.TakeValueColor());


def hbar1 = if (aftermarket or aftermarket[1]) and hi1 == 1 then 1 else 0;
def lbar1 = if (aftermarket or aftermarket[1]) and lo1 == 1 then 1 else 0;

plot xhbar1 = hbar1;
plot xlbar1 = lbar1;
xhbar1.SetHiding(yes);
xlbar1.SetHiding(yes);

plot xline = if show_trendline then if aftermarket and !IsNaN(xhbar1) then hrange else if aftermarket and !IsNaN(xlbar1) then hrange else na else na;
xline.EnableApproximation();
;
input show_flip_mode = yes;
AddLabel(show_flip_mode, if manual_flip == yes then "Manual Flip Mode" else "Auto Flip Mode", if manual_flip == no then Color.YELLOW else color.cyan);
 
Good evening @SleepyZ, thank you very much for the change to the label color code.
On the other hand @SleepyZ the fibo levels I needed are correct
0
23.6
38.2
50.0
61.8
78.6
100.0
127.3
144.0
161.8
261.8
423.6
What happens is that in post #52 when you made the change from level 764 to 786, it changed the information in the bubble instead of showing 764 it showed 786, but if you review the indicator in post#52 on a chart and compare it with the levels drawn by the Fibo tool of TOS you will notice that there is a difference between what the indicator draws at levels 236 and 786, I am attaching a screenshot with the indicator in post #52 and I indicate levels 236 and 786.
What I have been able to notice all these days with the adjustments that you were making to the indicator is that as this fibo flips, a mirror is created, a direct relationship between levels 0 to 100, 236 to 764, 382 to 618 and 500 is the center, For this reason, a problem is created in the indicator of wanting to mirror between levels 236 and 786, since the 786 can only mirror with level 214. I'm sorry if my explanation is confusing but after having done so many tests with the different improvements that you made to the indicator, I was able to notice that relationship between the levels.
In post #54 I tried to explain that, but I think my explanation was confusing, it is for this reason that it occurred to me to copy part of the indicator code and add levels 214 and 786, well as I said at the beginning I can't program so I try to find a solution to be able to have level 786 in the fibo.
Now the last fibo you sent is perfect, because it is related to 214 and 786, but if you wanted to plot level 236 and not 214 we would get that conflict again with levels 236 and 786 since they don't mirror (well it's the best way that I have done to make myself understand about these levels) Again thank you very much for the immense help with this indicator.
 

Attachments

  • Screenshot 2023-07-07 Auto_Fibo_Post_52.png
    Screenshot 2023-07-07 Auto_Fibo_Post_52.png
    133.8 KB · Views: 258
Good afternoon @SleepyZ, a few days ago I send a message to @BenTen about an Automatic Fib Retracement Indicator, and he sent me a link where I could find what I needed, I have been reading the posts in this forum, I wanted to thank you for such an excellent job, I have copied the code in the post #25, #27 and #31, which I have tested to see if they do what I need, and the codes take data that doesn't fit what I want to do. In my message to Mr BenTen I explained that I needed the fibo indicator to use the time range method so that timerange_begin/timerange_end inputs like prior day, premarket, and custom user time ranges, with the Fibs levels, using the high and low of the time range.

For example Pre-market High and Pre-Market Low (0:00 am to 9:05 am), especially in the Premarket time range, you can have the option to select the End Time (9:00 am, 9:03 am or 9: 29am) and plots that on the chart, as I said before, the codes in posts #25, #27 and #31 are the closest I have been able to see in my search in the forums about Fib but none allow me the option of taking the high and low of the Pre-market.
In the chart that you shared in post #25 that takes the previous day's high/low and that can flip there are two days in which the important fibo levels go in the opposite direction to the price movement (Monday and Wednesday) that is why when I sent my message to Mr BenTen, I was wondering if a switch could be made to the direction of the levels so that their projections were consistent with the movement of the asset's price.
Thank you very much once again for such an excellent job.

I am attaching the message that I sent to Mr BenTen and the two examples with the fibo levels when the price goes up or down.
Hello, I'm new new here. Can you please direct me to the link that has the codes for the pre-market fibs you showed in the two pictures? Thanks in advance.
 
This indicator for ThinkorSwim takes the high and low of the previous week or month and add Fibonacci retracement levels to create potential support and resistance levels. You can also use the high and low of the previous day, yearly, etc. Up to you to select the right timeframe to help your trading style.

View attachment 4487

thinkScript Code

Rich (BB code):
#
# WalkingBallista & BenTen
# https://usethinkscript.com/d/153-high-and-low-with-fibonacci-retracement-indicator-for-thinkorswim
input aggregationPeriod = AggregationPeriod.DAY;
input ShowTodayOnly = yes;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
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 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib-1);
plot h1 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib1-1);
plot h2 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib2-1);
plot h3 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib3-1);
plot h4 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib4-1);
plot h5 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib5-1);
plot h6 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib6-1);
plot h7 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib7-1);
plot h8 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib1-1);
plot h9 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib-1);
plot h10 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib7-1);

h.DefineColor("Color", Color.DARK_RED);
h.AssignValueColor(h.color("Color"));
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h1.DefineColor("Color", Color.RED);
h1.AssignValueColor(h1.color("Color"));
h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h2.DefineColor("Color", Color.RED);
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.RED);
h4.AssignValueColor(h3.color("Color"));
h4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h5.DefineColor("Color", Color.RED);
h5.AssignValueColor(h3.color("Color"));
h5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h6.DefineColor("Color", Color.RED);
h6.AssignValueColor(h3.color("Color"));
h6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h7.DefineColor("Color", Color.RED);
h7.AssignValueColor(h3.color("Color"));
h7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h8.DefineColor("Color", Color.RED);
h8.AssignValueColor(h3.color("Color"));
h8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h9.DefineColor("Color", Color.RED);
h9.AssignValueColor(h3.color("Color"));
h9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h10.DefineColor("Color", Color.RED);
h10.AssignValueColor(h3.color("Color"));
h10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot highofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH;
highofline.DefineColor("Color", Color.YELLOW);
highofline.AssignValueColor(highofline.color("Color"));
highofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lowofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL;
lowofline.DefineColor("Color", Color.YELLOW);
lowofline.AssignValueColor(highofline.color("Color"));
lowofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Shareable Link

https://tos.mx/UoIukn

Video Tutorial

Why don't the color change on the fib lines, I tray changing all the red lines I even went to the script and manually try to put diffrent colors and they still dont change, they stay RED. Anyone else having this problem?
 
The fib extension tool is different than the fib retracement tool.

The fib extension when anchored to the open, then uses the distance of the first part of three legs of the fib extension tool to create the fib levels over that distance.

See the image in the code posted above with the red TOS fib extension tool overlaid on the chart and how those levels align with the code's levels as denoted in the corresponding bubbles.
SleepyZ,
These were the levels that I pulled from your autofib post and used in the above code.
0
23.6
38.2
50.0
61.8
78.6
100.0
127.3
144.0
161.8
261.8
423.6

I did not see 21.4 in that list, but now I have changed 23.6 to 21.4 in this code.

I also changed the color of the mode label to yellow or cyan.

As far as the 786, it looked correct to me in the code above, so I did not have to change anything. I think you might have been confused by the input Fpos764 and related one's. The Fpos764 was just a name, and since you wanted 786 instead of 764, I changed the input to be Fpos764 = .786. Likewise, when you wanted 21.4 instead of 23.6, Fpos236 was changed to input Fpos236 = .214.
Greetings SleepyZ. Could you simplify this fib code that one could manually input either Min, Hr, Day, Week, Month or Year? For example, if I want to plot fib for 5 days or 10 days then it will plot for that specifically. Thank you so much.
 
This indicator for ThinkorSwim takes the high and low of the previous week or month and add Fibonacci retracement levels to create potential support and resistance levels. You can also use the high and low of the previous day, yearly, etc. Up to you to select the right timeframe to help your trading style.

View attachment 4487

thinkScript Code

Rich (BB code):
#
# WalkingBallista & BenTen
# https://usethinkscript.com/d/153-high-and-low-with-fibonacci-retracement-indicator-for-thinkorswim
input aggregationPeriod = AggregationPeriod.DAY;
input ShowTodayOnly = yes;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
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 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib-1);
plot h1 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib1-1);
plot h2 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib2-1);
plot h3 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib3-1);
plot h4 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib4-1);
plot h5 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib5-1);
plot h6 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib6-1);
plot h7 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib7-1);
plot h8 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib1-1);
plot h9 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib-1);
plot h10 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib7-1);

h.DefineColor("Color", Color.DARK_RED);
h.AssignValueColor(h.color("Color"));
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h1.DefineColor("Color", Color.RED);
h1.AssignValueColor(h1.color("Color"));
h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h2.DefineColor("Color", Color.RED);
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.RED);
h4.AssignValueColor(h3.color("Color"));
h4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h5.DefineColor("Color", Color.RED);
h5.AssignValueColor(h3.color("Color"));
h5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h6.DefineColor("Color", Color.RED);
h6.AssignValueColor(h3.color("Color"));
h6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h7.DefineColor("Color", Color.RED);
h7.AssignValueColor(h3.color("Color"));
h7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h8.DefineColor("Color", Color.RED);
h8.AssignValueColor(h3.color("Color"));
h8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h9.DefineColor("Color", Color.RED);
h9.AssignValueColor(h3.color("Color"));
h9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h10.DefineColor("Color", Color.RED);
h10.AssignValueColor(h3.color("Color"));
h10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot highofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH;
highofline.DefineColor("Color", Color.YELLOW);
highofline.AssignValueColor(highofline.color("Color"));
highofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lowofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL;
lowofline.DefineColor("Color", Color.YELLOW);
lowofline.AssignValueColor(highofline.color("Color"));
lowofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Shareable Link

https://tos.mx/UoIukn

Video Tutorial


How could I have 10 days to the aggregation period?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
453 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top