Auto Fib (Fibonacci) Levels Indicator for ThinkorSwim

C

Coop

New member
I saw a post on the usethinkscript Universe showing Fib time series, can anyone show me how to code these in different series like Lucas, or Mersenne?
 
theelderwand

theelderwand

Member
2019 Donor
VIP
@zeek FWIW i have tried scripting it but never ended up getting anywhere. So i use Auto Fib on longer timeframe and manually drawn ones for shorter term ones and trade them.
If you are interested join the Discord server. I share my charts, studies and trades.
 
zeek

zeek

Active member
2019 Donor
Ok, thanks for trying @theelderwand I did find a paid script that does exactly what i am looking for and you can see a demo in this video of the extension levels @7:45

If anyone happens to have this script and would be willing to share it here, would be much appreciated.
 
theelderwand

theelderwand

Member
2019 Donor
VIP
@zeek My 2c. I don't think it's worth it. I believe knowledge should be free. This guy is trying to make money off of something that isn't really worth anything.
 
zeek

zeek

Active member
2019 Donor
@zeek My 2c. I don't think it's worth it. I believe knowledge should be free. This guy is trying to make money off of something that isn't really worth anything.
I agree, not worth the cost he wants for it. Hopefully someone smart here can figure out how to add the extensions to our script here.
 
B

BLT

Member
@zeek, See if this modification of one of my scripts helps. I did not include the alerts.


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


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

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

input timerange_begin  = 0930;
input timerange_end    = 1030;

input display_upper_extended_fibs = no;
input display_lower_extended_fibs = no;

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:
    hh = if SecondsFromTime(timerange_begin) < 0 then Double.NaN else if SecondsFromTime(timerange_begin) == 0 then high else if SecondsFromTime(timerange_end) <= 0 and high > hh[1] then high else hh[1];
    ll = if SecondsFromTime(timerange_begin) < 0 then Double.NaN else if SecondsFromTime(timerange_begin) == 0 then low else if SecondsFromTime(timerange_end) <= 0 and low < ll[1] then low else ll[1];

}


def range  = hh - ll;
input fib1 = .236;
input fib2 = .382;
input fib3 = .500;
input fib4 = .618;
input fib5 = .764;
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  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then hh1[1] else hh;
def ll1  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then ll1[1] else ll;
def ff1  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then ff1[1]  else f1;
def ff2  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then ff2[1]  else f2;
def ff3  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then ff3[1]  else f3;
def ff4  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then ff4[1]  else f4;
def ff5  = if aggregation_displayed_in_expansion and IsNaN(close(period = aggregation)) then ff5[1]  else 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 = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else hh1;
hhp.SetPaintingStrategy(paintingStrategy);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(1);

plot llp = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else ll1;
llp.SetPaintingStrategy(paintingStrategy);
llp.SetDefaultColor(Color.RED);
llp.SetLineWeight(1);

plot f1p = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else ff1;
f1p.SetPaintingStrategy(paintingStrategy);
f1p.SetDefaultColor(Color.YELLOW);
f1p.SetLineWeight(1);

plot f2p = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else ff2;
f2p.SetPaintingStrategy(paintingStrategy);
f2p.SetDefaultColor(Color.YELLOW);
f2p.SetLineWeight(1);

plot f3p = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else ff3;
f3p.SetPaintingStrategy(paintingStrategy);
f3p.SetDefaultColor(Color.WHITE);
f3p.SetLineWeight(1);

plot f4p = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else ff4;
f4p.SetPaintingStrategy(paintingStrategy);
f4p.SetDefaultColor(Color.YELLOW);
f4p.SetLineWeight(1);

plot f5p = if aggregation_displayed_in_expansion and !IsNaN(close) then Double.NaN else ff5;
f5p.SetPaintingStrategy(paintingStrategy);
f5p.SetDefaultColor(Color.YELLOW);
f5p.SetLineWeight(1);

plot uhhp = if aggregation_displayed_in_expansion and !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + hh1;
uhhp.SetPaintingStrategy(paintingStrategy);
uhhp.SetDefaultColor(Color.GREEN);
uhhp.SetLineWeight(1);

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

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

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

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

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

plot Lllp = if aggregation_displayed_in_expansion and !IsNaN(close) or display_lower_extended_fibs
== no then Double.NaN else ll - range;
Lllp.SetPaintingStrategy(paintingStrategy);
Lllp.SetDefaultColor(Color.RED);
Lllp.SetLineWeight(1);

plot Lf1p = if aggregation_displayed_in_expansion and !IsNaN(close) or 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 aggregation_displayed_in_expansion and !IsNaN(close) or 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 aggregation_displayed_in_expansion and !IsNaN(close) or 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 aggregation_displayed_in_expansion and !IsNaN(close) or 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 aggregation_displayed_in_expansion and !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib5;
Lf5p.SetPaintingStrategy(paintingStrategy);
Lf5p.SetDefaultColor(Color.YELLOW);
Lf5p.SetLineWeight(1);

input showchart_bubbles = yes;
input bubble_option     = {default fiblevel, pricelevel};
input bubblemover       = 5; #used to move the bubble left and right
def n   = bubblemover;
def n1  = n + 1;
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), hhp[n1], if bubble_option == bubble_option.fiblevel then 1 else Round(hhp[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff1[n1], if bubble_option == bubble_option.fiblevel then fib1 else Round(f1p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff2[n1], if bubble_option == bubble_option.fiblevel then fib2 else Round(f2p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff3[n1], if bubble_option == bubble_option.fiblevel then fib3 else Round(f3p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff4[n1], if bubble_option == bubble_option.fiblevel then fib4 else Round(f4p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff5[n1], if bubble_option == bubble_option.fiblevel then fib5 else Round(f5p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), llp[n1], if bubble_option == bubble_option.fiblevel then 0 else Round(llp[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf1p[n1], if bubble_option == bubble_option.fiblevel then 1+fib1 else Round(uf1p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf2p[n1], if bubble_option == bubble_option.fiblevel then 1+fib2 else Round(uf2p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf3p[n1], if bubble_option == bubble_option.fiblevel then 1+fib3 else Round(uf3p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf4p[n1], if bubble_option == bubble_option.fiblevel then 1+fib4 else Round(f4p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf5p[n1], if bubble_option == bubble_option.fiblevel then 1+fib5 else Round(uf5p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf1p[n1], if bubble_option == bubble_option.fiblevel then -fib1 else Round(Lf1p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf2p[n1], if bubble_option == bubble_option.fiblevel then -fib2 else Round(LF2p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf3p[n1], if bubble_option == bubble_option.fiblevel then -fib3 else Round(Lf3p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf4p[n1], if bubble_option == bubble_option.fiblevel then -fib4 else Round(Lf4p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf5p[n1], if bubble_option == bubble_option.fiblevel then -fib5 else Round(Lf5p[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uhhp[n1], if bubble_option == bubble_option.fiblevel then 2 else Round(uhhp[n1] * 4, 0) / 4, Color.GRAY, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lllp[n1], if bubble_option == bubble_option.fiblevel then -1 else Round(Lllp[n1] * 4, 0) / 4, Color.GRAY, yes);

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

tomsk

Well-known member
VIP
Made some modifications to BLT's Fib Choices code to suit my needs, sectionalized the code for easier future code maintenance, marked the High/Low from which calculations were made, and color coded upper/lower extensions for easier visualization. Kudos for some really great ideas there @BLT Anyone that uses this code, just remember that this is designed for an intraday chart

Code:
# Fib Choices V1.1
# BLT, with modifications by tomsk
# 12.25.2019

# V1.0 - 12.24.2019 - BLT   - Initial release of Fib Choices
# V1.1 - 12.25.2019 - tomsk - Marked High/Low, color coded Fib upper/lower extensions

declare hide_on_daily;

input aggregation = AggregationPeriod.DAY;
input display_upper_extended_fibs = yes;
input display_lower_extended_fibs = yes;

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

def hh = high(period = aggregation);
def ll = low(period = aggregation);
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  = if !IsNaN(close(period = aggregation)) then hh else hh1[1];
def ff1  = if !IsNaN(close(period = aggregation)) then f1 else ff1[1];
def ff2  = if !IsNaN(close(period = aggregation)) then f2 else ff2[1];
def ff3  = if !IsNaN(close(period = aggregation)) then f3 else ff3[1];
def ff4  = if !IsNaN(close(period = aggregation)) then f4 else ff4[1];
def ff5  = if !IsNaN(close(period = aggregation)) then f5 else ff5[1];
def ll1  = if !IsNaN(close(period = aggregation)) then ll else ll1[1];

# REGULAR FIBONACCI RETRACEMENT LEVELS

plot hhp = if !IsNaN(close) then Double.NaN else hh1;
hhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(4);

plot f1p = if !IsNaN(close) then Double.NaN else ff1;
f1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f1p.SetDefaultColor(Color.YELLOW);
f1p.SetLineWeight(1);

plot f2p = if !IsNaN(close) then Double.NaN else ff2;
f2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f2p.SetDefaultColor(Color.YELLOW);
f2p.SetLineWeight(1);

plot f3p = if !IsNaN(close) then Double.NaN else ff3;
f3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f3p.SetDefaultColor(Color.WHITE);
f3p.SetLineWeight(1);

plot f4p = if !IsNaN(close) then Double.NaN else ff4;
f4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f4p.SetDefaultColor(Color.YELLOW);
f4p.SetLineWeight(1);

plot f5p = if !IsNaN(close) then Double.NaN else ff5;
f5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f5p.SetDefaultColor(Color.YELLOW);
f5p.SetLineWeight(1);

plot llp = if !IsNaN(close) then Double.NaN else ll1;
llp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llp.SetDefaultColor(Color.RED);
llp.SetLineWeight(4);

# UPPER FIBONACCI EXTENSION LEVELS

plot uhhp = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + hh1;
uhhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uhhp.SetDefaultColor(Color.GREEN);
uhhp.SetLineWeight(1);

plot uf1p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff1;
uf1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf1p.SetDefaultColor(Color.YELLOW);
uf1p.SetLineWeight(1);

plot uf2p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff2;
uf2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf2p.SetDefaultColor(Color.YELLOW);
uf2p.SetLineWeight(1);

plot uf3p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff3;
uf3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf3p.SetDefaultColor(Color.WHITE);
uf3p.SetLineWeight(1);

plot uf4p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff4;
uf4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf4p.SetDefaultColor(Color.YELLOW);
uf4p.SetLineWeight(1);

plot uf5p = if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff5;
uf5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf5p.SetDefaultColor(Color.YELLOW);
uf5p.SetLineWeight(1);

# LOWER FIBONACCI EXTENSION LEVELS

plot Lllp = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range;
Lllp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lllp.SetDefaultColor(Color.RED);
Lllp.SetLineWeight(1);

plot Lf1p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib1;
Lf1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf1p.SetDefaultColor(Color.YELLOW);
Lf1p.SetLineWeight(1);

plot Lf2p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib2;
Lf2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf2p.SetDefaultColor(Color.YELLOW);
Lf2p.SetLineWeight(1);

plot Lf3p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib3;
Lf3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf3p.SetDefaultColor(Color.WHITE);
Lf3p.SetLineWeight(1);

plot Lf4p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib4;
Lf4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf4p.SetDefaultColor(Color.YELLOW);
Lf4p.SetLineWeight(1);

plot Lf5p = if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib5;
Lf5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf5p.SetDefaultColor(Color.YELLOW);
Lf5p.SetLineWeight(1);

# CHART BUBBLES

input showchart_bubbles = yes;
input bubblemover       = 5; #used to move the bubble left and right
def n   = bubblemover;
def n1  = n + 1;

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), hhp[n], 1 + " = High", Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff1[n], fib1 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff2[n], fib2 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff3[n], fib3 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff4[n], fib4 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff5[n], fib5 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), llp[n], 0 + " = Low", Color.YELLOW, yes);

# EXTENSION ABOVE

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf1p[n], 1+fib1, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf2p[n], 1+fib2, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf3p[n], 1+fib3, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf4p[n], 1+fib4, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf5p[n], 1+fib5, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uhhp[n], 2     , Color.WHITE, yes);

# EXTENSION BELOW

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf1p[n], -fib1, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf2p[n], -fib2, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf3p[n], -fib3, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf4p[n], -fib4, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf5p[n], -fib5, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lllp[n], -1   , Color.PINK, yes);

# HIDE BUBBLE FLAG

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();
# End Fib Choices V1.1
 
Last edited:
H

HighBredCloud

Well-known member
VIP
@tomsk I can't seem to get your code to plot...any ideas?
 
T

tomsk

Well-known member
VIP
Load it on an intraday chart e.g. 15 mins. Make sure you have sufficient bars defined in your expansion area. If you do not do this, you won't see the data plots

Go to Settings > Time Axis > Expansion area
 
H

HighBredCloud

Well-known member
VIP
@tomsk is 10 enough? I had it set to 0...weird because I can see the code that BLT did...but I can't see your enhancements.
 
D

dreamb0x

New member
VIP
just curious if there's a possibility of a scanner when the candles hit the fibs line? like 75% an alert will be triggered?
 
T

tomsk

Well-known member
VIP
@dreamb0x Unfortunately, if you are referencing using the Fib Choices study to trigger an alert when price hits one of the retracement levels, you will not be able to do this as the TOS scanner cannot process secondary aggregations. This is because this study is written as an intraday aggregation e.g. 30 minutes while the daily high/low is captured using a daily aggregation.

For intraday retracements you might like to consider using something like Mobius RTH High/Low Fibonacci study.
 
zeek

zeek

Active member
2019 Donor
@tomsk Thanks for the updated version, i have 2 requests if you could possibly make these changes for me?

1. I prefer to have the Fib lines cross the whole chart instead of only showing in the expansion area, can this be changed?
2. In the BLT version posted above (and yours), when i select aggregation period Day, it calculates the low from regular hours (9:30) but i would prefer if it instead calculated the low from pre-market.
 
T

tomsk

Well-known member
VIP
@zeek Here is version V1.2 of the Fib Choices study, I have added an input selector plotAcrossChart that when set to yes, will plot the fib lines across the chart. By default this is set to no, which displays the fib lines at the expansion area.

The general design of this study by @BLT is to based the study on the RTH high/low, so I will respect his original design. I'll defer to him for any changes to other time brackets such as pre market

Code:
# Fib Choices V1.2
# BLT, with modifications by tomsk
# 12.27.2019

# V1.0 - 12.24.2019 - BLT   - Initial release of Fib Choices
# V1.1 - 12.25.2019 - tomsk - Marked High/Low, color coded Fib upper/lower extensions
# V1.2 - 12.27.2019 - tomsk - Added option to plot fib lines across entire chart

declare hide_on_daily;

input aggregation = AggregationPeriod.DAY;
input display_upper_extended_fibs = yes;
input display_lower_extended_fibs = yes;
input plotAcrossChart = no;

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

def hh = high(period = aggregation);
def ll = low(period = aggregation);
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  = if !IsNaN(close(period = aggregation)) then hh else hh1[1];
def ff1  = if !IsNaN(close(period = aggregation)) then f1 else ff1[1];
def ff2  = if !IsNaN(close(period = aggregation)) then f2 else ff2[1];
def ff3  = if !IsNaN(close(period = aggregation)) then f3 else ff3[1];
def ff4  = if !IsNaN(close(period = aggregation)) then f4 else ff4[1];
def ff5  = if !IsNaN(close(period = aggregation)) then f5 else ff5[1];
def ll1  = if !IsNaN(close(period = aggregation)) then ll else ll1[1];

# REGULAR FIBONACCI RETRACEMENT LEVELS

plot hhp = if plotAcrossChart then hh1 else if !IsNaN(close) then Double.NaN else hh1;
hhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(4);

plot f1p = if plotAcrossChart then ff1 else if !IsNaN(close) then Double.NaN else ff1;
f1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f1p.SetDefaultColor(Color.YELLOW);
f1p.SetLineWeight(1);

plot f2p = if plotAcrossChart then ff2 else if !IsNaN(close) then Double.NaN else ff2;
f2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f2p.SetDefaultColor(Color.YELLOW);
f2p.SetLineWeight(1);

plot f3p = if plotAcrossChart then ff3 else if !IsNaN(close) then Double.NaN else ff3;
f3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f3p.SetDefaultColor(Color.WHITE);
f3p.SetLineWeight(1);

plot f4p = if plotAcrossChart then ff4 else if !IsNaN(close) then Double.NaN else ff4;
f4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f4p.SetDefaultColor(Color.YELLOW);
f4p.SetLineWeight(1);

plot f5p = if plotAcrossChart then ff5 else if !IsNaN(close) then Double.NaN else ff5;
f5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
f5p.SetDefaultColor(Color.YELLOW);
f5p.SetLineWeight(1);

plot llp = if plotAcrossChart then ll1 else if !IsNaN(close) then Double.NaN else ll1;
llp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llp.SetDefaultColor(Color.RED);
llp.SetLineWeight(4);

# UPPER FIBONACCI EXTENSION LEVELS

plot uhhp = if plotAcrossChart and display_upper_extended_fibs then range + hh1 else if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + hh1;
uhhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uhhp.SetDefaultColor(Color.GREEN);
uhhp.SetLineWeight(1);

plot uf1p = if plotAcrossChart and display_upper_extended_fibs then range + ff1 else if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff1;
uf1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf1p.SetDefaultColor(Color.YELLOW);
uf1p.SetLineWeight(1);

plot uf2p = if plotAcrossChart and display_upper_extended_fibs then range + ff2 else if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff2;
uf2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf2p.SetDefaultColor(Color.YELLOW);
uf2p.SetLineWeight(1);

plot uf3p = if plotAcrossChart and display_upper_extended_fibs then range + ff3 else if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff3;
uf3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf3p.SetDefaultColor(Color.WHITE);
uf3p.SetLineWeight(1);

plot uf4p = if plotAcrossChart and display_upper_extended_fibs then range + ff4 else if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff4;
uf4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf4p.SetDefaultColor(Color.YELLOW);
uf4p.SetLineWeight(1);

plot uf5p = if plotAcrossChart and display_upper_extended_fibs then range + ff5 else if !IsNaN(close) or display_upper_extended_fibs == no then Double.NaN else range + ff5;
uf5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
uf5p.SetDefaultColor(Color.YELLOW);
uf5p.SetLineWeight(1);

# LOWER FIBONACCI EXTENSION LEVELS

plot Lllp = if plotAcrossChart and display_lower_extended_fibs then ll - range else if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range;
Lllp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lllp.SetDefaultColor(Color.RED);
Lllp.SetLineWeight(1);

plot Lf1p = if plotAcrossChart and display_lower_extended_fibs then ll - range * fib1 else if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib1;
Lf1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf1p.SetDefaultColor(Color.YELLOW);
Lf1p.SetLineWeight(1);

plot Lf2p = if plotAcrossChart and display_lower_extended_fibs then ll - range * fib2 else if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib2;
Lf2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf2p.SetDefaultColor(Color.YELLOW);
Lf2p.SetLineWeight(1);

plot Lf3p = if plotAcrossChart and display_lower_extended_fibs then ll - range * fib3 else if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib3;
Lf3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf3p.SetDefaultColor(Color.WHITE);
Lf3p.SetLineWeight(1);

plot Lf4p = if plotAcrossChart and display_lower_extended_fibs then ll - range * fib4 else if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib4;
Lf4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf4p.SetDefaultColor(Color.YELLOW);
Lf4p.SetLineWeight(1);

plot Lf5p = if plotAcrossChart and display_lower_extended_fibs then ll - range * fib5 else if !IsNaN(close) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib5;
Lf5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lf5p.SetDefaultColor(Color.YELLOW);
Lf5p.SetLineWeight(1);

# CHART BUBBLES

input showchart_bubbles = yes;
input bubblemover       = 5; #used to move the bubble left and right
def n   = bubblemover;
def n1  = n + 1;

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), hhp[n], 1 + " = High", Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff1[n], fib1 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff2[n], fib2 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff3[n], fib3 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff4[n], fib4 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ff5[n], fib5 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), llp[n], 0 + " = Low", Color.YELLOW, yes);

# EXTENSION ABOVE

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf1p[n], 1+fib1, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf2p[n], 1+fib2, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf3p[n], 1+fib3, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf4p[n], 1+fib4, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uf5p[n], 1+fib5, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), uhhp[n], 2     , Color.WHITE, yes);

# EXTENSION BELOW

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf1p[n], -fib1, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf2p[n], -fib2, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf3p[n], -fib3, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf4p[n], -fib4, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lf5p[n], -fib5, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), Lllp[n], -1   , Color.PINK, yes);

# HIDE BUBBLE FLAG

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();
# End Fib Choices V1.2
 
Last edited:
zeek

zeek

Active member
2019 Donor
But let`s say i wanted to change the aggregation period myself, is it only this line of code i need to modify?

input aggregation = AggregationPeriod.DAY;
I checked here in the TOS Learning Center but i can`t find any aggregation period that relates to extended hours? If anyone can point me to where i can find the appropriate period, would appreciate it. Thanks.
 
T

tomsk

Well-known member
VIP
The method that BLT determined the RTH high/low using AggregationPeriod.DAY is a fast way to obtain that data. Otherwise you'll have to mess around with time brackets using SecondsFromTime() and SecondsTillTime() all of which may seem cumbersome to the novice coder.
 
S

sobiswas

New member
VIP
Trying this indicator out. I am seeing two bubbles on the 50% retracement for 1D tsla chart. I just changed the color code for it to blue. Tried uploading the image says something went wrong, so here is the link to the screenshot.



Never mind, found the problem. Line 112 and 110 are same, removed the duplicate line.
 
Last edited by a moderator:
Top