Auto Fib (Fibonacci) Levels Indicator for ThinkorSwim


Are you sure? https://usethinkscript.com/threads/...ci-retracement-indicator-for-thinkorswim.153/

Now there's 3.

Code:
# Auto Fib Agg by Wiinii
#https://usethinkscript.com/threads/auto-fib-fibonacci-levels-indicator-for-thinkorswim.14/post-122981
# Based on Auto Fib V1.3 by tomsk

input useAgg_or_chart = {default "Aggregation Period", "Chart Length (overrides next 2)"};
input todayOnly = {default "No", "Yes (overrides aggPeriod)"};
input aggPeriod = AggregationPeriod.DAY;
input ShowLastPeriodOnly = yes;
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 n = 3;

def today = GetDay();
def Week = GetWeek();
def month = GetMonth();
def year = GetYear();
def lastDay = GetLastDay();
def lastWeek = GetLastWeek();
def lastmonth = GetLastMonth();
def lastyear = GetLastYear();

def aggP = if todayOnly == todayOnly."Yes (overrides aggPeriod)" then AggregationPeriod.DAY else aggPeriod;
def useAggP = useAgg_or_chart == useAgg_or_chart."Aggregation Period";

def hagg = high(period = aggP)[if todayOnly == todayOnly."Yes (overrides aggPeriod)" then 0 else 1];
def lagg = low(period = aggP)[if todayOnly == todayOnly."Yes (overrides aggPeriod)" then 0 else 1];
def n1  = n + 1;
def a = if useAggP then hagg else HighestAll(high);
def b = if useAggP then lagg else 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;
def highnumber = CompoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = if UseAggP then hagg else HighestAll(highnumber);
def lownumber = CompoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = if UseAggP then lagg else 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 isToday = If(today == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber =  if UseAggP then (if isToday then barnumber else Double.NaN) else 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 ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week != lastWeek and aggP == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month != lastmonth and aggP == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year != lastyear and aggP == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value0 else HighestAll(b + value0))
else if condition2 then (if UseAggP then a - value0 else HighestAll(a - value0)) else Double.NaN;

plot Retracement1 = if ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week != lastWeek and aggP == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month != lastmonth and aggP == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year != lastyear and aggP == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value1 else HighestAll(b + value1)) else if condition2 then (if UseAggP then a - value1 else HighestAll(a - value1)) else Double.NaN;

plot Retracement2 = if ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week != lastWeek and aggP == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month != lastmonth and aggP == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year != lastyear and aggP == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value2 else HighestAll(b + value2)) else if condition2 then (if UseAggP then a - value2 else HighestAll(a - value2)) else Double.NaN;

plot Retracement3 = if ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week != lastWeek and aggP == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month != lastmonth and aggP == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year != lastyear and aggP == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value3 else HighestAll(b + value3)) else if condition2 then (if UseAggP then a - value3 else HighestAll(a - value3)) else Double.NaN;

plot Retracement4 = if ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week != lastWeek and aggP == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month != lastmonth and aggP == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year != lastyear and aggP == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value4 else HighestAll(b + value4)) else if condition2 then (if UseAggP then a - value4 else HighestAll(a - value4)) else Double.NaN;

plot Retracement5 = if ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week != lastWeek and aggP == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month != lastmonth and aggP == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year != lastyear and aggP == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value5 else HighestAll(b + value5)) else if condition2 then (if UseAggP then a - value5 else HighestAll(a - value5)) else Double.NaN;

plot Retracement6 = if ShowLastPeriodOnly and today != lastDay and aggP == AggregationPeriod.DAY then Double.NaN
else if ShowLastPeriodOnly and Week and lastWeek == AggregationPeriod.WEEK then Double.NaN
else if ShowLastPeriodOnly and month and lastmonth == AggregationPeriod.MONTH then Double.NaN
else if ShowLastPeriodOnly and year and lastyear == AggregationPeriod.YEAR then Double.NaN
else if condition1 then (if UseAggP then b + value6 else HighestAll(b + value6)) else if condition2 then (if UseAggP then a - value6 else HighestAll(a - value6)) else Double.NaN;

DefineGlobalColor("Bubble", Color.WHITE);
Retracement0.AssignValueColor(CreateColor(255, 255, 255));
Retracement0.SetLineWeight(1);
Retracement0.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement0, Concat( (coefficient_0 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement0, Concat( (coefficient_0 * 100), "%"), GlobalColor("Bubble"), yes);

Retracement1.AssignValueColor(CreateColor(173, 216, 230));
Retracement1.SetLineWeight(1);
Retracement1.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement1, Concat( (coefficient_1 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement1, Concat( (coefficient_1 * 100), "%"), GlobalColor("Bubble"), yes);

Retracement2.AssignValueColor(CreateColor(0, 197, 49));
Retracement2.SetLineWeight(1);
Retracement2.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement2, Concat( (Coefficient_2 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement2, Concat( (Coefficient_2 * 100), "%"), GlobalColor("Bubble"), yes);

Retracement3.AssignValueColor(CreateColor(255, 64, 64));
Retracement3.SetLineWeight(1);
Retracement3.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement3, Concat( (Coefficient_3 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement3, Concat( (Coefficient_3 * 100), "%"), GlobalColor("Bubble"), yes);

Retracement4.AssignValueColor(CreateColor(255, 215, 0));
Retracement4.SetLineWeight(1);
Retracement4.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement4, Concat( (Coefficient_4 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement4, Concat( (Coefficient_4 * 100), "%"), GlobalColor("Bubble"), yes);

Retracement5.AssignValueColor(CreateColor(0, 255, 255));
Retracement5.SetLineWeight(1);
Retracement5.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement5, Concat( (Coefficient_5 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement5, Concat( (Coefficient_5 * 100), "%"), GlobalColor("Bubble"), yes);

Retracement6.AssignValueColor(CreateColor(255, 255, 255));
Retracement6.SetLineWeight(1);
Retracement6.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement6, Concat( (Coefficient_6 * 100), "%"), GlobalColor("Bubble"), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement6, Concat( (Coefficient_6 * 100), "%"), GlobalColor("Bubble"), 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");

EDIT 4/3/23 9:50pm with some enhancements.

Maybe someone can help me fix the fibfan, otherwise I'll look into it later.
 
Last edited:
Created by RyanHendricks.

Z7hCOks.png


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
I am highly using this auto fib indicator. Is it possible to have option to show draw fib only for today. I always do day trading and look for retracement only for current day. I always want to see 10 mins chart for 5 days and plot fib only for current day. Please help me to modify this script to plot only for today's chart
 
Please share the code if there Is a way to see the Fib levels as labels in the chart and the values when highlight in Fib level, on the right bar
 
@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
 

Attachments

  • Screenshot 2023-06-20 001316 Fibo_Levels_BABA.png
    Screenshot 2023-06-20 001316 Fibo_Levels_BABA.png
    97.8 KB · Views: 330
  • Screenshot 2023-06-19 220350 Fibo Levels.png
    Screenshot 2023-06-19 220350 Fibo Levels.png
    131.6 KB · Views: 344
I am highly using this auto fib indicator. Is it possible to have option to show draw fib only for today. I always do day trading and look for retracement only for current day. I always want to see 10 mins chart for 5 days and plot fib only for current day. Please help me to modify this script to plot only for today's chart
I second this, but would like to go a step further. Is there a way to modify it so it will only draw for let's say the last 20 candlesticks?
 
Can anyone help me change the chart bubbles to appear bars in the future?

I tried to add it like this but think I am missing something.

# plots a bubble x bars after last bar

input bars_in_future = 10;
def bif = bars_in_future;

addchartBubble(LabelsOn and F_236, F_0236,"23.6%",color.plum,bif);

here is the script.

#Automatic Fibonacci Long Levels
#based on Mobius's Fractal Pivot Strategy
#developed by Chewie76 on 8/27/2021

# User Inputs
input n = 20;
input FractalEnergyLength = 8;
input FractalEnergyThreshold = .68;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
input LabelsOn = yes;
input AlertsOn = yes;

# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def TS = TickSize();
def nan = double.nan;
def ATR = Round((MovingAverage(AvgType, TrueRange(h, c, l), nATR)) / TS, 0) * TS;
def risk = if Between(c, 0, 1500)
then ATR
else if Between(c, 1500, 3500)
then 2
else if Between(c, 3500, 5500)
then 4
else 6;
def FE = Log(Sum((Max(h, c[1]) - Min(l, c[1])), FractalEnergyLength) /
(Highest(h, FractalEnergyLength) - Lowest(l, FractalEnergyLength)))
/ Log(FractalEnergyLength);
# Parent Aggregation Pivot High
# Pivot High Variables
def p_hh = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -1);
def p_PivotH = if (bar > n and
h == Highest(h, n) and
p_hh)
then h
else NaN;
def p_PHValue = if !IsNaN(p_PivotH)
then p_PivotH
else p_PHValue[1];
def p_PHBar = if !IsNaN(p_PivotH)
then bar
else nan;
# Pivot High and Pivot High Exit Variables
# Pivot High Variables
def hh = fold ii = 1 to n + 1
with pp = 1
while pp
do h > GetValue(h, -1);
def PivotH = if (bar > n and
h == Highest(h, n) and
hh)
then h
else Double.NaN;
def PHValue = if !IsNaN(PivotH)
then PivotH
else PHValue[1];
def PHBar = if !IsNaN(PivotH)
then bar
else nan;
# Pivot High Exit Variables
def PHExit = if (bar > n and
h == Highest(h, n) and
hh)
then if l[1] < l
then l[1]
else fold r = 0 to 20
with a = NaN
while IsNaN(a)
do if GetValue(l[1], r) < l
then GetValue(l[1], r)
else NaN
else Double.NaN;
def PHExitValue = if !IsNaN(PHExit)
then PHExit
else PHExitValue[1];
def PHExitBar = if (bar > n and
h == Highest(h, n) and
hh)
then if l[1] < l
then bar - 1
else fold d = 0 to 20
with y = NaN
while IsNaN(y)
do if GetValue(l[1], d) < l
then GetValue(bar - 1, d)
else NaN
else NaN;
# Pivot Low and Pivot Low Entry Variables
# Parent Pivot Low Variables
def p_ll = fold j = 1 to n + 1
with q = 1
while q
do l < GetValue(l, -1);
def p_PivotL = if (bar > n and
l == Lowest(l, n) and
p_ll)
then l
else NaN;
def p_PLValue = if !IsNaN(p_PivotL)
then p_PivotL
else p_PLValue[1];
def p_PLBar = if !IsNaN(p_PivotL)
then bar
else nan;
# Pivot Low Variables
def ll = fold jj = 1 to n + 1
with qq = 1
while qq
do l < GetValue(l, -1);
def PivotL = if (bar > n and
l == Lowest(l, n) and
ll)
then l
else NaN;
def PLValue = if !IsNaN(PivotL)
then PivotL
else PLValue[1];
def PLBar = if !IsNaN(PivotL)
then bar
else nan;
# Pivot Low Entry Variables
def PLEntry = if (bar > n and
l == Lowest(l, n) and
ll)
then if h[1] > h
then h[1]
else fold t = 0 to 20
with w = NaN
while IsNaN(w)
do if GetValue(h[1], t) > h
then GetValue(h[1], t)
else NaN
else NaN;
def PLEntryValue = if !IsNaN(PLEntry)
then PLEntry
else PLEntryValue[1];
def PLEntryBar = if (bar > n and
l == Lowest(l, n) and
ll)
then if h[1] > h
then bar - 1
else fold u = 0 to 20
with z = NaN
while IsNaN(z)
do if GetValue(h[1], u) > h
then GetValue(bar - 1, u)
else NaN
else NaN;
# Plots

plot F_100 = if bar >= HighestAll(PLBar)
then HighestAll(if isNaN(c[-1])
then PLValue
else nan)
else nan;
F_100.SetDefaultColor(Color.dark_red);
F_100.SetLineWeight(2);
def F_0100 =(if isNaN(F_100[1]) then F_100 else Double.NaN);
addchartBubble(LabelsOn and F_100, F_0100,"100%",color.dark_red);

plot F_786 = if bar >= HighestAll(PLEntryBar)
then HighestAll(if isNaN(c[-1])
then PLEntryValue
else nan)
else nan;
F_786.SetDefaultColor(Color.light_red);
F_786.SetLineWeight(2);
def F_0786 =(if isNaN(F_786[1]) then F_786 else Double.NaN);
addchartBubble(LabelsOn and F_786, F_0786,"78.6%",color.light_red);

plot priceLine = HighestAll(if IsNaN(c[-1])
then c
else Double.NaN);
priceLine.SetStyle(Curve.SHORT_DASH);
priceLine.SetLineWeight(1);
priceLine.SetDefaultColor(Color.CYAN);
plot UpArrow = if c crosses above F_786 and FE > .5
then l
else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetLineWeight(5);
UpArrow.SetDefaultColor(Color.GREEN);

#Fib levels

# plots a bubble x bars after last bar

input bars_in_future = 10;
def bif = bars_in_future;


plot F_0 = (F_786-F_100) * 4.673 + F_100;
F_0.setdefaultcolor(color.red);
F_0.setlineweight(2);
def F_00 =(if isNaN(F_0[1]) then F_0 else Double.NaN);
addchartBubble(LabelsOn and F_0, F_00,"0%: " + asDollars(F_00),color.red,bif);

plot F_124 = (F_0 - F_100)/1.14155+ F_100;
F_124.setdefaultcolor(color.dark_orange);
F_124.setlineweight(2);
def F_0124 =(if isNaN(F_124[1]) then F_124 else Double.NaN);


plot F_236 = (F_0 - F_100)/1.3089+ F_100;
F_236.setdefaultcolor(color.plum);
F_236.setlineweight(2);
def F_0236 = (if isNaN(F_236[1]) then F_236 else Double.NaN);
addchartBubble(LabelsOn and F_236, F_0236,"23.6%",color.plum,bif);

plot F_382 = (F_0 - F_100)/1.618+ F_100;
F_382.setdefaultcolor(color.cyan);
F_382.setlineweight(2);
def F_0382 =(if isNaN(F_382[1]) then F_382 else Double.NaN);
addchartBubble(LabelsOn and F_382, F_0382,"38.2%",color.cyan);

plot F_50 = (F_0 - F_100)/2 + F_100;
F_50.setdefaultcolor(color.green);
F_50.setlineweight(2);
def F_050 =(if isNaN(F_50[1]) then F_50 else Double.NaN);


plot F_618 = (F_0 - F_100)/2.618+ F_100;
F_618.setdefaultcolor(color.yellow);
F_618.setlineweight(2);
def F_0618 =(if isNaN(F_618[1]) then F_618 else Double.NaN);
addchartBubble(LabelsOn and F_618, F_0618,"61.8%",color.yellow);

plot F_886 = (F_786 - F_100)/1.88+ F_100;
F_886.setdefaultcolor(color.violet);
F_886.setlineweight(2);
def F_0886 =(if isNaN(F_886[1]) then F_886 else Double.NaN);


plot FE_272 = (F_0 - F_100)*1.272 + F_100;
FE_272.setdefaultcolor(color.yellow);
FE_272.SetStyle(Curve.LONG_DASH);
FE_272.setlineweight(2);
def F_0272 =(if isNaN(FE_272[1]) then FE_272 else Double.NaN);


plot FE_50 = (F_0 - F_100)*1.5 + F_100;
FE_50.setdefaultcolor(color.GREEN);
FE_50.SetStyle(Curve.LONG_DASH);
FE_50.setlineweight(2);
def FE_050 =(if isNaN(FE_50[1]) then FE_50 else Double.NaN);


# Alerts
Alert(AlertsOn and UpArrow, " ", Alert.Bar, Sound.ding);
 
@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

I think this is what you're looking for https://usethinkscript.com/threads/premarket-after-market-for-thinkorswim.75/
 
Can anyone help me change the chart bubbles to appear bars in the future?

I tried to add it like this but think I am missing something.

# plots a bubble x bars after last bar

input bars_in_future = 10;
def bif = bars_in_future;

addchartBubble(LabelsOn and F_236, F_0236,"23.6%",color.plum,bif);

here is the script.

#Automatic Fibonacci Long Levels
#based on Mobius's Fractal Pivot Strategy
#developed by Chewie76 on 8/27/2021

# User Inputs
input n = 20;
input FractalEnergyLength = 8;
input FractalEnergyThreshold = .68;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
input LabelsOn = yes;
input AlertsOn = yes;

# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def TS = TickSize();
def nan = double.nan;
def ATR = Round((MovingAverage(AvgType, TrueRange(h, c, l), nATR)) / TS, 0) * TS;
def risk = if Between(c, 0, 1500)
then ATR
else if Between(c, 1500, 3500)
then 2
else if Between(c, 3500, 5500)
then 4
else 6;
def FE = Log(Sum((Max(h, c[1]) - Min(l, c[1])), FractalEnergyLength) /
(Highest(h, FractalEnergyLength) - Lowest(l, FractalEnergyLength)))
/ Log(FractalEnergyLength);
# Parent Aggregation Pivot High
# Pivot High Variables
def p_hh = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -1);
def p_PivotH = if (bar > n and
h == Highest(h, n) and
p_hh)
then h
else NaN;
def p_PHValue = if !IsNaN(p_PivotH)
then p_PivotH
else p_PHValue[1];
def p_PHBar = if !IsNaN(p_PivotH)
then bar
else nan;
# Pivot High and Pivot High Exit Variables
# Pivot High Variables
def hh = fold ii = 1 to n + 1
with pp = 1
while pp
do h > GetValue(h, -1);
def PivotH = if (bar > n and
h == Highest(h, n) and
hh)
then h
else Double.NaN;
def PHValue = if !IsNaN(PivotH)
then PivotH
else PHValue[1];
def PHBar = if !IsNaN(PivotH)
then bar
else nan;
# Pivot High Exit Variables
def PHExit = if (bar > n and
h == Highest(h, n) and
hh)
then if l[1] < l
then l[1]
else fold r = 0 to 20
with a = NaN
while IsNaN(a)
do if GetValue(l[1], r) < l
then GetValue(l[1], r)
else NaN
else Double.NaN;
def PHExitValue = if !IsNaN(PHExit)
then PHExit
else PHExitValue[1];
def PHExitBar = if (bar > n and
h == Highest(h, n) and
hh)
then if l[1] < l
then bar - 1
else fold d = 0 to 20
with y = NaN
while IsNaN(y)
do if GetValue(l[1], d) < l
then GetValue(bar - 1, d)
else NaN
else NaN;
# Pivot Low and Pivot Low Entry Variables
# Parent Pivot Low Variables
def p_ll = fold j = 1 to n + 1
with q = 1
while q
do l < GetValue(l, -1);
def p_PivotL = if (bar > n and
l == Lowest(l, n) and
p_ll)
then l
else NaN;
def p_PLValue = if !IsNaN(p_PivotL)
then p_PivotL
else p_PLValue[1];
def p_PLBar = if !IsNaN(p_PivotL)
then bar
else nan;
# Pivot Low Variables
def ll = fold jj = 1 to n + 1
with qq = 1
while qq
do l < GetValue(l, -1);
def PivotL = if (bar > n and
l == Lowest(l, n) and
ll)
then l
else NaN;
def PLValue = if !IsNaN(PivotL)
then PivotL
else PLValue[1];
def PLBar = if !IsNaN(PivotL)
then bar
else nan;
# Pivot Low Entry Variables
def PLEntry = if (bar > n and
l == Lowest(l, n) and
ll)
then if h[1] > h
then h[1]
else fold t = 0 to 20
with w = NaN
while IsNaN(w)
do if GetValue(h[1], t) > h
then GetValue(h[1], t)
else NaN
else NaN;
def PLEntryValue = if !IsNaN(PLEntry)
then PLEntry
else PLEntryValue[1];
def PLEntryBar = if (bar > n and
l == Lowest(l, n) and
ll)
then if h[1] > h
then bar - 1
else fold u = 0 to 20
with z = NaN
while IsNaN(z)
do if GetValue(h[1], u) > h
then GetValue(bar - 1, u)
else NaN
else NaN;
# Plots

plot F_100 = if bar >= HighestAll(PLBar)
then HighestAll(if isNaN(c[-1])
then PLValue
else nan)
else nan;
F_100.SetDefaultColor(Color.dark_red);
F_100.SetLineWeight(2);
def F_0100 =(if isNaN(F_100[1]) then F_100 else Double.NaN);
addchartBubble(LabelsOn and F_100, F_0100,"100%",color.dark_red);

plot F_786 = if bar >= HighestAll(PLEntryBar)
then HighestAll(if isNaN(c[-1])
then PLEntryValue
else nan)
else nan;
F_786.SetDefaultColor(Color.light_red);
F_786.SetLineWeight(2);
def F_0786 =(if isNaN(F_786[1]) then F_786 else Double.NaN);
addchartBubble(LabelsOn and F_786, F_0786,"78.6%",color.light_red);

plot priceLine = HighestAll(if IsNaN(c[-1])
then c
else Double.NaN);
priceLine.SetStyle(Curve.SHORT_DASH);
priceLine.SetLineWeight(1);
priceLine.SetDefaultColor(Color.CYAN);
plot UpArrow = if c crosses above F_786 and FE > .5
then l
else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetLineWeight(5);
UpArrow.SetDefaultColor(Color.GREEN);

#Fib levels

# plots a bubble x bars after last bar

input bars_in_future = 10;
def bif = bars_in_future;


plot F_0 = (F_786-F_100) * 4.673 + F_100;
F_0.setdefaultcolor(color.red);
F_0.setlineweight(2);
def F_00 =(if isNaN(F_0[1]) then F_0 else Double.NaN);
addchartBubble(LabelsOn and F_0, F_00,"0%: " + asDollars(F_00),color.red,bif);

plot F_124 = (F_0 - F_100)/1.14155+ F_100;
F_124.setdefaultcolor(color.dark_orange);
F_124.setlineweight(2);
def F_0124 =(if isNaN(F_124[1]) then F_124 else Double.NaN);


plot F_236 = (F_0 - F_100)/1.3089+ F_100;
F_236.setdefaultcolor(color.plum);
F_236.setlineweight(2);
def F_0236 = (if isNaN(F_236[1]) then F_236 else Double.NaN);
addchartBubble(LabelsOn and F_236, F_0236,"23.6%",color.plum,bif);

plot F_382 = (F_0 - F_100)/1.618+ F_100;
F_382.setdefaultcolor(color.cyan);
F_382.setlineweight(2);
def F_0382 =(if isNaN(F_382[1]) then F_382 else Double.NaN);
addchartBubble(LabelsOn and F_382, F_0382,"38.2%",color.cyan);

plot F_50 = (F_0 - F_100)/2 + F_100;
F_50.setdefaultcolor(color.green);
F_50.setlineweight(2);
def F_050 =(if isNaN(F_50[1]) then F_50 else Double.NaN);


plot F_618 = (F_0 - F_100)/2.618+ F_100;
F_618.setdefaultcolor(color.yellow);
F_618.setlineweight(2);
def F_0618 =(if isNaN(F_618[1]) then F_618 else Double.NaN);
addchartBubble(LabelsOn and F_618, F_0618,"61.8%",color.yellow);

plot F_886 = (F_786 - F_100)/1.88+ F_100;
F_886.setdefaultcolor(color.violet);
F_886.setlineweight(2);
def F_0886 =(if isNaN(F_886[1]) then F_886 else Double.NaN);


plot FE_272 = (F_0 - F_100)*1.272 + F_100;
FE_272.setdefaultcolor(color.yellow);
FE_272.SetStyle(Curve.LONG_DASH);
FE_272.setlineweight(2);
def F_0272 =(if isNaN(FE_272[1]) then FE_272 else Double.NaN);


plot FE_50 = (F_0 - F_100)*1.5 + F_100;
FE_50.setdefaultcolor(color.GREEN);
FE_50.SetStyle(Curve.LONG_DASH);
FE_50.setlineweight(2);
def FE_050 =(if isNaN(FE_50[1]) then FE_50 else Double.NaN);


# Alerts
Alert(AlertsOn and UpArrow, " ", Alert.Bar, Sound.ding);

This will plot the bubbles past the last bar. You can use the input to move them.

Screenshot 2023-07-03 072324.png

Code:
#Automatic Fibonacci Long Levels
#based on Mobius's Fractal Pivot Strategy
#developed by Chewie76 on 8/27/2021

# User Inputs
input n = 20;
input FractalEnergyLength = 8;
input FractalEnergyThreshold = .68;
input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
input LabelsOn = yes;
input AlertsOn = yes;

# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def TS = TickSize();
def nan = Double.NaN;
def ATR = Round((MovingAverage(AvgType, TrueRange(h, c, l), nATR)) / TS, 0) * TS;
def risk = if Between(c, 0, 1500)
then ATR
else if Between(c, 1500, 3500)
then 2
else if Between(c, 3500, 5500)
then 4
else 6;
def FE = Log(Sum((Max(h, c[1]) - Min(l, c[1])), FractalEnergyLength) /
(Highest(h, FractalEnergyLength) - Lowest(l, FractalEnergyLength)))
/ Log(FractalEnergyLength);
# Parent Aggregation Pivot High
# Pivot High Variables
def p_hh = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -1);
def p_PivotH = if (bar > n and
h == Highest(h, n) and
p_hh)
then h
else nan;
def p_PHValue = if !IsNaN(p_PivotH)
then p_PivotH
else p_PHValue[1];
def p_PHBar = if !IsNaN(p_PivotH)
then bar
else nan;
# Pivot High and Pivot High Exit Variables
# Pivot High Variables
def hh = fold ii = 1 to n + 1
with pp = 1
while pp
do h > GetValue(h, -1);
def PivotH = if (bar > n and
h == Highest(h, n) and
hh)
then h
else Double.NaN;
def PHValue = if !IsNaN(PivotH)
then PivotH
else PHValue[1];
def PHBar = if !IsNaN(PivotH)
then bar
else nan;
# Pivot High Exit Variables
def PHExit = if (bar > n and
h == Highest(h, n) and
hh)
then if l[1] < l
then l[1]
else fold r = 0 to 20
with a = nan
while IsNaN(a)
do if GetValue(l[1], r) < l
then GetValue(l[1], r)
else nan
else Double.NaN;
def PHExitValue = if !IsNaN(PHExit)
then PHExit
else PHExitValue[1];
def PHExitBar = if (bar > n and
h == Highest(h, n) and
hh)
then if l[1] < l
then bar - 1
else fold d = 0 to 20
with y = nan
while IsNaN(y)
do if GetValue(l[1], d) < l
then GetValue(bar - 1, d)
else nan
else nan;
# Pivot Low and Pivot Low Entry Variables
# Parent Pivot Low Variables
def p_ll = fold j = 1 to n + 1
with q = 1
while q
do l < GetValue(l, -1);
def p_PivotL = if (bar > n and
l == Lowest(l, n) and
p_ll)
then l
else nan;
def p_PLValue = if !IsNaN(p_PivotL)
then p_PivotL
else p_PLValue[1];
def p_PLBar = if !IsNaN(p_PivotL)
then bar
else nan;
# Pivot Low Variables
def ll = fold jj = 1 to n + 1
with qq = 1
while qq
do l < GetValue(l, -1);
def PivotL = if (bar > n and
l == Lowest(l, n) and
ll)
then l
else nan;
def PLValue = if !IsNaN(PivotL)
then PivotL
else PLValue[1];
def PLBar = if !IsNaN(PivotL)
then bar
else nan;
# Pivot Low Entry Variables
def PLEntry = if (bar > n and
l == Lowest(l, n) and
ll)
then if h[1] > h
then h[1]
else fold t = 0 to 20
with w = nan
while IsNaN(w)
do if GetValue(h[1], t) > h
then GetValue(h[1], t)
else nan
else nan;
def PLEntryValue = if !IsNaN(PLEntry)
then PLEntry
else PLEntryValue[1];
def PLEntryBar = if (bar > n and
l == Lowest(l, n) and
ll)
then if h[1] > h
then bar - 1
else fold u = 0 to 20
with z = nan
while IsNaN(z)
do if GetValue(h[1], u) > h
then GetValue(bar - 1, u)
else nan
else nan;


plot priceLine = HighestAll(if IsNaN(c[-1])
then c
else Double.NaN);
priceLine.SetStyle(Curve.SHORT_DASH);
priceLine.SetLineWeight(1);
priceLine.SetDefaultColor(Color.CYAN);



#Fib levels
# plots a bubble x bars after last bar

input bars_in_future = 10;
def b = bars_in_future;
def b1 = b + 1;

# Plots

plot F_786 = if bar >= HighestAll(PLEntryBar)
then HighestAll(if IsNaN(c[-1])
then PLEntryValue
else nan)
else nan;
F_786.SetDefaultColor(Color.LIGHT_RED);
F_786.SetLineWeight(2);
def F_0786 = (if IsNaN(F_786[1]) then F_786 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_786, "78.6%", Color.LIGHT_RED);

plot UpArrow = if c crosses above F_786 and FE > .5
then l
else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetLineWeight(5);
UpArrow.SetDefaultColor(Color.GREEN);

plot F_100 = if bar >= HighestAll(PLBar)
then HighestAll(if IsNaN(c[-1])
then PLValue
else nan)
else nan;
F_100.SetDefaultColor(Color.DARK_RED);
F_100.SetLineWeight(2);
def F_0100 = (if IsNaN(F_100[1]) then F_100 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_100, "100%", Color.DARK_RED);

plot F_0 = (F_786 - F_100) * 4.673 + F_100;
F_0.SetDefaultColor(Color.RED);
F_0.SetLineWeight(2);
def F_00 = (if IsNaN(F_0[1]) then F_0 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_0, "0%: \n" + AsDollars(F_0), Color.RED);

plot F_124 = (F_0 - F_100) / 1.14155 + F_100;
F_124.SetDefaultColor(Color.DARK_ORANGE);
F_124.SetLineWeight(2);
def F_0124 = (if IsNaN(F_124[1]) then F_124 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_124, "12.4%", Color.DARK_ORANGE);

plot F_236 = (F_0 - F_100) / 1.3089 + F_100;
F_236.SetDefaultColor(Color.PLUM);
F_236.SetLineWeight(2);
def F_0236 = (if IsNaN(F_236[1]) then F_236 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_236, "23.6%", Color.PLUM);

plot F_382 = (F_0 - F_100) / 1.618 + F_100;
F_382.SetDefaultColor(Color.CYAN);
F_382.SetLineWeight(2);
def F_0382 = (if IsNaN(F_382[1]) then F_382 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_382, "38.2%", Color.CYAN);

plot F_50 = (F_0 - F_100) / 2 + F_100;
F_50.SetDefaultColor(Color.GREEN);
F_50.SetLineWeight(2);
def F_050 = (if IsNaN(F_50[1]) then F_50 else Double.NaN);


plot F_618 = (F_0 - F_100) / 2.618 + F_100;
F_618.SetDefaultColor(Color.YELLOW);
F_618.SetLineWeight(2);
def F_0618 = (if IsNaN(F_618[1]) then F_618 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_618, "61.8%", Color.YELLOW);

plot F_886 = (F_786 - F_100) / 1.88 + F_100;
F_886.SetDefaultColor(Color.VIOLET);
F_886.SetLineWeight(2);
def F_0886 = (if IsNaN(F_886[1]) then F_886 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), F_886, "88.6%", Color.VIOLET);

plot FE_272 = (F_0 - F_100) * 1.272 + F_100;
FE_272.SetDefaultColor(Color.YELLOW);
FE_272.SetStyle(Curve.LONG_DASH);
FE_272.SetLineWeight(2);
def F_0272 = (if IsNaN(FE_272[1]) then FE_272 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), FE_272, "27.2%", Color.YELLOW);

plot FE_50 = (F_0 - F_100) * 1.5 + F_100;
FE_50.SetDefaultColor(Color.GREEN);
FE_50.SetStyle(Curve.LONG_DASH);
FE_50.SetLineWeight(2);
def FE_050 = (if IsNaN(FE_50[1]) then FE_50 else Double.NaN);
AddChartBubble(LabelsOn and IsNaN(close[b]) and !IsNaN(close[b1]), FE_50, "50.0%", Color.GREEN);

# Alerts
Alert(AlertsOn and UpArrow, " ", Alert.BAR, Sound.Ding);
 
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%.

Folks here is version 1.3 of the Auto Fib study that now displays the bubbles on the right of the chart.
Please ensure that you increase the expansion area to that the bubbles have room to be displayed
Personally I set that to 22 on my chart settings

Chart Settings > Time Axis > Expansion Area

Given several changes to this code from the first time it was posted by @BenTen in 2018, I have created a change log
It details the various modifications to the base code that was made including a really nice cleaned up version from @theelderwand

Hope this helps

Code:
# 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
Thank you so much, this is the only one I found that actually works with my timeframe
 
This will plot the bubbles past the last bar. You can use the input to move them.
Sleepy, What is the "n" reference? It doesn't seem to be bars. When use on 1m TF, 10 n is the entire day high to low. I have to move to 1 to get a closer intraday. On the 5 min., I just tested NVDA 1:40 pm. At 5 n, I get 0% at 454.57 which is around 40 bars back.
 

Attachments

  • FIBs.jpg
    FIBs.jpg
    190.9 KB · Views: 303
Sleepy, What is the "n" reference? It doesn't seem to be bars. When use on 1m TF, 10 n is the entire day high to low. I have to move to 1 to get a closer intraday. On the 5 min., I just tested NVDA 1:40 pm. At 5 n, I get 0% at 454.57 which is around 40 bars back.

I only added how to place the bubbles to @chewie76 code https://usethinkscript.com/threads/...onacci-level-indicators-for-thinkorswim.7731/

The 'n' in the code is the number of bars used by Mobius to determine pivot highs/lows. Chewie then adapted Mobius' code to determine the Fib 0% and 100%. If you have any questions about how he used that code, please ask Chewie.
 
trying to build a scanner to scan looking for retracement to the .78 from a HH or LL over last 20 periods- time to be adjusted in settings.

Here is what I have so far.
There is an error expected double
no such variable N at 66:11

i tried changing to plot - didnt help

I am REALLY beginner at code- so speak like I'm 5 pls.
Nothing against 5 year olds!
Juno

# 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_5 = .786;



plot 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 value5 = range * coefficient_5;


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


Plot Retracement5 = if condition1 then highestall(b + value5) else if condition2 then highestall(a - value5) else double.nan;


Retracement5.assignvaluecolor(CreateColor(0,255,255));
Retracement5.setLineWeight(2);
retracement5.hidebubble();




alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
# End Auto Fib v1.3
 
[Edited to provide a basic trendline option and expansion of the def bars to provide more plots.]

1.This allows an innput of the timeframe desired (1330 to 2230 in your case). The start can be greater than the end time input, for example, to do the entire aftermarket for stocks input from 1600 to 0929,
2.The current developing fibs will be displayed. To do this, the volumeprofiles profilehigh/profilelow was used set at the bar timeframe. This has a limitation on the number of bars it will then display on your chart. The lower the chart aggregation the fewer the fibs will plot.
3. The fibs will flip from 0 and 100 to 100 and 0 depending on whether the bar of the high is before the bar of the low.
4. Various options are available to extend the lines (default) yes, showtodayonly (default no).
Greetings Friends, Is there a way that this can use the Highest Close Price of Candle and Lowest Close of Candle for period please?

Thank you in advance.
 

msingh87

Greetings Friends, Is there a way that this can use the Highest Close Price of Candle and Lowest Close of Candle for period please?

Thank you in advance.


I made an adjustment to the referenced script to plot a developing HL Close during the premarket and then extend that through the regular trading hours till the next premarket start.

The image shows input showtodayonly set to yes to just plot the last fibs.

Screenshot 2023-12-16 140527.png
Code:
#Auto_Fibs_TimeRange_Flip_0_100_using_HL_Closes

input start = 0400;
input end   = 0929;
input showtodayonly  = no;
input bubblemover    = 2;
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 bn     = BarNumber();
def na     = Double.NaN;

def hprofile = if aftermarket[-1] and aftermarket == 0
               then close
               else if aftermarket and close > hprofile[1]
               then close
               else hprofile[1];

def lprofile = if aftermarket[-1] and aftermarket == 0
               then close
               else if aftermarket and close < lprofile[1]
               then close
               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 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;

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

plot ORH;
plot ORL;
plot Fib50;
plot Fib236;
plot Fib382;
plot Fib618;
plot Fib764;
plot Fib1618;
plot Fib_618;

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

if showtodayonly and HighestAll(dataCount) - dataCount > 0
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;

} else {
    ORH      = hrange;
    ORL      = lrange;
    Fib50    = F50;
    Fib236   = F236;
    Fib382   = F382;
    Fib618   = F618;
    Fib764   = F764;
    Fib1618  = F1618;
    Fib_618  = F_618;

}

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

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 = hbar;
plot xlbar = lbar;
xhbar.SetHiding(yes);
xlbar.SetHiding(yes);

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

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

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

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

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

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

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

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

AddChartBubble(
if !showbubbles
then na
else IsNaN(close[mo]) and !IsNaN(close[mo1]),
Fib_618[mo1],
(if xhbar[mo + 1] > xlbar[mo + 1] then -618 else 1618),
Fib_618.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[1] == 1 and aftermarket == 0 and !IsNaN(xhbar1) then hrange else if aftermarket[1] == 1 and aftermarket == 0 and !IsNaN(xlbar1) then hrange else na else na;
xline.EnableApproximation();
;
 
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%.

Folks here is version 1.3 of the Auto Fib study that now displays the bubbles on the right of the chart.
Please ensure that you increase the expansion area to that the bubbles have room to be displayed
Personally I set that to 22 on my chart settings

Chart Settings > Time Axis > Expansion Area

Given several changes to this code from the first time it was posted by @BenTen in 2018, I have created a change log
It details the various modifications to the base code that was made including a really nice cleaned up version from @theelderwand

Hope this helps

Code:
# 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
its possible to create a scanner where the stocks on daily pull to fib level 16.8%.
 
its possible to create a scanner where the stocks on daily pull to fib level 16.8%.

1. Copy the full code in post #3 link and pasting it a new study.
2. Change these 2 lines as follows in your new study and save it with a new name.
3. Copy and paste your revised code in a custom study filter in the scanner.
3a. Rather than copying and pasting the code, you can add a custom study filter and reference the new name you gave your study, for example, name().scan.

Code:
input coefficient_1 = .168;

plot scan = close crosses above retracement1 and upward;
 
Good afternoon @tomsk @SleepyZ I hope you are doing well, As I mentioned before, I am not a coder and I am grateful for the help we receive in this community. I am looking for an Automatic Fibo indicator for Options. The closest thing is the indicator in Post # 1. I don't know if it would be possible to modify the indicator code in Post # 1 https://usethinkscript.com/threads/auto-fib-fibonacci- levels-indicator-for-thinkorswim.14/, to use it in option charts, I have attached screenshoots of an SPX call option with the TOS Fibo tool and with the Auto Fibo Levels indicator, the problem is that the indicator takes the lowest price on the chart (even if I select only 1 day) and as seen in the screenshoot, the low that the indicator took was $0.90 which is from the previous day, being an intraday call option the lowest point should be zero as is plotted on the graph with the TOS tool. ( And also if it were possible to have the option to activate on/off the coefficient and separately the price and to be able to select separately whether the coefficient and/or the price is shown on the left or right, I ask about that option because if it had open 4 options contracts the space to see the bubbles with the coefficients and price would be very limited. In my search for a Fibo indicator for options I saw an indicator in Post #350 https://usethinkscript.com/threads/...vels-indicator-for-thinkorswim.14/post-127643 that had the coefficients with the same colors as the drawn lines that could help to better differentiate the levels. And if you could add the 70.5% and 90% levels to the indicator, again thank you very much for your valuable help.
In the case of a 0 DTE option, this indicator should take anchor 1 (zero) starting at 9:30 am. And if you need the option to see the movement of the contract price in the week as shown in screenshoot 5, you can select the number of days.
 

Attachments

  • Screenshot 2024-02-02 SPX_Call_Contract_Five_Days_with_TOS_Fibo_Tool_and_Auto_Fibo.png
    Screenshot 2024-02-02 SPX_Call_Contract_Five_Days_with_TOS_Fibo_Tool_and_Auto_Fibo.png
    115.1 KB · Views: 180
  • Screenshot 2024-02-02 Four_Option_Contracts_with FIBOs.png
    Screenshot 2024-02-02 Four_Option_Contracts_with FIBOs.png
    443.6 KB · Views: 185
  • Screenshot 2024-02-02 SPX_Call_Contract_with_TOS_Fibo_Tool_and_Auto_Fibo_Indicator.png
    Screenshot 2024-02-02 SPX_Call_Contract_with_TOS_Fibo_Tool_and_Auto_Fibo_Indicator.png
    165.4 KB · Views: 174
  • Screenshot 2024-02-02 SPX_Call_Contract_with_AUTO_Fibo_Indicator.png
    Screenshot 2024-02-02 SPX_Call_Contract_with_AUTO_Fibo_Indicator.png
    86.9 KB · Views: 146
  • Screenshot 2024-02-02 SPX_Call_Contract_with_TOS_Fibo_Tool.png
    Screenshot 2024-02-02 SPX_Call_Contract_with_TOS_Fibo_Tool.png
    83 KB · Views: 163
Good afternoon @tomsk @SleepyZ I hope you are doing well, As I mentioned before, I am not a coder and I am grateful for the help we receive in this community. I am looking for an Automatic Fibo indicator for Options. The closest thing is the indicator in Post # 1. I don't know if it would be possible to modify the indicator code in Post # 1 https://usethinkscript.com/threads/auto-fib-fibonacci- levels-indicator-for-thinkorswim.14/, to use it in option charts, I have attached screenshoots of an SPX call option with the TOS Fibo tool and with the Auto Fibo Levels indicator, the problem is that the indicator takes the lowest price on the chart (even if I select only 1 day) and as seen in the screenshoot, the low that the indicator took was $0.90 which is from the previous day, being an intraday call option the lowest point should be zero as is plotted on the graph with the TOS tool. ( And also if it were possible to have the option to activate on/off the coefficient and separately the price and to be able to select separately whether the coefficient and/or the price is shown on the left or right, I ask about that option because if it had open 4 options contracts the space to see the bubbles with the coefficients and price would be very limited. In my search for a Fibo indicator for options I saw an indicator in Post #350 https://usethinkscript.com/threads/...vels-indicator-for-thinkorswim.14/post-127643 that had the coefficients with the same colors as the drawn lines that could help to better differentiate the levels. And if you could add the 70.5% and 90% levels to the indicator, again thank you very much for your valuable help.
In the case of a 0 DTE option, this indicator should take anchor 1 (zero) starting at 9:30 am. And if you need the option to see the movement of the contract price in the week as shown in screenshoot 5, you can select the number of days.

[Edit: See Post 372 https://usethinkscript.com/threads/...vels-indicator-for-thinkorswim.14/post-137860 for final code for OPTIONS ONLY autofibs]

1. This is the requested mod to post #1 in this thread. The logic is set to use 0 instead of the low for the last day.
2. The highs for the last day will continue to develop throughout the day, changing the autofibs with it.
3. The 2 fib levels were added.
4. The price bubbles for the fibs were hidden. The code to do this was commented (#) out, causing the prices to display.

Screenshot 2024-02-03 165207.png
Code:
# Auto Fib V1.4
# 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

# V1.4 - 20240203 - Sleepyz        - Modified to work for Options for only the last day. There the
#                                    low was defaulted to 0 as requested by the requestor. 2 fibs added


#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 Coefficient_7 = .705;
input Coefficient_8 = .900;

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

def n1  = n + 1;
def lastdayhigh = if getday()!=getday() then high else if high> lastdayhigh[1] then high else lastdayhigh[1];
def lastdaylow  = CompoundValue(1, if GetDay() != GetDay()[1] then 0 else if low < lastdaylow[1] then low else lastdaylow[1], low);
def a = highestall(lastdayhigh);
def b = Lowestall(lastdaylow);
def b1 = if b==0 and getday()==getlastday() then barnumber() else double.nan;
def barnumber = BarNumber();
def c = if high == a then barnumber else Double.NaN;
def d = if b!=0 and low == b then barnumber else if b==0 then b1 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 value7 = range * Coefficient_7;
def value8 = range * Coefficient_8;

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;
plot Retracement7 = if condition1 then HighestAll(b + value7) else if condition2 then HighestAll(a - value7) else Double.NaN;
plot Retracement8 = if condition1 then HighestAll(b + value8) else if condition2 then HighestAll(a - value8) 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);

Retracement7.AssignValueColor(CreateColor(255, 255, 255));
Retracement7.SetLineWeight(4);
#Retracement7.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement7, Concat( (Coefficient_7 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement7, Concat( (Coefficient_7 * 100), "%"), GetColor(LabelColor), yes);

Retracement8.AssignValueColor(CreateColor(255, 255, 255));
Retracement8.SetLineWeight(4);
#Retracement8.HideBubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement8, Concat( (Coefficient_8 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement8, Concat( (Coefficient_8 * 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
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
200 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