DeMark Relative Retracement Levels Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
A member of ours just converted the DeMark Relative Retracement Levels indicator from TradingView to ThinkorSwim. Sharing it here with everyone else.

This indicator finds the previous days high, and low and today's open using daily timeframe and then applies the Fibonacci .382* and *.618 to them. Four different retracement levels will be added to your chart. You can anticipate reversals or breaks at these levels.

Here is the $SBUX 5min chart. See how well the candles respect those support and resistance lines?

3YyP0f4.png


thinkScript Code

Rich (BB code):
#
# WalkingBallista
#
input aggregationPeriod = AggregationPeriod.DAY;

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
def PO = open(period = aggregationPeriod);

def range = PH - PL;
def a = range * 0.382;
def b = range * 0.618;

plot h = PO + a;
plot h1 = PO + b;
plot l = PO - a;
plot l1 = PO - b;

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);

l.DefineColor("Color", Color.Dark_Green);
l.AssignValueColor(l.color("Color"));
l.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

l1.DefineColor("Color", Color.Green);
l1.AssignValueColor(l1.color("Color"));
l1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Shreable Link

https://tos.mx/e9Qoy8

Credits
  • TradingView version
  • Special shoutout to one of our Discord members, WalkingBallista, for converting the script to ThinkorSwim.
 
Last edited:

Antares66

Member
This is a great great indicator. I have tried to use it on tick charts with an indicator setting of 4 hours but get no results. When setting the indicator to daily, weekly and monthly it is plotted on the tick chart but not with the setting 4 hours. Does someone know the reason for that?
On time based charts the indicators shows up with a 4 hours setting.
 

tradebyday

Active member
This is a great great indicator. I have tried to use it on tick charts with an indicator setting of 4 hours but get no results. When setting the indicator to daily, weekly and monthly it is plotted on the tick chart but not with the setting 4 hours. Does someone know the reason for that?
On time based charts the indicators shows up with a 4 hours setting.
It is because it is a tick chart. Tick charts do not use time aggregation so therefore you will experience issues like this when trying to use a tool on a MTF basis overlaying a tick chart, the best way around this may be by including the full formula for however the indicator is calculated (VWAP does this which may be why it works seamlessly on tick charts) then it may be able to use the chart data still to portray the indicator as you wish. I can not confirm this would actually work though. Just a theory
 

Welkin

Active member
I made something similar, but instead of applying fib ratios to the prior day's high - low range, it instead uses the prior day's ATR / 2 and is added and subtracted from the day's open, then using the ATR's range, fib ratios are used to plot fibonacci lines:

https://tos.mx/1viZGHN

juh9hA4.png

Code:
#[email protected]
#Plots Upper and Lower lines based on the ATR onto the current day's open with fib ratios
def NA = Double.NaN;
input length = 14;
input averageType = AverageType.WILDERS;
input Agg1 = AggregationPeriod.DAY;
input ShowFibRatios = yes;

def TR1 = high("period" = Agg1) - low("period" = Agg1);
def TR2 = AbsValue(high("period" = Agg1) - close("period" = Agg1)[1]);
def TR3 = AbsValue(low("period" = Agg1) - close("period" = Agg1)[1]);
def TrueRange = if TR1 > TR2 and TR1 > TR3 then TR1 else if TR2 > TR1 and TR2 > TR3 then TR2 else TR3;

def ATR1 = MovingAverage(averageType, TrueRange, length);

plot ATR1H = open("period" = Agg1) + (ATR1[1] / 2);
plot ATRp50 = open("period" = Agg1) + (ATR1[1]);
plot ATR50 = open("period" = Agg1);
plot ATRn50 = open("period" = Agg1) - (ATR1[1]);
plot ATR1L = open("period" = Agg1) - (ATR1[1] / 2);

def ATRange = ATR1H - ATR1L;
plot ATR236 =if !ShowFibRatios then NA else  ATR1H - (ATRange * .236);
plot ATR382 =if !ShowFibRatios then NA else  ATR1H - (ATRange * .382);
plot ATR618 =if !ShowFibRatios then NA else  ATR1H - (ATRange * .618);
plot ATR786 =if !ShowFibRatios then NA else  ATR1H - (ATRange * .786);

plot ATRm236 =if !ShowFibRatios then NA else  ATR1L + (ATRange * .236);
plot ATRm786 =if !ShowFibRatios then NA else  ATR1L + (ATRange * .786);

plot ATRp236 =if !ShowFibRatios then NA else  ATR1H + (ATRange * .236);
plot ATRp382 =if !ShowFibRatios then NA else  ATR1H + (ATRange * .382);
plot ATRp618 =if !ShowFibRatios then NA else  ATR1H + (ATRange * .618);
plot ATRp786 =if !ShowFibRatios then NA else  ATR1H + (ATRange * .786);

plot ATRn236 =if !ShowFibRatios then NA else  ATR1L - (ATRange * .236);
plot ATRn382 =if !ShowFibRatios then NA else  ATR1L - (ATRange * .382);
plot ATRn618 =if !ShowFibRatios then NA else  ATR1L - (ATRange * .618);
plot ATRn786 =if !ShowFibRatios then NA else  ATR1L - (ATRange * .786);


ATR1H.SetDefaultColor(Color.MAGENTA);
ATR1L.SetDefaultColor(Color.MAGENTA);

ATR50.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRp50.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRn50.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR1H.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR1L.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATR236.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR382.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR618.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR786.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRp236.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRp382.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRp618.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRp786.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


ATRm236.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRm786.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


ATRn236.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRn382.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRn618.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRn786.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATR1H.SetDefaultColor(Color.MAGENTA);
ATR1L.SetDefaultColor(Color.MAGENTA);
ATRp50.SetDefaultColor(Color.WHITE);
ATRn50.SetDefaultColor(Color.WHITE);
ATR50.SetDefaultColor(Color.WHITE);
ATR236.SetDefaultColor(Color.DARK_GRAY);
ATR382.SetDefaultColor(Color.DARK_GRAY);
ATR618.SetDefaultColor(Color.DARK_GRAY);
ATR786.SetDefaultColor(Color.DARK_GRAY);

ATRm236.SetDefaultColor(Color.DARK_GRAY);
ATRm786.SetDefaultColor(Color.DARK_GRAY);

ATRn236.SetDefaultColor(Color.DARK_GRAY);
ATRn382.SetDefaultColor(Color.DARK_GRAY);
ATRn618.SetDefaultColor(Color.DARK_GRAY);
ATRn786.SetDefaultColor(Color.DARK_GRAY);

ATRp236.SetDefaultColor(Color.DARK_GRAY);
ATRp382.SetDefaultColor(Color.DARK_GRAY);
ATRp618.SetDefaultColor(Color.DARK_GRAY);
ATRp786.SetDefaultColor(Color.DARK_GRAY);
 
Last edited by a moderator:

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.
Top