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
    Screenshot 2024-02-12 Auto_Fibo_Options_Scan.png
    16.8 KB · Views: 164

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

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.

Screenshot 2024-02-13 075909.png
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);
AddLabel(1, fib, Color.BLACK);
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);

#
 
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.
 
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.
 
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.

Screenshot 2024-03-18 130308.png

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);

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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());

AddChartBubble(
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.
 
Could someone provide the modified automatic fib level script for different time interval but same time frame?

For example, I would like to have the automatic fib levels for high & low for last 6 months for D time frame.
At the same time, I also wanted to have the automatic fib levels for high & low for last 1 year for the same D time frame.

The time frame D is same but the interval is changed from 6 months to 1 Year. I dont want to manually change on thinkorswim everytime. It would be so much easier if the script can do it for the specified time intervals ( Like 3 months, 6 months, 1 Year )..
This is used to determine the Fib levels of the recent Highs & Lows and also to determine the Fib levels of the previous Highs & Lows ( but not recent )
 
Could someone provide the modified automatic fib level script for different time interval but same time frame?

For example, I would like to have the automatic fib levels for high & low for last 6 months for D time frame.
At the same time, I also wanted to have the automatic fib levels for high & low for last 1 year for the same D time frame.

The time frame D is same but the interval is changed from 6 months to 1 Year. I dont want to manually change on thinkorswim everytime. It would be so much easier if the script can do it for the specified time intervals ( Like 3 months, 6 months, 1 Year )..
This is used to determine the Fib levels of the recent Highs & Lows and also to determine the Fib levels of the previous Highs & Lows ( but not recent )

Unfortunately no.
This script is based on the whatever number of candles are set on the chart.
The number of candles on your chart is set in chart settings and not modifiable by ThinkScript.
 
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.
@SleepyZ I would like for this calculate the fibs based on highest and lowest of the hourly chart in the past 5 days. How can you guide me ?
 
Created by RyanHendricks.

View attachment 4235

thinkScript Code

Ruby:
# Auto Fib V1.3
# tomsk
# 11.19.2019

# Automatically draws fibonacci retracements using the highest price and lowest price
# from the current view and timeframe.
#
# Fibonacci retracements use horizontal lines to indicate areas of support or resistance
# at the key Fibonacci levels before it continues in the original direction. These levels
# are created by drawing a trendline between two extreme points and then dividing the
# vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%.

# CHANGE LOG
#
# V1.0 - 12.18.2018 - BenTen       - Initial release of Auto Fib, created by Ryan Hendricks
# V1.1 - 11.15.2019 - theelderwand - As script was difficult to read, made the following enhancements
#                                    Expands to right
#                                    Doesn't expand to left
#                                    Custom colors for Fibonacci bars (0.618 is GOLD color)
#                                    Custom line weights
#                                    Code is modularized so you can add extra plots as needed
# V1.2 - 11.15.2019 - tomsk        - Added an input selector for the colors of the label. You
#                                    can select from any of the colors listed - red, orange,
#                                    green, etc and bubbles for all the fib retracements will
#                                    utilize that color.
# V1.3 - 11.19.2019 - tomsk        - Modified the AddChartBubbles to be displayed on the right
#                                    side of the chart. Please ensure that you increase the
#                                    expansion area to that the bubbles have room to be displayed
#                                    Chart Settings > Time Axis > Expansion Area

#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>

#hint coefficient_0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: coefficient_0
#wizard text: coefficient_0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

input price = close;
input high = high;
input low = low;
input coefficient_0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = 1.000;

input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};
input n = 3;

def n1  = n + 1;
def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();

def range =  a - b;

def value0 = range * coefficient_0;
def value1 = range * coefficient_1;
def value2 = range * coefficient_2;
def value3 = range * coefficient_3;
def value4 = range * coefficient_4;
def value5 = range * coefficient_5;
def value6 = range * coefficient_6;

def condition1 = downward and barnumber >= highnumberall;
def condition2 = upward and barnumber >= lownumberall;

Plot Retracement0 = if condition1 then highestall(b + value0) else if condition2 then highestall(a - value0) else double.nan;
Plot Retracement1 = if condition1 then highestall(b + value1) else if condition2 then highestall(a - value1) else double.nan;
Plot Retracement2 = if condition1 then highestall(b + value2) else if condition2 then highestall(a - value2) else double.nan;
Plot Retracement3 = if condition1 then highestall(b + value3) else if condition2 then highestall(a - value3) else double.nan;
Plot Retracement4 = if condition1 then highestall(b + value4) else if condition2 then highestall(a - value4) else double.nan;
Plot Retracement5 = if condition1 then highestall(b + value5) else if condition2 then highestall(a - value5) else double.nan;
Plot Retracement6 = if condition1 then highestall(b + value6) else if condition2 then highestall(a - value6) else double.nan;

Retracement0.assignvaluecolor(CreateColor(255,255,255));
Retracement0.setLineWeight(4);
retracement0.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);

Retracement1.assignvaluecolor(CreateColor(173,216,230));
Retracement1.setLineWeight(2);
retracement1.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);

Retracement2.assignvaluecolor(CreateColor(0,197,49));
Retracement2.setLineWeight(2);
retracement2.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);

Retracement3.assignvaluecolor(CreateColor(255,64,64));
Retracement3.setLineWeight(3);
retracement3.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);

Retracement4.assignvaluecolor(CreateColor(255,215,0));
Retracement4.setLineWeight(5);
retracement4.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);

Retracement5.assignvaluecolor(CreateColor(0,255,255));
Retracement5.setLineWeight(2);
retracement5.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);

Retracement6.assignvaluecolor(CreateColor(255,255,255));
Retracement6.setLineWeight(4);
Retracement6.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);

alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1");
alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1");
alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3");
alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3");
alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");
# End Auto Fib v1.3

Shareable Link

https://tos.mx/Fz8Ss0
Is there a way to allow this to change color/thickness etc?
 
@SleepyZ I would like for this calculate the fibs based on highest and lowest of the hourly chart in the past 5 days. How can you guide me ?

You might be able to make one of these multi-timeframe Fibonacci scripts work for you:
MTF Fibonacci
https://usethinkscript.com/threads/multi-timeframe-hloc-plus-fibs-for-thinkorswim.8022/
https://usethinkscript.com/threads/...ci-retracement-indicator-for-thinkorswim.153/
https://usethinkscript.com/threads/...icator-for-thinkorswim.14/page-18#post-122981
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
343 Online
Create Post

Similar threads

Similar threads

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