Fibonacci Extension and Retracement In One Script?

mikeraya

New member
Is it possible to write a code that gives a Fibonacci Extension and Retracement on one draw? Thank you in advance.
 
Solution
Is it possible to write a code that gives a Fibonacci Extension and Retracement on one draw? Thank you in advance.

Here are 2 auto scripts (retracement and extension) that I posted in here that are modified to be in one script.

It uses the previous day for the retacement and the current day's developing candles for the extension. If the previous day's low was before the high of the day (only aggperiod tested) then the developing low of the current day would be used for the extension. If the previous day's high was first then the current day will use the high.

Screenshot-2023-04-30-154416.png
Code:
#Combined_AutoFib_Retracement_Extension

#Auto_FibExtensions_flips_fib_levels_including_intraday_timeframes_using_Open_as_ZeroBase

def limit_display =...

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

Is it possible to write a code that gives a Fibonacci Extension and Retracement on one draw? Thank you in advance.

Here are 2 auto scripts (retracement and extension) that I posted in here that are modified to be in one script.

It uses the previous day for the retacement and the current day's developing candles for the extension. If the previous day's low was before the high of the day (only aggperiod tested) then the developing low of the current day would be used for the extension. If the previous day's high was first then the current day will use the high.

Screenshot-2023-04-30-154416.png
Code:
#Combined_AutoFib_Retracement_Extension

#Auto_FibExtensions_flips_fib_levels_including_intraday_timeframes_using_Open_as_ZeroBase

def limit_display = yes;
def display_x     = 1;
input aggperiod     = {"1 MIN", "2 MIN", "3 MIN", "5 MIN", "10 MIN", "15 MIN", "30 MIN", "1 HOUR", default "DAY", "WEEK", "MONTH", "YEAR"};
input showbubbles   = yes;
input bubblemover   = -1;
input showverticals = yes;

def bm  = bubblemover;
def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);

switch (aggperiod) {
case "1 MIN":
    period = Floor(seconds / 60 + day_number * 24 * 60);
case "2 MIN":
    period = Floor(seconds / 120 + day_number * 24);
case "3 MIN":
    period = Floor(seconds / 180 + day_number * 24);
case "5 MIN":
    period = Floor(seconds / 300 + day_number * 24);
case "10 MIN":
    period = Floor(seconds / 600 + day_number * 24);
case "15 MIN":
    period = Floor(seconds / 900 + day_number * 24);
case "30 MIN":
    period = Floor(seconds / 1800 + day_number * 24);
case "1 HOUR":
    period = Floor(seconds / 3600 + day_number * 24);
case "DAY":
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case "WEEK":
    period = Floor(day_number / 7);
case "MONTH":
    period = Floor(month - First(month));
case "YEAR":
    period = GetYear();
}

def na = Double.NaN;
def bn = BarNumber();
def H  = high(period = aggperiod);
def L  = low(period = aggperiod);
def O  = open(period = aggperiod);

def hbar = if high == H then bn else hbar[1];
def lbar = if low == L  then bn else lbar[1];

def basis;
switch (aggperiod) {
case "1 MIN":
    basis = period != period[-1];
case "2 MIN":
    basis = period != period[-1];
case "3 MIN":
    basis = period != period[-1];
case "5 MIN":
    basis = period != period[-1];
case "10 MIN":
    basis = period != period[-1];
case "15 MIN":
    basis = period != period[-1];
case "30 MIN":
    basis = period != period[-1];
case "1 HOUR":
    basis = period != period[-1];
case "DAY":
    basis = GetDay() != GetDay()[-1];
case "WEEK":
    basis = GetWeek() != GetWeek()[-1];
case "MONTH":
    basis = GetMonth() != GetMonth()[-1];
case "YEAR":
    basis = GetYear() != GetYear()[-1];
}
input F1 = -1.00;
input F2 = -.618;
input F3 = -.27;
input F4 = 0.236;
input F5 = 0.382;
input F6 = 0.500;
input F7 = 0.618;
input F8 = 0.764;
input F9 = 1.00;
input F10 = 1.27;
input F11 = 1.618;
input F12 = 2.00;

def rz         = if period != period[1]
                 then if hbar[1] < lbar[1]
                      then high(period=aggperiod)
                      else low(period=aggperiod)
                 else rz[1];
def rplusminus = if period != period[1]
                 then if hbar[1] < lbar[1]
                      then 0
                      else 1
                 else rplusminus[1];

def Count  = CompoundValue(1, if (H + L != H[1] + L[1]) then Count[1] + 1 else Count[1], 0);

plot rzero = if limit_display and HighestAll(Count) - Count <= (display_x - 1)
             then rz
             else if !limit_display
             then rz else na;


def range  = AbsValue(H[1] - L[1]);

plot FF1   = if rplusminus == 1 then rzero + (range * F1) else rzero - (range * F1);
plot FF2   = if rplusminus == 1 then rzero + (range * F2) else rzero - (range * F2);
plot FF3   = if rplusminus == 1 then rzero + (range * F3) else rzero - (range * F3);
plot FF4   = if rplusminus == 1 then rzero + (range * F4) else rzero - (range * F4);
plot FF5   = if rplusminus == 1 then rzero + (range * F5) else rzero - (range * F5);
plot FF6   = if rplusminus == 1 then rzero + (range * F6) else rzero - (range * F6);
plot FF7   = if rplusminus == 1 then rzero + (range * F7) else rzero - (range * F7);
plot FF8   = if rplusminus == 1 then rzero + (range * F8) else rzero - (range * F8);
plot FF9   = if rplusminus == 1 then rzero + (range * F9) else rzero - (range * F9);
plot FF10  = if rplusminus == 1 then rzero + (range * F10) else rzero - (range * F10);
plot FF11  = if rplusminus == 1 then rzero + (range * F11) else rzero - (range * F11);
plot FF12  = if rplusminus == 1 then rzero + (range * F12) else rzero - (range * F12);

rzero.SetDefaultColor(Color.WHITE);
rzero.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rzero.SetLineWeight(1);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

AddChartBubble(if IsNaN(rzero[-1]) then Double.NaN else showbubbles and basis[bm] , rzero[bm], 0, if rplusminus[bm] == 1 then Color.GREEN else Color.RED);
AddChartBubble(if IsNaN(FF1[-1]) then Double.NaN else showbubbles and basis[bm], FF1[bm], F1, FF1.TakeValueColor());
AddChartBubble(if IsNaN(FF2[-1]) then Double.NaN else showbubbles and basis[bm], FF2[bm], F2, FF2.TakeValueColor());
AddChartBubble(if IsNaN(FF3[-1]) then Double.NaN else showbubbles and basis[bm], FF3[bm], F3, FF3.TakeValueColor());
AddChartBubble(if IsNaN(FF4[-1]) then Double.NaN else showbubbles and basis[bm], FF4[bm], F4, FF4.TakeValueColor());
AddChartBubble(if IsNaN(FF5[-1]) then Double.NaN else showbubbles and basis[bm], FF5[bm],  F5, FF5.TakeValueColor());
AddChartBubble(if IsNaN(FF6[-1]) then Double.NaN else showbubbles and basis[bm], FF6[bm], F6, FF6.TakeValueColor());
AddChartBubble(if IsNaN(FF7[-1]) then Double.NaN else showbubbles and basis[bm], FF7[bm], F7 , FF7.TakeValueColor());
AddChartBubble(if IsNaN(FF8[-1]) then Double.NaN else showbubbles and basis[bm], FF8[bm],  F8, FF8.TakeValueColor());
AddChartBubble(if IsNaN(FF9[-1]) then Double.NaN else showbubbles and basis[bm], FF9[bm],  F9, if rplusminus == 1 then Color.GREEN else Color.RED);
AddChartBubble(if IsNaN(FF10[-1]) then Double.NaN else showbubbles and basis[bm], FF10[bm],  F10, FF10.TakeValueColor());
AddChartBubble(if IsNaN(FF11[-1]) then Double.NaN else showbubbles and basis[bm], FF11[bm],  F11, FF11.TakeValueColor());
AddChartBubble(if IsNaN(FF12[-1]) then Double.NaN else showbubbles and basis[bm], FF12[bm], F12, FF12.TakeValueColor());

AddVerticalLine(if limit_display and HighestAll(Count) - Count <= (display_x - 1)  and period!=period[1] then 1 else if !limit_display and showverticals and period != period[1] then 1 else na, " ", Color.WHITE );
;

#=========================================================================

#Auto_FibPrevDayRetracements_plots_previous_day_and_fib_levels_based_thereon
input ShowTodayOnly = { default "No", "Yes"};

input displace      = 1;

def ORHa = if isnan(close) or ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else high(period = aggperiod)[displace];
def ORLa = if isnan(close) or ShowTodayOnly and !IsNaN(close(period = aggperiod)[-1]) then Double.NaN else  low(period = aggperiod)[displace];


def hbara = if high == high(period = aggperiod) then bn else hbara[1];
def lbara = if low == low(period = aggperiod) then bn else lbara[1];


input F1a = -1.00;
input F2a = -0.62;
input F3a = -0.27;
input F4a = 0.236;
input F5a = 0.382;
input F6a = 0.500;
input F7a = 0.618;
input F8a = 0.786;
input F10a = 1.27;
input F11a = 1.618;
input F12a = 2.00;

def Counta  = CompoundValue(1, if (ORHa + ORLa != ORHa[1] + ORLa[1]) then Count[1] + 1 else Count[1], 0);

plot rzeroa = if limit_display and HighestAll(Count) - Count <= (display_x - 1)
             then rz
             else if !limit_display
             then rz else na;


plot rHia =  if limit_display and HighestAll(Count) - Count <= (display_x - 1)
            then ORHa
            else if !limit_display
            then ORHa  
            else na;
plot rLoa =   if limit_display and HighestAll(Count) - Count <= (display_x - 1)
            then ORLa
            else if !limit_display
            then ORLa  
            else na;

rHia.SetDefaultColor(Color.WHITE);
rHia.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rHia.SetLineWeight(2);

rLoa.SetDefaultColor(Color.WHITE);
rLoa.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
rLoa.SetLineWeight(2);


def rangea  = rHia - rLoa;
plot FF1a   = rLoa + (rangea * F1a);
plot FF2a   = rLoa + (rangea * F2a);
plot FF3a   = rLoa + (rangea * F3a);
plot FF4a   = rLoa + (rangea * F4a);
plot FF5a   = rLoa + (rangea * F5a);
plot FF6a   = rLoa + (rangea * F6a);
plot FF7a   = rLoa + (rangea * F7a);
plot FF8a   = rLoa + (rangea * F8a);
plot FF10a  = rLoa + (rangea * F10a);
plot FF11a  = rLoa + (rangea * F11a);
plot FF12a  = rLoa + (rangea * F12a);

def ha = high(period = AggregationPeriod.DAY);
def la = low(period = AggregationPeriod.DAY);

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

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

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

FF4a.SetDefaultColor(Color.CYAN);
FF4a.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF4a.SetLineWeight(1);

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

FF6a.SetDefaultColor(Color.WHITE);
FF6a.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF6a.SetLineWeight(1);

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

FF8a.SetDefaultColor(Color.CYAN);
FF8a.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FF8a.SetLineWeight(1);

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

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

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

def basisa;
switch (aggperiod) {
case "1 MIN":
    basisa = period != period[1];
case "2 MIN":
    basisa = period != period[1];
case "3 MIN":
    basisa = period != period[1];
case "5 MIN":
    basisa = period != period[1];
case "10 MIN":
    basisa = period != period[1];
case "15 MIN":
    basisa = period != period[1];
case "30 MIN":
    basisa = period != period[1];
case "1 HOUR":
    basisa = period != period[1];
case "DAY":
    basisa = GetDay() != GetDay()[1];
case "WEEK":
    basisa = GetWeek() != GetWeek()[1];
case "MONTH":
    basisa = GetMonth() != GetMonth()[1];
case "YEAR":
    basisa = GetYear() != GetYear()[1];
}

AddChartBubble(showbubbles and basisa, rHia, if lbara > hbara then 100 else 0, if lbara > hbara then Color.GREEN else Color.RED);
AddChartBubble(showbubbles and basisa, rLoa, if lbara > hbara then 0 else 100, if lbara > hbara then Color.RED else Color.GREEN, no);
AddChartBubble(showbubbles and basisa, FF1a, if lbara > hbara then F1a else F12a, FF1a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF2a, if lbara > hbara then F2a else F11a, FF2a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF3a, if lbara > hbara then F3a else F10a, FF3a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF4a, if lbara > hbara then F4a else F8a, FF4a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF5a, if lbara > hbara then F5a else F7a, FF5a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF6a, if lbara > hbara then F6a else F6a, FF6a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF7a, if lbara > hbara then F7a else F5a, FF7a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF8a, if lbara > hbara then F8a else F4a, FF8a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF10a, if lbara > hbara then F10a else F3a, FF10a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF11a, if lbara > hbara then F11a else F2a, FF11a.TakeValueColor());
AddChartBubble(showbubbles and basisa, FF12a, if lbara > hbara then F12a else F1a, FF12a.TakeValueColor());
;
;
 
Last edited by a moderator:
Solution
Here are 2 auto scripts (retracement and extension) that I posted in here that are modified to be in one script.

It uses the previous day for the retacement and the current day's developing candles for the extension. If the previous day's low was before the high of the day (only aggperiod tested) then the developing low of the current day would be used for the extension. If the previous day's high was first then the current day will use the high.
Hi SleepyZ, can you add the codes that shows the two red dashed lines? I copied and pasted, but it does not show the red dashed lines. Thanks,
 
Hi SleepyZ, can you add the codes that shows the two red dashed lines? I copied and pasted, but it does not show the red dashed lines. Thanks,

Those are not part of the code. The red dashed lines, shaded circles and blue dashed horizontal lines were added to the image to help confirm the coding.
 
Here are 2 auto scripts (retracement and extension) that I posted in here that are modified to be in one script.

It uses the previous day for the retacement and the current day's developing candles for the extension. If the previous day's low was before the high of the day (only aggperiod tested) then the developing low of the current day would be used for the extension. If the previous day's high was first then the current day will use the high.
Is it possible to set this to premarket hours as well?
 
hi @BenTen or anyone else who could help
I tried everything and can't seem to figure this out
I ve been using this code :
Code:
plot Data = close;# Automatically draws fibonacci retracements using the highest price and lowest price
# from the current view and timeframe.
#
# Fibonacci retracements use horizontal lines to indicate areas of support or resistance
# at the key Fibonacci levels before it continues in the original direction. These levels
# are created by drawing a trendline between two extreme points and then dividing the
# vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%.

# CHANGE LOG
#
# V1.0 - 12.18.2018 - BenTen       - Initial release of Auto Fib, created by Ryan Hendricks
# V1.1 - 11.15.2019 - theelderwand - As script was difficult to read, made the following enhancements
#                                    Expands to right
#                                    Doesn't expand to left
#                                    Custom colors for Fibonacci bars (0.618 is GOLD color)
#                                    Custom line weights
#                                    Code is modularized so you can add extra plots as needed
# V1.2 - 11.15.2019 - tomsk        - Added an input selector for the colors of the label. You
#                                    can select from any of the colors listed - red, orange,
#                                    green, etc and bubbles for all the fib retracements will
#                                    utilize that color.
# V1.3 - 11.19.2019 - tomsk        - Modified the AddChartBubbles to be displayed on the right
#                                    side of the chart. Please ensure that you increase the
#                                    expansion area to that the bubbles have room to be displayed
#                                    Chart Settings > Time Axis > Expansion Area

#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>

#hint coefficient_0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: coefficient_0
#wizard text: coefficient_0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

input price = close;
input high = high;
input low = low;
input coefficient_0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = 1.000;

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

def n1  = n + 1;
def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();

def range =  a - b;

def value0 = range * coefficient_0;
def value1 = range * coefficient_1;
def value2 = range * coefficient_2;
def value3 = range * coefficient_3;
def value4 = range * coefficient_4;
def value5 = range * coefficient_5;
def value6 = range * coefficient_6;

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

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

Retracement0.assignvaluecolor(CreateColor(255,255,255));
Retracement0.setLineWeight(4);
retracement0.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);

Retracement1.assignvaluecolor(CreateColor(173,216,230));
Retracement1.setLineWeight(2);
retracement1.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);

Retracement2.assignvaluecolor(CreateColor(0,197,49));
Retracement2.setLineWeight(2);
retracement2.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);

Retracement3.assignvaluecolor(CreateColor(255,64,64));
Retracement3.setLineWeight(3);
retracement3.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);

Retracement4.assignvaluecolor(CreateColor(255,215,0));
Retracement4.setLineWeight(5);
retracement4.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);

Retracement5.assignvaluecolor(CreateColor(0,255,255));
Retracement5.setLineWeight(2);
retracement5.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);

Retracement6.assignvaluecolor(CreateColor(255,255,255));
Retracement6.setLineWeight(4);
Retracement6.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);

alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1");
alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1");
alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3");
alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3");
alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");
# End Auto Fib v1.3

And the issue I'm having with it or at least what I would love to change is the fact that the 0% and 100% line move when the candles touch it, so the candles don't ever get to cross those lines, which doesn't help with my strategy so I was wondering if you could edit this code to make it so that the lines don't move further away, one market opens where they are calculated to be stays put like the other lines?
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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