New problem. I inserted your line offset code, as a test, on lines 15 and 87 in the code below. The image shows that it had the desired effect on the top green line. Unfortunately, it somehow interferes with the chart bubble code on line 171. How would the chartbubble code need to be altered?
View attachment 25851
Code:# www.usethinkscript.com # 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 line_offsets = 5; input fib1 =...
Ok, assuming hh1 is any value that I have developed elsewhere, what would the code be to plot it beginning five BARS to the right of the last BAR.
?Code:def hh1 = 25000; plot hhp = if !IsNaN(close) then Double.NaN else hh1;
Code:input hh1 = 25000; input offset = 5; plot hhp = if !IsNaN(close[offset]) then Double.NaN else hh1;
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
# www.usethinkscript.com
# 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 line_offsets = 5;
input fib1 = .236;
input fib2 = .382;
input fib3 = .500;
input fib4 = .618;
input fib5 = .786;
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
# Define the level for the horizontal line
input lineLevel = 50;
# Define the number of bars to extend from the right margin
input barsFromRight = 5;
# Calculate the condition for plotting the line
def condition = (GetMaxValueOffset(10) - barsFromRight) <= BarNumber();
plot hhp = if !IsNaN(close) then Double.NaN else hh1;
hhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(2);
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(2);
# UPPER FIBONACCI EXTENSION LEVELS
plot uhhp = if !IsNaN(close[line_offsets]) 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.CYAN, 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
The following snippet of code would fix line 171. See lower panel of the image.New problem. I inserted your line offset code, as a test, on lines 15 and 87 in the code below. The image shows that it had the desired effect on the top green line. Unfortunately, it somehow interferes with the chart bubble code on line 171. How would the chartbubble code need to be altered?
View attachment 25851
Code:# www.usethinkscript.com # 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 line_offsets = 5; input fib1 = .236; input fib2 = .382; input fib3 = .500; input fib4 = .618; input fib5 = .786; 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 # Define the level for the horizontal line input lineLevel = 50; # Define the number of bars to extend from the right margin input barsFromRight = 5; # Calculate the condition for plotting the line def condition = (GetMaxValueOffset(10) - barsFromRight) <= BarNumber(); plot hhp = if !IsNaN(close) then Double.NaN else hh1; hhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); hhp.SetDefaultColor(Color.GREEN); hhp.SetLineWeight(2); 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(2); # UPPER FIBONACCI EXTENSION LEVELS plot uhhp = if !IsNaN(close[line_offsets]) 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.CYAN, 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
Code:AddChartBubble(showchart_bubbles and !IsNaN(close[n1 + line_offsets]) and IsNaN(close[n + line_offsets]), uhhp[n], 2 , Color.WHITE, yes);
However, I assumed you would want all of the lines to move right by input line_spaces. See upper panel in image. Fixed code below
Code:# www.usethinkscript.com # 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 line_offsets = 5; input fib1 = .236; input fib2 = .382; input fib3 = .500; input fib4 = .618; input fib5 = .786; 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 # Define the level for the horizontal line input lineLevel = 50; # Define the number of bars to extend from the right margin input barsFromRight = 5; # Calculate the condition for plotting the line def condition = (GetMaxValueOffset(10) - barsFromRight) <= BarNumber(); plot hhp = if !IsNaN(close[line_offsets]) then Double.NaN else hh1; hhp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); hhp.SetDefaultColor(Color.GREEN); hhp.SetLineWeight(2); plot f1p = if !IsNaN(close[line_offsets]) then Double.NaN else ff1; f1p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); f1p.SetDefaultColor(Color.YELLOW); f1p.SetLineWeight(1); plot f2p = if !IsNaN(close[line_offsets]) then Double.NaN else ff2; f2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); f2p.SetDefaultColor(Color.YELLOW); f2p.SetLineWeight(1); plot f3p = if !IsNaN(close[line_offsets]) then Double.NaN else ff3; f3p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); f3p.SetDefaultColor(Color.WHITE); f3p.SetLineWeight(1); plot f4p = if !IsNaN(close[line_offsets]) then Double.NaN else ff4; f4p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); f4p.SetDefaultColor(Color.YELLOW); f4p.SetLineWeight(1); plot f5p = if !IsNaN(close[line_offsets]) then Double.NaN else ff5; f5p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); f5p.SetDefaultColor(Color.YELLOW); f5p.SetLineWeight(1); plot llp = if !IsNaN(close[line_offsets]) then Double.NaN else ll1; llp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); llp.SetDefaultColor(Color.RED); llp.SetLineWeight(2); # UPPER FIBONACCI EXTENSION LEVELS plot uhhp = if !IsNaN(close[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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[line_offsets]) 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; def move = !IsNaN(close[n1 +line_offsets]) and IsNaN(close[n+line_offsets]); AddChartBubble(showchart_bubbles and move , hhp[n], 1 + " = High", Color.YELLOW, yes); AddChartBubble(showchart_bubbles and move, ff1[n], fib1 , Color.YELLOW, yes); AddChartBubble(showchart_bubbles and move, ff2[n], fib2 , Color.YELLOW, yes); AddChartBubble(showchart_bubbles and move, ff3[n], fib3 , Color.CYAN, yes); AddChartBubble(showchart_bubbles and move, ff4[n], fib4 , Color.YELLOW, yes); AddChartBubble(showchart_bubbles and move, ff5[n], fib5 , Color.YELLOW, yes); AddChartBubble(showchart_bubbles and move, llp[n], 0 + " = Low", Color.YELLOW, yes); # EXTENSION ABOVE AddChartBubble(showchart_bubbles and move, uf1p[n], 1+fib1, Color.WHITE, yes); AddChartBubble(showchart_bubbles and move, uf2p[n], 1+fib2, Color.WHITE, yes); AddChartBubble(showchart_bubbles and move, uf3p[n], 1+fib3, Color.WHITE, yes); AddChartBubble(showchart_bubbles and move, uf4p[n], 1+fib4, Color.WHITE, yes); AddChartBubble(showchart_bubbles and move, uf5p[n], 1+fib5, Color.WHITE, yes); AddChartBubble(showchart_bubbles and move, uhhp, 2 , Color.WHITE, yes); # EXTENSION BELOW AddChartBubble(showchart_bubbles and move, Lf1p[n], -fib1, Color.PINK, yes); AddChartBubble(showchart_bubbles and move, Lf2p[n], -fib2, Color.PINK, yes); AddChartBubble(showchart_bubbles and move, Lf3p[n], -fib3, Color.PINK, yes); AddChartBubble(showchart_bubbles and move, Lf4p[n], -fib4, Color.PINK, yes); AddChartBubble(showchart_bubbles and move, Lf5p[n], -fib5, Color.PINK, yes); AddChartBubble(showchart_bubbles and move, 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
# www.usethinkscript.com
# Fib Choices V2
# BLT, with modifications by tomsk, van wooten and SleepyZ
# 10.2.2025
# 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 Line_offset = 5;
input fib1 = .236;
input fib2 = .382;
input fib3 = .500;
input fib4 = .618;
input fib5 = .786;
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
# Define the level for the horizontal line
input lineLevel = 50;
# Define the number of bars to extend from the right margin
input barsFromRight = 5;
#Input line_offset = 5;
# Calculate the condition for plotting the line
def condition = (GetMaxValueOffset(10) - barsFromRight) <= BarNumber();
plot hhp = if !IsNaN(close[line_offset]) then Double.NaN else hh1;
hhp.SetPaintingStrategy(PaintingStrategy.LINE);
hhp.Setstyle(curve.firm);
hhp.SetDefaultColor(Color.GREEN);
hhp.SetLineWeight(2);
plot f1p = if !IsNaN(close[line_offset]) then Double.NaN else ff1;
f1p.SetPaintingStrategy(PaintingStrategy.LINE);
f1p.Setstyle(curve.SHORT_DASH);
f1p.SetDefaultColor(Color.YELLOW);
f1p.SetLineWeight(1);
plot f2p = if !IsNaN(close[line_offset]) then Double.NaN else ff2;
f2p.SetPaintingStrategy(PaintingStrategy.LINE);
f2p.Setstyle(curve.SHORT_DASH);
f2p.SetDefaultColor(Color.YELLOW);
f2p.SetLineWeight(1);
plot f3p = if !IsNaN(close[line_offset]) then Double.NaN else ff3;
f3p.SetPaintingStrategy(PaintingStrategy.LINE);
f3p.Setstyle(curve.firm);
f3p.SetDefaultColor(Color.WHITE);
f3p.SetLineWeight(1);
plot f4p = if !IsNaN(close[line_offset]) then Double.NaN else ff4;
f4p.SetPaintingStrategy(PaintingStrategy.LINE);
f4p.Setstyle(curve.SHORT_DASH);
f4p.SetDefaultColor(Color.YELLOW);
f4p.SetLineWeight(1);
plot f5p = if !IsNaN(close[line_offset]) then Double.NaN else ff5;
f5p.SetPaintingStrategy(PaintingStrategy.LINE);
f5p.Setstyle(curve.SHORT_DASH);
f5p.SetDefaultColor(Color.YELLOW);
f5p.SetLineWeight(1);
plot llp = if !IsNaN(close[line_offset]) then Double.NaN else ll1;
llp.SetPaintingStrategy(PaintingStrategy.LINE);
llp.Setstyle(curve.firm);
llp.SetDefaultColor(Color.RED);
llp.SetLineWeight(2);
# UPPER FIBONACCI EXTENSION LEVELS
plot uhhp = if !IsNaN(close[line_offset]) or display_upper_extended_fibs == no then Double.NaN else range + hh1;
uhhp.SetPaintingStrategy(PaintingStrategy.LINE);
uhhp.Setstyle(curve.firm);
uhhp.SetDefaultColor(Color.GREEN);
uhhp.SetLineWeight(1);
plot uf1p = if !IsNaN(close[line_offset]) or display_upper_extended_fibs == no then Double.NaN else range + ff1;
uf1p.SetPaintingStrategy(PaintingStrategy.LINE);
uf1p.Setstyle(curve.SHORT_DASH);
uf1p.SetDefaultColor(Color.YELLOW);
uf1p.SetLineWeight(1);
plot uf2p = if !IsNaN(close[line_offset]) or display_upper_extended_fibs == no then Double.NaN else range + ff2;
uf2p.SetPaintingStrategy(PaintingStrategy.LINE);
uf2p.Setstyle(curve.SHORT_DASH);
uf2p.SetDefaultColor(Color.YELLOW);
uf2p.SetLineWeight(1);
plot uf3p = if !IsNaN(close[line_offset]) or display_upper_extended_fibs == no then Double.NaN else range + ff3;
uf3p.SetPaintingStrategy(PaintingStrategy.LINE);
uf3p.Setstyle(curve.firm);
uf3p.SetDefaultColor(Color.WHITE);
uf3p.SetLineWeight(1);
plot uf4p = if !IsNaN(close[line_offset]) or display_upper_extended_fibs == no then Double.NaN else range + ff4;
uf4p.SetPaintingStrategy(PaintingStrategy.LINE);
uf4p.Setstyle(curve.SHORT_DASH);
uf4p.SetDefaultColor(Color.YELLOW);
uf4p.SetLineWeight(1);
plot uf5p = if !IsNaN(close[line_offset]) or display_upper_extended_fibs == no then Double.NaN else range + ff5;
uf5p.SetPaintingStrategy(PaintingStrategy.linE);
uf5p.Setstyle(curve.SHORT_DASH);
uf5p.SetDefaultColor(Color.YELLOW);
uf5p.SetLineWeight(1);
# LOWER FIBONACCI EXTENSION LEVELS
plot Lllp = if !IsNaN(close[line_offset]) or display_lower_extended_fibs == no then Double.NaN else ll - range;
Lllp.SetPaintingStrategy(PaintingStrategy.LINE);
Lllp.Setstyle(curve.firm);
Lllp.SetDefaultColor(Color.RED);
Lllp.SetLineWeight(1);
plot Lf1p = if !IsNaN(close[line_offset]) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib1;
Lf1p.SetPaintingStrategy(PaintingStrategy.LINE);
Lf1p.Setstyle(curve.SHORT_DASH);
Lf1p.SetDefaultColor(Color.YELLOW);
Lf1p.SetLineWeight(1);
plot Lf2p = if !IsNaN(close[line_offset]) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib2;
Lf2p.SetPaintingStrategy(PaintingStrategy.LINE);
Lf2p.Setstyle(curve.SHORT_DASH);
Lf2p.SetDefaultColor(Color.YELLOW);
Lf2p.SetLineWeight(1);
plot Lf3p = if !IsNaN(close[line_offset]) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib3;
Lf3p.SetPaintingStrategy(PaintingStrategy.LINE);
Lf3p.Setstyle(curve.firm);
Lf3p.SetDefaultColor(Color.WHITE);
Lf3p.SetLineWeight(1);
plot Lf4p = if !IsNaN(close[line_offset]) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib4;
Lf4p.SetPaintingStrategy(PaintingStrategy.LINE);
Lf4p.Setstyle(curve.SHORT_DASH);
Lf4p.SetDefaultColor(Color.YELLOW);
Lf4p.SetLineWeight(1);
plot Lf5p = if !IsNaN(close[line_offset]) or display_lower_extended_fibs == no then Double.NaN else ll - range * fib5;
Lf5p.SetPaintingStrategy(PaintingStrategy.LINE);
Lf5p.Setstyle(curve.SHORT_DASH);
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 bubble_offset = line_offset;
def n = bubblemover - line_offset;
def n1 = n + 1;
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), hhp[n], 1 + " = High", Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), ff1[n], fib1 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), ff2[n], fib2 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), ff3[n], fib3 , Color.CYAN, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), ff4[n], fib4 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), ff5[n], fib5 , Color.YELLOW, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), llp[n], 0 + " = Low", Color.YELLOW, yes);
# EXTENSION ABOVE
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), uf1p[n], 1+fib1, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), uf2p[n], 1+fib2, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), uf3p[n], 1+fib3, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), uf4p[n], 1+fib4, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), uf5p[n], 1+fib5, Color.WHITE, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), uhhp[n], 2 , Color.WHITE, yes);
# EXTENSION BELOW
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), Lf1p[n], -fib1, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), Lf2p[n], -fib2, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), Lf3p[n], -fib3, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), Lf4p[n], -fib4, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), Lf5p[n], -fib5, Color.PINK, yes);
AddChartBubble(showchart_bubbles and !IsNaN(close[n1+ line_offset]) and IsNaN(close[n+ line_offset]), 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 V2
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
G | how to change offset after market close for plotted line | Questions | 12 | |
T | offset the volume scale 0 line display by a given amount | Questions | 1 | |
R | Limit To Most Recent & Offset Bubbles? | Questions | 1 | |
D | Help with Awesome Oscillator offset/bar shift | Questions | 4 | |
D | Add offset to a 3min HMA135 on 1min chart | Questions | 2 |
Start a new thread and receive assistance from our community.
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.
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.