High and Low with Fibonacci Retracement Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This indicator for ThinkorSwim takes the high and low of the previous week or month and add Fibonacci retracement levels to create potential support and resistance levels. You can also use the high and low of the previous day, yearly, etc. Up to you to select the right timeframe to help your trading style.



thinkScript Code

Rich (BB code):
#
# WalkingBallista & BenTen
# https://usethinkscript.com/d/153-high-and-low-with-fibonacci-retracement-indicator-for-thinkorswim
input aggregationPeriod = AggregationPeriod.DAY;
input ShowTodayOnly = yes;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
def PO = open(period = aggregationPeriod);
def Today = if GetDay() == GetLastDay() then 1 else 0;
def Week = if GetWeek() == GetLastWeek() then 1 else 0;

def range = PH - PL;
input fib = 1.618;
input fib1 = 1.272;
input fib2 = 0.618;
input fib3 = 0.236;
input fib4 = 0.382;
input fib5 = 0.5;
input fib6 = 0.786;
input fib7 = 2.618;

plot h = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib-1);
plot h1 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib1-1);
plot h2 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib2-1);
plot h3 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib3-1);
plot h4 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib4-1);
plot h5 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib5-1);
plot h6 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib6-1);
plot h7 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH + range*(fib7-1);
plot h8 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib1-1);
plot h9 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib-1);
plot h10 = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL - range*(fib7-1);

h.DefineColor("Color", Color.DARK_RED);
h.AssignValueColor(h.color("Color"));
h.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h1.DefineColor("Color", Color.RED);
h1.AssignValueColor(h1.color("Color"));
h1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h2.DefineColor("Color", Color.RED);
h2.AssignValueColor(h2.color("Color"));
h2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h3.DefineColor("Color", Color.RED);
h3.AssignValueColor(h3.color("Color"));
h3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h4.DefineColor("Color", Color.RED);
h4.AssignValueColor(h3.color("Color"));
h4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h5.DefineColor("Color", Color.RED);
h5.AssignValueColor(h3.color("Color"));
h5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h6.DefineColor("Color", Color.RED);
h6.AssignValueColor(h3.color("Color"));
h6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h7.DefineColor("Color", Color.RED);
h7.AssignValueColor(h3.color("Color"));
h7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h8.DefineColor("Color", Color.RED);
h8.AssignValueColor(h3.color("Color"));
h8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h9.DefineColor("Color", Color.RED);
h9.AssignValueColor(h3.color("Color"));
h9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

h10.DefineColor("Color", Color.RED);
h10.AssignValueColor(h3.color("Color"));
h10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot highofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PH;
highofline.DefineColor("Color", Color.YELLOW);
highofline.AssignValueColor(highofline.color("Color"));
highofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot lowofline = if ShowTodayOnly and !Today and aggregationPeriod == AggregationPeriod.Day then Double.NaN else if ShowTodayOnly and !Week and aggregationPeriod == AggregationPeriod.Week then Double.NaN else PL;
lowofline.DefineColor("Color", Color.YELLOW);
lowofline.AssignValueColor(highofline.color("Color"));
lowofline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Shareable Link

http://tos.mx/UoIukn

Video Tutorial

 
Last edited:
B

Buckbull

Member
Could this script be modified for the 15min chart to plot the Days High and low candle ? If so how ?
 
BenTen

BenTen

Administrative
Staff
VIP
@Buckbull Select the 15m timeframe from the indicator's settings.
 
BenTen

BenTen

Administrative
Staff
VIP
@Juxtapose You would have to modify the code.
 
T

tradetollive

New member
Hello can someone help to adjust this fib, i use it everyday it work great to trade but is not accurate do to, is not including extended hour i want it to include 4:00 am to 8:00 PM last day. ( here an example is missing .13 cents do to not capturing the after-hour thanks

 
Last edited by a moderator:
dojionehundop

dojionehundop

New member
Hi @BenTen, thanks a lot for this. Would you please be able to show me what code to add in order to add bubbles to the plots? Ideally with fibs on the left, and prices on the right? Or just one on the right? Is there an easy way to invert the 100% and 0% to flip the fibs upside down or rightside up?
 
dojionehundop

dojionehundop

New member
@dojionehundop You can take inspiration from this script and modify this one to look like it: https://usethinkscript.com/threads/auto-fib-fibonacci-levels-indicator-for-thinkorswim.14/
Thanks for the tip @BenTen, and I totally get that you want me to figure it out myself. I've been looking at it and playing with adding in the AddChartBubble in the script. To be honest I'm not a coder and have no idea what I'm doing so all of the effort has been fruitless. I've been trying to modify this code with other scripts you have on here for a week, which is why I thought it'd be worth it to come out of the shadows and just finally be a part of the community so I can ask you guys. Would you be able to help me get started as far as charting bubbles to the right with a displacement as with BLT's code with the displacement option? BLT's code is on page 5 of the link you shared and keeps the bubbles in view when you're trading.

If there is any way that you could show me how to do this bubble on the right with the displacement option for one fib line, I can do the rote work of copying that method for all of the rest of them.
 
Last edited:
dojionehundop

dojionehundop

New member
@BenTen - is there any chance you can please help me out by showing me how to do this for only one of the fib numbers? It would be so incredibly helpful
 
dojionehundop

dojionehundop

New member
I found a glitch where when you select "show today only," it shows yesterday over today only fine, and last week over this week only fine. But when you select "show today only" for last month/quarter/year, it shows fibs for all months/quarters/years. Also for day/week, it will show yesterday over today, but ALSO yesterday over 1 year ago from today. If you could help me fix that bug, that would be tremendous
 
Last edited:
dojionehundop

dojionehundop

New member
@BenTen I'm working on it and wondering if you can show me how to add a 'show quarter/year/month only function,' I had all of these on over 6 grids and it caused ToS to crash and reset all of my indicator settings. It must be because of all of the calculations its doing beyond just last quarter/year/month over this quarter/year/month
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@dojionehundop I will take a look and get back to you.
 
N

Ninja Bull

New member
Hi Ben, great work on this script! I myself I'm new with scripting but I was wondering if you can add Bubbles with each Fibonacci Level and price along with the ability to add different colors to each level? Greatly appreciate your help on this one.
 

Top