Auto Fib (Fibonacci) Levels Indicator for ThinkorSwim

theelderwand

theelderwand

Member
2019 Donor
VIP
@sobiswas Are you looking at the 1.3 Version of the indicator ?? This is a very old version of the indicator looks like.
 
T

tomsk

Well-known member
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.

@theelderwand Indeed so, I looked deeper into this and even attempted to play around with the code base. In the end I concluded that Fibonacci extensions are best displayed on intraday aggregation charts rather than daily due to the fact that most retracement studies utilize Highestall high and Lowestall low as the basis for the fibs. It was a fun exercise in self discovery !
 
B

BLT

Member
@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();
 
N

Nikola

New member
any way to show the price on the right axis so i can see the price levels for these levels?
 
B

BLT

Member
@Nikola yes, just delete the last part of the script with HideBubble() code for each of the fib lines
 
markos

markos

Well-known member
VIP
@Nikola yes, just delete the last part of the script with HideBubble() code for each of the fib lines
@BLT We are so blessed to have you here at uTS. I'm an old fan of via StanL's writings.
Thank you!
 
N

Nikola

New member
@Nikola yes, just delete the last part of the script with HideBubble() code for each of the fib lines
i fixed it jhowever it only shows the bubbles when i hoover on it but then my curser block it. can i make it so the bubbles stay?
 
R

Rdg1515

New member
I saw the auto fib scripts on this site and its perfect but I can't figure out how to get the scanner to find stocks that have hit the 38 50 or 60 fib retracements.
 
T

tomsk

Well-known member
VIP
@Rdg1515 Since the market is currently in an uptrend, my assumption is that you'd like to scan for uptrend stocks that have retraced to either the 38.2%, 50%, or 61.8% levels. The way the code is written, it also has the capability to calculate retracement levels for downtrending stocks. That said, I have converted the code base you posted earlier to scan for uptrending stocks that have made a 38.2% retracement.

Code:
# Fibonacci Uptrend Retracement Scan
# tomsk
# 1.3.2020

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

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;

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;
def highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
def 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;

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;

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

plot scan = close crosses above retracement2 and upward;

# End Fibonacci Uptrend Retracement Scan

In the event you'd like to scan for deeper retracement levels,, all you got to do is to revise the following line to reflect the level you'd like to scan for. The 50% retracement level is held by the variable retracement3 while that for 61.8% is help by the variable retracement4. Scanning the S&P 500 at the 38.2% retracement level, these is currently only 1 result. At the 50%, there are 2 results.

Code:
plot scan = close crosses above retracement2 and upward;
 
R

Rdg1515

New member
Awesome!!!
Thanks for taking the time and helping me out, I really appreciate it @tomsk
 
R

Rdg1515

New member
@tomsk

If I change the plot scan to say
plot scan= close below retracement 2 and downward;

Will that scan for downtrending stocks that have hit the retracements for possible short position?
 
T

tomsk

Well-known member
VIP
@Rdg1515 Your statement as written has a syntax error, you're missing a key qualifier "crosses". Here is the corrected code adjustment you'll need.

Code:
plot scan = close crosses below retracement2 and downward;
With this modification, a scan of the S&P 500 returned 2 results at the current time - ALB and IVZ
 
Last edited:
C

Craighaber71

Active member
2019 Donor
VIP
Does anyone have an fibonacci extension study....Not fibonacci retracement...


Thanks
 
C

Craighaber71

Active member
2019 Donor
VIP
Has anyone seen a auto Fibonacci extensions study for swing low to swing high..Thanks
 
B

Buckbull

Member
@Rdg1515 Since the market is currently in an uptrend, my assumption is that you'd like to scan for uptrend stocks that have retraced to either the 38.2%, 50%, or 61.8% levels. The way the code is written, it also has the capability to calculate retracement levels for downtrending stocks. That said, I have converted the code base you posted earlier to scan for uptrending stocks that have made a 38.2% retracement.

Code:
# Fibonacci Uptrend Retracement Scan
# tomsk
# 1.3.2020

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

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;

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;
def highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
def 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;

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;

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

plot scan = close crosses above retracement2 and upward;

# End Fibonacci Uptrend Retracement Scan

In the event you'd like to scan for deeper retracement levels,, all you got to do is to revise the following line to reflect the level you'd like to scan for. The 50% retracement level is held by the variable retracement3 while that for 61.8% is help by the variable retracement4. Scanning the S&P 500 at the 38.2% retracement level, these is currently only 1 result. At the 50%, there are 2 results.

Code:
plot scan = close crosses above retracement2 and upward;
Tomsk is there a way to adjust this so it could pick the latest trend , was wondering how far back does this go to pick the 0% and the 100%
 
P

PSK

New member
VIP
Do we have similar auto fib placement indicator for fib extensions?
 
B

BLT

Member
Has anyone seen a auto Fibonacci extensions study for swing low to swing high..Thanks
Here is code for Swing High/Low with options to show all swings or last swing, fib levels, number of swings to display fib1 levels, and chart bubbles identifying swings and fib1 levels. The fib bubbles can moved left/right in the expansion by the number of bars at the input: bubble_mover
Code:
#SwingHL_Fibs
#01.19.2020 - BLT - Swing High/Low with options to show all swings or last swing, fib levels, number of swings to display fib1 levels, and chart bubbles identifying swings and fib1 levels. The fib bubbles can moved left/right in the expansion by the number of bars at the input: bubble_mover 

input showlastswing = yes;
input swing_back1 = 5;
input swing_forward1 = 5;
input maxbars1 = 30;

def na = Double.NaN;
def bn = barnumber();
def sb1 = swing_back1;
def sf1 = swing_forward1;
def lfor1 = Lowest(low, sf1)[-sf1];
def lback1 = Lowest(low, sb1)[1];
def swinglow1 = if low < lfor1 and low < lback1 then 1 else 0;
def swinglowbar = if low < lfor1 and low < lback1 then bn else na;
def hfor1  = Highest(high, sf1)[-sf1];
def hback1 = Highest(high, sb1)[1];
def swinghigh1   = if high > hfor1 and high > hback1 then 1 else 0;
def swinghighbar = if high > hfor1 and high > hback1 then bn else na;

#Swings identifed as points
plot r2 = if showlastswing ==yes and bn==highestall(swinghighbar) then high else if showlastswing == no and swinghigh1 then high else na;
plot s2 = if showlastswing == yes and bn==highestall(swinglowbar) then low else if showlastswing == no and swinglow1 then low else na;

r2.SetStyle(Curve.POINTS);
r2.SetLineWeight(4);
r2.SetDefaultColor(Color.GREEN);
r2.HideBubble();
s2.SetStyle(Curve.POINTS);
s2.SetLineWeight(4);
s2.SetDefaultColor(Color.RED);
s2.HideBubble();


input bubbleoffsetfactor  = 3;
input showbubbles_r2s2    = yes;
AddChartBubble(showbubbles_r2s2 and r2, high + TickSize() * bubbleoffsetfactor, "R2", Color.GREEN, yes);
AddChartBubble(showbubbles_r2s2 and s2, low - TickSize() * bubbleoffsetfactor, "S2", Color.RED, no);

#Store Previous Data
def r2save = if !IsNaN(r2) then r2 else r2save[1];
def s2save = if !IsNaN(s2) then s2 else s2save[1];

#Fibonacci
def data      = CompoundValue(1, if (r2save == high) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]) + 1;
input numberfibstoshow = 1;

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;

def fibh = r2save;
def fibl = s2save;
def range = fibh - fibl;

input showfiblines = yes;

plot fibHp = r2save;
plot fibLp = s2save;
plot fibM  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fibMlevel else na;
plot fib1  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib1level else na;
plot fib2  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib2level else na;
plot fib3  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib3level else na;
plot fib4  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib4level else na;
plot fib5  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib5level else na;
plot fib6  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib6level else na;
plot fib7  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib7level else na;
plot fib8  = if showfiblines == no then na else if datacount <= numberfibstoshow then fibl + range * fib8level else na;

fibHp.SetPaintingStrategy(PaintingStrategy.DASHES);
fibLp.SetPaintingStrategy(PaintingStrategy.DASHES);
fibHp.SetLineWeight(2);
fibLp.SetLineWeight(2);
fibM.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibHp.SetDefaultColor(Color.GREEN);
fibLp.SetDefaultColor(Color.RED);
fibM.SetDefaultColor(Color.WHITE);
fib1.SetDefaultColor(Color.CYAN);
fib2.SetDefaultColor(Color.YELLOW);
fib3.SetDefaultColor(Color.YELLOW);
fib4.SetDefaultColor(Color.CYAN);
fib5.setdefaultColor(color.yellow);
fib6.setdefaultColor(color.yellow);
fib7.setdefaultColor(color.yellow);
fib8.setdefaultColor(color.yellow);

fibM.HideBubble();
fib1.HideBubble();
fib2.HideBubble();
fib3.HideBubble();
fib4.HideBubble();
fib5.HideBubble();
fib6.HideBubble();
fib7.HideBubble();
fib8.HideBubble();

input showfib_bubbles = yes;
input bubble_mover    = 5;
def   n = bubble_mover;
def  n1 = n +1;
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fibh[n1], "R2 " + astext(fibh[n1]), Color.green, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fibl[n1], "S2 " + astext(fibl[n1]), Color.red, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib4[n1], "23.6%", Color.cyan, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib1[n1], "76.4%", Color.cyan, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib3[n1], "38.2%", Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib2[n1], "61.8%", Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fibm[n1], "50.0%", Color.white, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib5[n1], "161.8%", Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib6[n1], "261.8%", Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib7[n1], "161.8%", Color.yellow, yes);
AddChartBubble(showfib_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), fib8[n1], "261.8%", Color.yellow, yes);
 
Top