Auto Fib (Fibonacci) Extensions Indicator for ThinkorSwim

tomsk

Well-known member
VIP
Fibonacci Extension study version 1.1
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 by a moderator:
Hi Team,
I have code Fibonacci retracement but looking if we have any code for extension for possible stock up.
 
Hi Team,
I have code Fibonacci retracement but looking if we have any code for extension for possible stock up.

Here is a zigzag script that I did year's ago that included fib extensions. You have many options in the script, including how many fib extensions to show. As the zigzag does repaint, this script currently is set to show the last 2 extensions. The picture includes an overlay of the TOS built-in fib extension tool shown with the values on the left of the last extension to confirm those drawn by the script shown on the right side bubbles.

Screenshot-2021-08-07-124113.png

Ruby:
## AO_SupplyDemandCompositeVer2_2
## START CODE
## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from
## Thinkorswim ZigZagSign Script
##8.24.13 Mod by Lar to add Supply/Demand Levels (Red Zones are Supply, Green are Demand), ability to enter percentage, amount or atr for reversalAmount (using the greater of the three at any reversal)
##2.20.14 Mod by Linus to hide non-active Supply/Demand Levels.
##2.20.14 Mods by Linus to remove everything but Supply/Demand levels and arrows.
##3.04.14 Mods by Linus to change Supply/Demand levels to start at arrows. (Ver2.1)
##3.12.14 Mods by Linus to fix first Supply/Demand levels to not start at Zero. (Ver2.2)
##6.4.14 Mods by Lar using some of Linus changes to allow showing just today's fibs and to show only a user selectable number of fib extension changes within the chart, along with their applicable bubbles (and b = number of spaces to move bubbles in expansion)

def   price               = close;
def   priceH              = high;    # swing high
def   priceL              = low;     # swing low
input ATRreversalfactor   = 3.0;#Hint ATRreversalfactor: 3 is standard, adjust to whatever instrument/timeframe you are trading.
input ATRlength           = 5;#Hint ATRlength: 5 is standard, adjust to whatever instrument/timeframe you are trading
input zigzagpercent       = 3.0;#LAR original is 0.2, but modified in testing for 4h charting (may modify further later)
input zigzagamount        = .15;
def ATR                   = reference ATR(length = ATRlength);
def reversalAmount        = if (close * zigzagpercent / 100) > Max
(zigzagamount < ATRreversalfactor * ATR, zigzagamount) then
(close * zigzagpercent / 100) else if zigzagamount < ATRreversalfactor * ATR then
ATRreversalfactor * ATR else zigzagamount;
input showSupplyDemand    = {Off, default Arrow, Pivot};
input showArrows          = no; #orignal by LAR was no
input useAlerts           = no; #orignal by LAR was no
 
#Original TOS ZigZag code Modified by Linus
def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {
    minMaxPrice = price;
    state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.undefined;
        minMaxPrice = GetValue(minMaxPrice, 1);
    }
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else {
        state = state.uptrend;
        minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
    }
} else {
    if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.downtrend;
        minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
    }
}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth =  barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
    if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
        tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with
lastPeriodBarAcc = 1
            while lastPeriodBarAcc > 0
            do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
                then -lastPeriodBarAcc
                else lastPeriodBarAcc + 1;
    } else {
        tmpLastPeriodBar = 0;
    }
} else {
    tmpLastPeriodBar = Double.NaN;
}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue
(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
    currentPriceLevel =
        fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc
= minMaxPrice
            do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice,
barWithMaxOnPeriodI));
    currentPoints =
        fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc =
Double.NaN
            while IsNaN(maxPointOnPeriodAcc)
            do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
                then maxPointOnPeriodI
                else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
    currentPriceLevel =
        fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc
= minMaxPrice
            do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice,
barWithMinOnPeriodI));
    currentPoints =
        fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc =
Double.NaN
            while IsNaN(minPointOnPeriodAcc)
            do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
                then minPointOnPeriodI
                else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state ==
state.downtrend)) {
    currentPriceLevel = GetValue(currentPriceLevel, 1);
    currentPoints = GetValue(currentPoints, 1) + 1;
} else {
    currentPoints = 1;
    currentPriceLevel = GetValue(price, currentPoints);
}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state ==
state.uptrend then priceH else priceL else if (currentPoints == 0) then
currentPriceLevel else Double.NaN;

rec zzSave =  if !IsNaN("ZZ$") then if (barNumber == barCount or barNumber == 1)
then if IsNaN(barNumber[-1]) and  state == state.uptrend then priceH else priceL
else currentPriceLevel else GetValue(zzSave, 1);

def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if
barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel)
- GetValue(zzSave, 1);

def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and
GetValue(isConf, 1));

"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.GREEN);
"ZZ$".DefineColor("Down Trend", Color.RED);
"ZZ$".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined") else if isUp
then "ZZ$".Color("Up Trend") else "ZZ$".Color("Down Trend"));
"ZZ$".SetLineWeight(2);
DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);

#Showlabel for Confirmed/Unconfirmed Status of Current Zigzag
AddLabel(barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
 
#Arrows

def zzL = if !IsNaN("ZZ$") and state == state.downtrend then priceL else
GetValue(zzL, 1);

def zzH = if !IsNaN("ZZ$") and state == state.uptrend then priceH else GetValue
(zzH, 1);

def dir = CompoundValue(1, if zzL != zzL[1] then 1 else if zzH != zzH[1] then -1
else dir[1], 0);

def signal = CompoundValue(1,
    if dir > 0 and low > zzL then
        if signal[1] <= 0 then 1 else signal[1]
    else if dir < 0 and high < zzH then
        if signal[1] >= 0 then -1 else signal[1]
    else signal[1]
, 0);

plot U1 = showArrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);

plot D1 = showArrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);

Alert(useAlerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(useAlerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);

#Supply Demand Areas
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;

if BarNumber() == 1 {
    rLow = Double.NaN;
    rHigh = Double.NaN;
} else if signal crosses 0 {
    rLow = low[idx];
    rHigh = high[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}

plot HighLine = if showSupplyDemand and !IsNaN(close) then rHigh else
Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);
HighLine.HideBubble();

plot LowLine = if showSupplyDemand and !IsNaN(close) then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);
LowLine.HideBubble();

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

AddCloud(hlUp, LowLine, Color.GREEN, Color.GREEN);
AddCloud(hlDn, LowLine, Color.RED, Color.RED);

#Store Previous Data
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
rec priorzz1 = if zzsave2  != zzsave2[1]  then zzsave2[1]  else priorzz1[1];
rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];
rec priorzz4 = if priorzz3 != priorzz3[1] then priorzz3[1] else priorzz4[1];
rec priorzz5 = if priorzz4 != priorzz4[1] then priorzz4[1] else priorzz5[1];
rec priorzz6 = if priorzz5 != priorzz5[1] then priorzz5[1] else priorzz6[1];

rec data = CompoundValue(1, if (zzSave == priceH or zzSave == priceL) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
input numberextfibstoshow = 2;
input showFibExtLines = yes;
input showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) * 1
else extfib1[1];
plot extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib1) and dir < 0 then extfib1[1] else Double.NaN;
extfib100.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100.SetDefaultColor(Color.RED);
extfib100.SetLineWeight(1);
extfib100.HideBubble();
def extfib2 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2[1];
plot extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib2) and dir < 0 then extfib2[1] else Double.NaN;
extfib618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618.SetDefaultColor(Color.RED);
extfib618.SetLineWeight(1);
extfib618.HideBubble();
def extfib3 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3[1];
plot extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib3) and dir < 0 then extfib3[1] else Double.NaN;
extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618.SetDefaultColor(Color.RED);
extfib1618.SetLineWeight(1);
extfib1618.HideBubble();
def extfib4 = if zzSave == priceH then high - AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4[1];
plot extfib2618 = if  datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib4) and dir < 0 then extfib4[1] else Double.NaN;
extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618.SetDefaultColor(Color.RED);
extfib2618.SetLineWeight(1);
extfib2618.HideBubble();
def extfib1_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) * 1
else extfib1_[1];
plot extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib1_) and dir > 0 then extfib1_[1] else Double.NaN;
extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100_.SetDefaultColor(Color.GREEN);
extfib100_.SetLineWeight(1);
extfib100_.HideBubble();
def extfib2_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2_[1];
plot extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib2_) and dir > 0 then extfib2_[1] else Double.NaN;
extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618_.SetDefaultColor(Color.GREEN);
extfib618_.SetLineWeight(1);
extfib618_.HideBubble();
def extfib3_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3_[1];
plot extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib3_) and dir > 0 then extfib3_[1] else Double.NaN;
extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618_.SetDefaultColor(Color.GREEN);
extfib1618_.SetLineWeight(1);
extfib1618_.HideBubble();
def extfib4_ = if zzSave == priceL then low + AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4_[1];
plot extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and currentPoints != 0 and !IsNaN(extfib4_) and dir > 0 then extfib4_[1]  else Double.NaN;
extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618_.SetDefaultColor(Color.GREEN);
extfib2618_.SetLineWeight(1);
extfib2618_.HideBubble();
input b = 2;
def direction = if !isUp then 1 else 0;

AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1[b + 2], "100%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2[b + 2], "61.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3[b + 2], "161.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4[b + 2], "261.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1_[b + 2], "100%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2_[b + 2], "61.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3_[b + 2], "161.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4_[b + 2], "261.8%", Color.GREEN, yes);
 
@SleepyZ Getting this error while trying to save it as a Study? "rec data = CompoundValue(.... Identifier Already used: data at 232.5. Already assigned: data at 232.5
 
@SleepyZ I just imported the indicator. So, for ROKU it is showing as Confirmed Zigzag -36.79 on the Weekly chart. Does this indicate that the price of ROKU can drop -36.79 in a Weekly timeframe? Am I reading this correctly?
 
@SleepyZ I just imported the indicator. So, for ROKU it is showing as Confirmed Zigzag -36.79 on the Weekly chart. Does this indicate that the price of ROKU can drop -36.79 in a Weekly timeframe? Am I reading this correctly?
It shows that the current 'red' zigzag has fallen by $36.79 and at that time that confirmed the zigzag. However, since the zigzag is a 'repainting' indicator, it can change direction, in this case back up before a new zigzag is formed and the current one could become unconfirmed. You have to be very careful using a zigzag. I use them mainly for support/resistance.

The next fib of importance shown is the -61.8% level and a possible target.
 
Here is a zigzag script that I did year's ago that included fib extensions. You have many options in the script, including how many fib extensions to show. As the zigzag does repaint, this script currently is set to show the last 2 extensions. The picture includes an overlay of the TOS built-in fib extension tool shown with the values on the left of the last extension to confirm those drawn by the script shown on the right side bubbles.
Thanks Sleepyz, What does Label "unconfirmed zigzag: 0.11" means, thanks,
 
My apologies if this is a simple question, I for the life at the moment cannot figure out what I am doing wrong. In the image linked, I removed the plots for everything except fib extension but the same happens in the original script.
The extensions (in green dash) start up from the orange arrow.

I want them to start at the purple arrow and then they would draw roughly where the lines are. I am not looking for adjust the color or the dash. I am looking to adjust the starting point to use the extensions to plot upward from the highest value on chart.


Thank you for any help or suggestions
 
My apologies if this is a simple question, I for the life at the moment cannot figure out what I am doing wrong. In the image linked, I removed the plots for everything except fib extension but the same happens in the original script.
The extensions (in green dash) start up from the orange arrow.

I want them to start at the purple arrow and then they would draw roughly where the lines are. I am not looking for adjust the color or the dash. I am looking to adjust the starting point to use the extensions to plot upward from the highest value on chart.


Thank you for any help or suggestions
 
My apologies if this is a simple question, I for the life at the moment cannot figure out what I am doing wrong. In the image linked, I removed the plots for everything except fib extension but the same happens in the original script.
The extensions (in green dash) start up from the orange arrow.

I want them to start at the purple arrow and then they would draw roughly where the lines are. I am not looking for adjust the color or the dash. I am looking to adjust the starting point to use the extensions to plot upward from the highest value on chart.


Thank you for any help or suggestions
Unfortunately, this is all that is available at this time :(
 
Fibonacci Extension study version 1.1
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
Hi, I want to see if someone has an auto fib just like this one but I only need it to show the 50% and 61.8%, or if someone can adjust this one. unfortunately, I know very little about how to adjust and or use thinkscripts
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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