# Auto Fib (Fibonacci) Levels Indicator for ThinkorSwim

Good evening @SleepyZ, thanks for the latest improvement of the indicator, this looks great, I have just installed the latest version so I need to test the level selector and observe the label/signal of the chosen level.
On the other hand, I copied the code for the possible scan of the indicator for the watchlist and it only shows 0.00 and Nan (I attached a screenshoot), with the last improvement to the indicator in which you can now select the level that the label will show, the scan would be a perfect complement, to not have so many charts of open options contracts.

#### Attachments

• Screenshot 2024-02-12 Auto_Fibo_Options_Scan.png
16.8 KB · Views: 50
Good evening @SleepyZ, thanks for the latest improvement of the indicator, this looks great, I have just installed the latest version so I need to test the level selector and observe the label/signal of the chosen level.
On the other hand, I copied the code for the possible scan of the indicator for the watchlist and it only shows 0.00 and Nan (I attached a screenshoot), with the last improvement to the indicator in which you can now select the level that the label will show, the scan would be a perfect complement, to not have so many charts of open options contracts.

If you want a watchlist column then something like this might help. It tracks the fib level real time using the following set to DAY.
There is a coloring of the background that you can adjust to your liking within the code.

Code:
#AutoFib for OPTIONS only

input ShowTodayOnly = no;
input showlastbubbles = yes;
input showpriorbubbles = no;
input bubblemover = 8; #Hint n: Number of Bars to shift bubble horizontally
input showlabels = yes;

def hi = high(period = AggregationPeriod.DAY);
def ORH1 = if ShowTodayOnly and GetDay() != GetLastDay() then Double.NaN else if GetDay() != GetDay()[1] then hi else if hi > ORH1[1] then hi else ORH1[1];
def ORL1 = if ShowTodayOnly and GetDay() != GetLastDay() then Double.NaN else if GetDay() != GetDay()[1] then 0 else ORL1[1];#low(period = period)[displace];

plot orh = ORH1;
orh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
orh.SetLineWeight(2);

plot orl = ORL1;
orl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
orl.SetLineWeight(2);

input F1 = 236;
input F2 = 382;
input F3 = 500;
input F4 = 618;
input F5 = 705;
input F6 = 786;
input F7 = 900;

def rHi = orh;
def rLo = orl;

def range = AbsValue(rHi - rLo);
plot FF1 = rHi - (range * F1 * .001);
plot FF2 = rHi - (range * F2 * .001);
plot FF3 = rHi - (range * F3 * .001);
plot FF4 = rHi - (range * F4 * .001);
plot FF5 = rHi - (range * F5 * .001);
plot FF6 = rHi - (range * F6 * .001);
plot FF7 = rHi - (range * F7 * .001);

def fib = 1000 * Round(1 - (close / range), 3);
AssignBackgroundColor(
if Between(fib, 610, 638) then Color.RED
else if Between(fib, 690, 710) then Color.LIGHT_RED
else if Between(fib, 780, 790) then Color.MAGENTA
else if Between(fib, 890, 910) then Color.PINK
else Color.WHITE);

#

If you want a watchlist column then something like this might help. It tracks the fib level real time using the following set to DAY.
There is a coloring of the background that you can adjust to your liking within the code.
Thanks @SleepyZ for the watchlist code, I'm going to test it tomorrow.

A bubblemover was added. The image shows a -130 to move the bubbles to the left as an example.

It looks like you can also try to decrease you active traders to pick up some additional space to accomodate the bubbles.
@SleepyZ can you pls share a link of that amazing look chart setup.

Thanks @SleepyZ for this awesome script!

One request:
I would like to showcase 10D 5M Fibonacci Retracement on the current chart timeframe being shown for example on 1D 1M chart.

Is this something you could help me out here?

Thanks @SleepyZ for this awesome script!

One request:
I would like to showcase 10D 5M Fibonacci Retracement on the current chart timeframe being shown for example on 1D 1M chart.

Is this something you could help me out here?

1. I am not sure which of the fib studies you were referring.
2. Since the most recent was a very specific one for use only on options, I modified a similar one on here that I did that was for pre/aftermarket times to a timeframe basis that you requested.
3. It uses the volumeprofile indicator's profilehigh/low for the 0/100 levels
4. The image shows a setting of 2 days on a 5m chart, for example.

Code:
#Auto_Fibs_TimeProfile_Flip_0_100_time_chart_version

input timePerProfile = { CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;

input showtodayonly  = no;
input bubblemover    = 0;
input showbubbles    = yes;
input extendlines    = yes;
input show_trendline = yes;

input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;

def bn = barnumber();
def na = double.nan;
def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
period = Floor(seconds / 3600 + day_number * 24);
case DAY:
period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
period = Floor(day_number / 7);
case MONTH:
period = Floor(month - First(month));
case "OPT EXP":
period = exp_opt - First(exp_opt);
case BAR:
period = BarNumber() - 1;
}

def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}

profile vol = volumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = compoundValue(1, onExpansion, no);

def hProfile   = if IsNaN(vol.getHighest()) and con then hProfile[1] else vol.getHighest();
def lProfile   = if IsNaN(vol.getLowest()) and con then lProfile[1] else vol.getLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;

def hrange = ProfileHigh;
def lrange = ProfileLow;

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

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
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 hi1 == 1 then bn else hbar[1];
def lbar = if 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);

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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());

if !showbubbles
then na
else if extendlines and !isnan(close[-1])
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 hi1 == 1 then 1 else 0;
def lbar1 = if 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 !IsNaN(xhbar1) then hrange else if !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);

#

1. I am not sure which of the fib studies you were referring.
2. Since the most recent was a very specific one for use only on options, I modified a similar one on here that I did that was for pre/aftermarket times to a timeframe basis that you requested.
3. It uses the volumeprofile indicator's profilehigh/low for the 0/100 levels
4. The image shows a setting of 2 days on a 5m chart, for example.
Thanks SleepyZ!

Sorry,
I meant for the initial Auto Fib for stocks; not for options.

It would be nice to showcase different Fib Retracement with day and time lengths on any chart.
For example, 10D 5M and 20D 15M Fib Retracement on a 1D 1M chart.

Thanks SleepyZ!

Sorry,
I meant for the initial Auto Fib for stocks; not for options.

It would be nice to showcase different Fib Retracement with day and time lengths on any chart.
For example, 10D 5M and 20D 15M Fib Retracement on a 1D 1M chart.

The auto fib retracement scripts are based upon the highestall/lowestall prices displayed upon the charts being viewed. So if you are viewing a 1D 1M chart, then only those values can be used in the auto fib retracement study at the beginning of this thread.

87k+ Posts
401 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?