Auto Fib (Fibonacci) Levels Indicator for ThinkorSwim

See if this might be what you are requesting. This will make the highest price's bar changed to show the high of a prior bar offset by the number of bars at the input.

Add the following code to the script:
input offset = 1;

Modify the following code in the script:

def a = if high == HighestAll(high) then high[offset] else a[1];

hcxkNfd.gif
I would be vary interested in how you got the bubbles to appear in the middle. I would like center or right alignment.

Thanks!
 

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

I would be vary interested in how you got the bubbles to appear in the middle. I would like center or right alignment.

Thanks!

Here is an addchartbubble example that might help. It displays code for both a movable bubble and a far right bubble placement.

Capture.jpg
Code:
def h   = if IsNaN(close) then h[1] else Highest(high, 5);#extends line to right
plot hh = h;

#Movable bubble
#The IsNaN(close[n]) and !IsNaN(close[n1]) defines the last candle on the chart
input n = 1; #used to move the bubble left and right
def n1  = n + 1;
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), hh[n1] , "High", Color.GREEN, yes);

#Places bubble to far right
#The BarNumber() == HighestAll(BarNumber()) defines the last barnumber on the chart, including the right expansion space
AddChartBubble(BarNumber() == HighestAll(BarNumber()), hh , "High", Color.GREEN, yes);
 
Last edited:
Can you please let me know how I can shift the bubbles to the right side and price tags on the fib lines. This will help me a lot. If it is a too much of coding and work then leave as is.

Thanks,
 
Can you please let me know how I can shift the bubbles to the right side and price tags on the fib lines. This will help me a lot. If it is a too much of coding and work then leave as is.

Thanks,

This is the code in post #1 modified to allow a user input option to display bubbles on left and/or right side of the Fibonacci lines.

Capture.jpg
Code:
#20210716 Sleepyz - modified to have optional bubbles on Left Side and/or Right Side of Fibonacci Lines

#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>
#hint onExpansion: Determines if the retracement lines are projected past the current bar into the right side expansion <b>(Default is Yes)</b>
#hint Extend_to_left: Determines if the retracement lines are extended to the left side of the chart. <b>(Default is No)</b>

#hint Coefficient0: 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: onExpansion
#wizard text: onExpansion:
#wizard input: Extend_to_left
#wizard text: Extend_to_left:
#wizard input: Coefficient0
#wizard text: Coefficient0:
#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 show_bubbles_left  = yes;
input show_bubbles_right = yes;
input price = close;
input high = high;
input low = low;
input onExpansion = Yes;
input Extend_to_left = no;
input Coefficient0 = 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;

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;

Plot Retracement0 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient0))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient0)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient0))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient0)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient0))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient0)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient0))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient0)) else double.nan;
Retracement0.assignvaluecolor(color.red);
retracement0.hidebubble();


Plot Retracement1 =  if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_1))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_1)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_1))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_1)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_1))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_1)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_1))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_1)) else double.nan;
Retracement1.assignvaluecolor(color.red);
retracement1.hidebubble();


Plot Retracement2 =if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_2))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_2)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_2))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_2)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_2))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_2)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_2))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_2)) else double.nan;
Retracement2.assignvaluecolor(color.red);
retracement2.hidebubble();


Plot Retracement3 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_3))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_3)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_3))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_3)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_3))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_3)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_3))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_3)) else double.nan;
Retracement3.assignvaluecolor(color.red);
retracement3.hidebubble();


Plot Retracement4 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_4))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_4)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_4))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_4)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_4))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_4)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_4))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_4)) else double.nan;
Retracement4.assignvaluecolor(color.red);
retracement4.hidebubble();


Plot Retracement5 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_5))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_5)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_5))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_5)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_5))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_5)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_5))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_5)) else double.nan;
Retracement5.assignvaluecolor(color.red);
retracement5.hidebubble();


Plot Retracement6 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_6))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_6)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_6))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_6)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_6))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_6)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_6))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_6)) else double.nan;
Retracement6.assignvaluecolor(color.red);
retracement6.hidebubble();


#Bubbles on Left Side
AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement0, concat( (coefficient0 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement0, concat( (coefficient0 * 100), "%"), color.red, yes);

AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement1, concat( (coefficient_1 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement1, concat( (coefficient_1 * 100), "%"), color.red, yes);

AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement2, concat( (coefficient_2 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement2, concat( (coefficient_2 * 100), "%"), color.red, yes);

AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);

AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement4, concat( (coefficient_4 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement4, concat( (coefficient_4 * 100), "%"), color.red, yes);

AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement5, concat( (coefficient_5 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement5, concat( (coefficient_5 * 100), "%"), color.red, yes);

AddChartBubble(show_bubbles_left and (downward and barnumber == highnumberall), retracement6, concat( (coefficient_6 * 100), "%"), color.red, yes);
AddChartBubble(show_bubbles_left and (upward and barnumber == lownumberall), retracement6, concat( (coefficient_6 * 100), "%"), color.red, yes);

#Bubbles on Right Side
AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement0, Concat( (coefficient0 * 100), "%\n") + Concat( "$", Round(retracement0, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement0, Concat( (coefficient0 * 100), "%\n") + Concat( "$", Round(retracement0, 2)), Color.YELLOW, yes);

AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement1, Concat( (coefficient_1 * 100), "%\n") + Concat( "$", Round(retracement1, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement1, Concat( (coefficient_1 * 100), "%\n") + Concat( "$", Round(retracement1, 2)), Color.YELLOW, yes);

AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement2, Concat( (coefficient_2 * 100), "%\n") + Concat( "$", Round(retracement2, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement2, Concat( (coefficient_2 * 100), "%\n") + Concat( "$", Round(retracement2, 2)), Color.YELLOW, yes);

AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement3, Concat( (coefficient_3 * 100), "%\n") + Concat( "$", Round(retracement3, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement3, Concat( (coefficient_3 * 100), "%\n") + Concat( "$", Round(retracement3, 2)), Color.YELLOW, yes);

AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement4, Concat( (coefficient_4 * 100), "%\n") + Concat( "$", Round(retracement4, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement4, Concat( (coefficient_4 * 100), "%\n") + Concat( "$", Round(retracement4, 2)), Color.YELLOW, yes);

AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement5, Concat( (coefficient_5 * 100), "%\n") + Concat( "$", Round(retracement5, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement5, Concat( (coefficient_5 * 100), "%\n") + Concat( "$", Round(retracement5, 2)), Color.YELLOW, yes);

AddChartBubble(show_bubbles_right and (downward and BarNumber() == HighestAll(BarNumber())), retracement6, Concat( (coefficient_6 * 100), "%\n") + Concat( "$", Round(retracement6, 2)), Color.YELLOW, yes);
AddChartBubble(show_bubbles_right and (upward and BarNumber() == HighestAll(BarNumber())), retracement6, Concat( (coefficient_6 * 100), "%\n") + Concat( "$", Round(retracement6, 2)), Color.YELLOW, yes);


#Alerts
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");
 
Hi @BenTen & @MerryDay & @SleepyZ is there a way to obtain an Automatic Fib Retracement that uses the previous day (High of Day and Low of Day) and plots that on the next day chart? I want it to work mainly on the 15 min chart with the following levels:

-1 - Green
-0.62 - Green
-0.27 - Green
0 - Green
0.236 - Red
0.382 - Red
0.50 - Yellow
0.62 - Blue
0.705 - Blue
0.79 - Blue
1 - Green
1.27 - Green
1.618 - Green
2 - Green
 
Last edited by a moderator:
Hi @BenTen & @MerryDay & @SleepyZ is there a way to obtain an Automatic Fib Retracement that uses the previous day (High of Day and Low of Day) and plots that on the next day chart? I want it to work mainly on the 15 min chart with the following levels:

-1 - Green
-0.62 - Green
-0.27 - Green
0 - Green
0.236 - Red
0.382 - Red
0.50 - Yellow
0.62 - Blue
0.705 - Blue
0.79 - Blue
1 - Green
1.27 - Green
1.618 - Green
2 - Green
See if this helps. Picture is set to showtodayonly == yes. You can move the bubbles left/right at the bubblemover input.
Capture.jpg
Ruby:
#Auto_FibPrevDay - plots high/low from previous day and fib levels based thereon

input ShowTodayOnly = { default "No", "Yes"};
input showbubbles   = yes;
input bubblemover   = 4; #Hint n: Number of Bars to shift bubble to the right
input period        = AggregationPeriod.DAY;
input displace      = 1;

plot ORH = if showtodayonly and !IsNaN(close(period = period)[-1]) then double.nan else high(period = period)[displace];
plot ORL = if showtodayonly and !IsNaN(close(period = period)[-1]) then double.nan else  low(period = period)[displace];

ORH.SetDefaultColor(Color.RED);
ORH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORH.SetLineWeight(2);

ORL.SetDefaultColor(Color.GREEN);
ORL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ORL.SetLineWeight(2);

input F1 = -1.00;
input F2 = -0.62;
input F3 = -0.27;
input F4 = 0.236;
input F5 = 0.382;
input F6 = 0.500;
input F7 = 0.62;
input F8 = 0.705;
input F9 = 0.79;
input F10 = 1.27;
input F11 = 1.618;
input F12 = 2.00;

def rHi =  ORH;
def rLo =  ORL;

def range  = rHi - rLo;
plot FF1   = rLo + (range * F1);
plot FF2   = rLo + (range * F2);
plot FF3   = rLo + (range * F3);
plot FF4   = rLo + (range * F4);
plot FF5   = rLo + (range * F5);
plot FF6   = rLo + (range * F6);
plot FF7   = rLo + (range * F7);
plot FF8   = rLo + (range * F8);
plot FF9   = rLo + (range * F9);
plot FF10  = rLo + (range * F10);
plot FF11  = rLo + (range * F11);
plot FF12  = rLo + (range * F12);

def h = high(period = AggregationPeriod.DAY);
def l = low(period = AggregationPeriod.DAY);



FF1.SetDefaultColor(Color.GREEN);
FF1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF1.SetLineWeight(1);

FF2.SetDefaultColor(Color.GREEN);
FF2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF2.SetLineWeight(1);

FF3.SetDefaultColor(Color.GREEN);
FF3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF3.SetLineWeight(1);

FF4.SetDefaultColor(Color.RED);
FF4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF4.SetLineWeight(1);

FF5.SetDefaultColor(Color.RED);
FF5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF5.SetLineWeight(1);

FF6.SetDefaultColor(Color.YELLOW);
FF6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF6.SetLineWeight(1);

FF7.SetDefaultColor(Color.BLUE);
FF7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF7.SetLineWeight(1);

FF8.SetDefaultColor(Color.BLUE);
FF8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF8.SetLineWeight(1);

FF9.SetDefaultColor(Color.BLUE);
FF9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF9.SetLineWeight(1);

FF10.SetDefaultColor(Color.GREEN);
FF10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF10.SetLineWeight(1);

FF11.SetDefaultColor(Color.GREEN);
FF11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF11.SetLineWeight(1);

FF12.SetDefaultColor(Color.GREEN);
FF12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF12.SetLineWeight(1);

def   b           = bubblemover;
def   b1          = b + 1;
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF1[b], F1, FF1.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF2[b], F2, FF2.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF3[b], F3, FF3.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF4[b], F4, FF4.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF5[b], F5, FF5.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF6[b], F6, FF6.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF7[b], F7, FF7.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF8[b], F8, FF8.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF9[b], F9, FF9.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF10[b], F10, FF10.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF11[b], F11, FF11.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), FF12[b], F12, FF12.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), orh[b], 1, orh.Takevaluecolor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), orl[b], 0, orl.Takevaluecolor());
 
Hello,
Would it be possible to scan for stocks approaching the golden pocket using the 3yr weekly charts. Using 3year low and 3 year high and searching for a stock coming back down to the within 1-5% of the 61.8% decrease from the top value. Giving the trader a heads up of the approaching pocket for a bounce.
Any help would be appreciated Thanks.
 
In the top example what can I add to the code to display the price level of the fib levels on the chart next to the percentage?
 
TMpg8o6.png

Basically a scan like this. Something that could show stocks approaching the pocket from above. Then I can set alerts for when it is closer for a possible bounce
 
@ChadAnt here is the Study for AutoFib, But I guess you may have this already.

https://usethinkscript.com/threads/auto-fib-fibonacci-levels-indicator-for-thinkorswim.14/

Here is the 5 line code you are looking for as an addition to this study, all you have to do is scan for that gpArrow from this script on Weekly charts.

Ruby:
def gpH = value4 + (value4 * .05);
def gPL = value4 + (value4 * .01);
def gp = if price > gpL and price < gPH then 1 else Double.NaN;

plot gpArrow = if gp then low else Double.NaN;
gpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
 
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
Hi, Thanks much for helping community. Is there any possibility to provide Fibonacci extensions script.
 
The code that @BLT provided is very customizable. You can either change the fib levels via the user interface for any of the following standard definitions

Code:
input fib1level           = .236;
input fib2level           = .382;
input fibMlevel           = .500;
input fib3level           = .618;
input fib4level           = .764;
input fib5level           = 1.618;
input fib6level           = 2.618;
input fib7level           = -.618;
input fib8level           = -1.618;

Or, you can define more fib levels and add more plot lines. Either approach should be fine
Is it possible to provide full line code for 1.618 extension.
 
When I import this script I see the 0% in the top and 100% at the bottom. How do I correct this?
yep, 0% in the top and 100% at the bottom do appear. Right where they belong. It is a function of the script.

If you want to continue this discussion:
In order to troubleshoot the issues. We need to be able to see what you are seeing. So we need you to post the following:
  1. What code did you copy&paste? Even if you think it is the same as the one on the forum. We need to see yours. Maybe the issue is that you missed part of the code when you created the study. Copy&Paste YOUR code here.
  2. Provide a screen grab of the wonky results. Make sure to grab the whole chart so we can see the aggregations, what stock, and all your settings so we can try to replicate your results and correct them.
After you post the above information, I am sure someone will be able to point you toward possible solutions.
Unsure of how to upload screenshots to the forum, Here are directions.
 
Good morning, new to the scene here. I love this auto fib, however the % bubbles are allows covering the last few candles on all charts. Is there a way to move them out of the way? Not able to attach screenshot, only asked for http//: Thank you in advance for your help.
Dan

Is there a more recent version?


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
 
@zeek per your request, I modified the time range method so that timerange_begin/timerange_end inputs would allow for post close of prior day, current day premarket, and custom user time ranges, with the Fibonacci lines drawn across the entire chart.

Code:
#FibChoices v1
#Request usethinkscript.com @theelderwand to duplicate a swimdicators video's chart's indicator
#BLT 20191224

#v1 20191228 per request @zeek, changed time range method so that timerange_begin/timerange_end inputs would allow for post close of prior day, current day premarket, and custom user time ranges, with the Fibonacci lines drawn across the entire chart.


input method = {default aggregation, developing_reg_thrs, developing_ext_thrs, time_range};

input aggregation              = AggregationPeriod.DAY;
input aggregation_periodsback  = 0;

input timerange_begin  = 0000;
input timerange_end    = 0929;
# Examples: pre-market setting: 0000,0929; previous close through pre-market: 1600,0929;
# intraday opening range: 0930,1030

input display_upper_extended_fibs = no;
input display_lower_extended_fibs = no;

input fib1 = .236;
input fib2 = .382;
input fib3 = .500;
input fib4 = .618;
input fib5 = .764;

input showchart_bubbles = yes;
input bubble_option     = {default fiblevel, pricelevel};
input bubblemover       = 1; #used to move the bubble left and right

def bn = BarNumber();
#Time Range - Determines High/Low Where TimeRange_Begin Times are Between 1600 and 2359 Following the Prior Day's Close
def globexOpen   = if (if GetDayOfWeek(GetYYYYMMDD()) == 1 then SecondsFromTime(timerange_begin) >= 0 else SecondsFromTime(timerange_begin) >= 0) or SecondsFromTime(timerange_end) < 0 then 1 else 0;
def globexReset  = if globexOpen and !globexOpen[1] then 1 else 0;
def globexHigh   = CompoundValue(1, If((high > globexHigh[1] and globexOpen) or globexReset, high, globexHigh[1]), high);
def globexLow    = CompoundValue(1, If((low < globexLow[1] and globexOpen) or globexReset, low, globexLow[1]), low);
def globexhighbn = if high == (globexHigh) then bn else globexhighbn[1];
def globexlowbn  = if low == (globexLow) then bn else globexlowbn[1];

#Time Range - Determines High/Low with TimeRange_Begin Times From 0000 for PreMarket, Current Day or Intraday Pereiods
def day     = GetDay() == GetLastDay();
def lastday = if day and SecondsFromTime(timerange_begin) >= 0 then bn else Double.NaN;
def hhamt   = if day and bn == LowestAll(lastday) then high else if SecondsFromTime(timerange_end) <= 0 then Max(high, hhamt[1]) else hhamt[1];
def hhbn    = if high == (hhamt) then bn else hhbn[1];
def llamt   = if day and bn == LowestAll(lastday)  then low else if SecondsFromTime(timerange_end) <= 0 then Min(low, llamt[1]) else llamt[1];
def llbn    = if low == (llamt) then bn else llbn[1];

#Fibonacci High/Lows Determined based upon input method selected
def hh;
def ll;

switch (method){
#
case aggregation:
    hh = high(period = aggregation)[aggregation_periodsback];
    ll = low(period = aggregation)[aggregation_periodsback];
#
case developing_reg_thrs:
    hh = if GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then high else if GetTime() > RegularTradingStart(GetYYYYMMDD()) and high > hh[1] then high else hh[1];
    ll = if GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then low else if GetTime() > RegularTradingStart(GetYYYYMMDD()) and low < ll[1] then low else ll[1];
#
case developing_ext_thrs:
    hh = if GetTime() crosses above RegularTradingEnd(GetYYYYMMDD()) then high else if high > hh[1] then high else hh[1];
    ll = if GetTime() crosses above RegularTradingEnd(GetYYYYMMDD()) then low else if low < ll[1] then low else ll[1];
#
case time_range:
#Lines will display across the entire chart
    hh = if Between(timerange_begin, 1600, 2359) then HighestAll(if BarNumber() == HighestAll(globexhighbn) then globexHigh else Double.NaN) else HighestAll(if bn == HighestAll(hhbn) then (hhamt) else Double.NaN);
    ll = if Between(timerange_begin, 1600, 2359) then LowestAll(if BarNumber() == HighestAll(globexlowbn) then globexLow else Double.NaN) else LowestAll(if bn == HighestAll(llbn) then llamt else Double.NaN);

}

#Fibonacci Line Plots
def range  = hh - ll;
def f1   = ll + range * fib1;
def f2   = ll + range * fib2;
def f3   = ll + range * fib3;
def f4   = ll + range * fib4;
def f5   = ll + range * fib5;
def hh1  = hh;
def ll1  = ll;
def ff1  = f1;
def ff2  = f2;
def ff3  = f3;
def ff4  = f4;
def ff5  = f5;

input fib_line_choice = {default horizontal, points, dashes};
def paintingStrategy = if fib_line_choice == fib_line_choice.horizontal then PaintingStrategy.HORIZONTAL else if fib_line_choice == fib_line_choice.points then PaintingStrategy.POINTS else PaintingStrategy.DASHES;

plot hhp = hh1;
hhp.SetPaintingStrategy(paintingStrategy);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(1);

plot llp =  ll1;
llp.SetPaintingStrategy(paintingStrategy);
llp.SetDefaultColor(Color.RED);
llp.SetLineWeight(1);

plot f1p =  ff1;
f1p.SetPaintingStrategy(paintingStrategy);
f1p.SetDefaultColor(Color.YELLOW);
f1p.SetLineWeight(1);

plot f2p =  ff2;
f2p.SetPaintingStrategy(paintingStrategy);
f2p.SetDefaultColor(Color.YELLOW);
f2p.SetLineWeight(1);

plot f3p =  ff3;
f3p.SetPaintingStrategy(paintingStrategy);
f3p.SetDefaultColor(Color.WHITE);
f3p.SetLineWeight(1);

plot f4p = ff4;
f4p.SetPaintingStrategy(paintingStrategy);
f4p.SetDefaultColor(Color.YELLOW);
f4p.SetLineWeight(1);

plot f5p =  ff5;
f5p.SetPaintingStrategy(paintingStrategy);
f5p.SetDefaultColor(Color.YELLOW);
f5p.SetLineWeight(1);

#Fibonacci - Upper Extended Fib Lines
plot uhhp = if display_upper_extended_fibs == no then Double.NaN else range + hh1;
uhhp.SetPaintingStrategy(paintingStrategy);
uhhp.SetDefaultColor(Color.GREEN);
uhhp.SetLineWeight(1);

plot uf1p = if  display_upper_extended_fibs == no then Double.NaN else range + ff1;
uf1p.SetPaintingStrategy(paintingStrategy);
uf1p.SetDefaultColor(Color.YELLOW);
uf1p.SetLineWeight(1);

plot uf2p = if  display_upper_extended_fibs == no then Double.NaN else range + ff2;
uf2p.SetPaintingStrategy(paintingStrategy);
uf2p.SetDefaultColor(Color.YELLOW);
uf2p.SetLineWeight(1);

plot uf3p = if  display_upper_extended_fibs == no then Double.NaN else range + ff3;
uf3p.SetPaintingStrategy(paintingStrategy);
uf3p.SetDefaultColor(Color.WHITE);
uf3p.SetLineWeight(1);

plot uf4p = if  display_upper_extended_fibs == no then Double.NaN else range + ff4;
uf4p.SetPaintingStrategy(paintingStrategy);
uf4p.SetDefaultColor(Color.YELLOW);
uf4p.SetLineWeight(1);

plot uf5p = if  display_upper_extended_fibs == no then Double.NaN else range + ff5;
uf5p.SetPaintingStrategy(paintingStrategy);
uf5p.SetDefaultColor(Color.YELLOW);
uf5p.SetLineWeight(1);

#Fibonacci - Lower Extended Fib Lines
plot Lllp = if  display_lower_extended_fibs == no then Double.NaN else ll - range;
Lllp.SetPaintingStrategy(paintingStrategy);
Lllp.SetDefaultColor(Color.RED);
Lllp.SetLineWeight(1);

plot Lf1p = if  display_lower_extended_fibs == no then Double.NaN else ll - range * fib1;
Lf1p.SetPaintingStrategy(paintingStrategy);
Lf1p.SetDefaultColor(Color.YELLOW);
Lf1p.SetLineWeight(1);

plot Lf2p = if display_lower_extended_fibs == no then Double.NaN else ll - range * fib2;
Lf2p.SetPaintingStrategy(paintingStrategy);
Lf2p.SetDefaultColor(Color.YELLOW);
Lf2p.SetLineWeight(1);

plot Lf3p = if display_lower_extended_fibs == no then Double.NaN else ll - range * fib3;
Lf3p.SetPaintingStrategy(paintingStrategy);
Lf3p.SetDefaultColor(Color.WHITE);
Lf3p.SetLineWeight(1);

plot Lf4p = if  display_lower_extended_fibs == no then Double.NaN else ll - range * fib4;
Lf4p.SetPaintingStrategy(paintingStrategy);
Lf4p.SetDefaultColor(Color.YELLOW);
Lf4p.SetLineWeight(1);

plot Lf5p = if display_lower_extended_fibs == no then Double.NaN else ll - range * fib5;
Lf5p.SetPaintingStrategy(paintingStrategy);
Lf5p.SetDefaultColor(Color.YELLOW);
Lf5p.SetLineWeight(1);

#Bubbles Displaying Fib Levels in Right Expansion
def n   = bubblemover;
def n1  = n + 1;
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), hhp[n1], 1, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff1[n1], fib1, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff2[n1], fib2, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff3[n1], fib3, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff4[n1], fib4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff5[n1], fib5, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), llp[n1], 0, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf1p[n1], 1 + fib1, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf2p[n1], 1 + fib2, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf3p[n1], 1 + fib3, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf4p[n1], 1 + fib4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf5p[n1], 1 + fib5, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf1p[n1], -fib1, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf2p[n1], -fib2, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf3p[n1], -fib3 , Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf4p[n1], -fib4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf5p[n1], -fib5, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uhhp[n1], 2, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lllp[n1], -1, Color.GRAY, yes);

#Hiding Fib Line Price Levels Usually Displayed on Right Price Axis
hhp.HideBubble();
llp.HideBubble();
uhhp.HideBubble();
Lllp.HideBubble();
f1p.HideBubble();
f2p.HideBubble();
f3p.HideBubble();
f4p.HideBubble();
f5p.HideBubble();
Lf1p.HideBubble();
Lf2p.HideBubble();
Lf3p.HideBubble();
Lf4p.HideBubble();
Lf5p.HideBubble();
uf1p.HideBubble();
uf2p.HideBubble();
uf3p.HideBubble();
uf4p.HideBubble();
uf5p.HideBubble();
Can you add $ on the left and % on the right?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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