Drawdown Indicator for ThinkorSwim

evanevans

Active member
I have an obsession with stocks that have gorgeous charts. :) And one of the factors that makes a chart "gorgeous" to me, is that is has a strong trend coupled with low volatility and high performance. Some excellent examples are the daily charts on MSFT and LULU to name a few. Aside from pandemics and giant market pullbacks, those stocks have great resiliency, and when they consolidate, they go sideways, not down.

One of the ways you can visually see how resilient a stock is over time, is by checking it's drawdowns in %.

I searched around the web and forum for a ThinkScript indicator to show drawdown %, and could not find that anyone has created a drawdown % indicator. It's an excellent indication of risk and volatility. When you divide the return over time by the risk over the same time, you get the Sortino ratio, which is a measure of how much reward you are getting for your risk. So, being able to see drawdown in relationship with a stock which is ripping and roaring can help you know if it's a good or poor opportunity. No matter what timeframe you are on, being able to visualize it, can really help you assess if you want to get into the position or not.

Now, in my mind, there are two ways to display this.

One, is how you would see it on portfolio manager's risk charts. A zero line represents days where it's making new highs. Anytime price drops below the all time high, it becomes subtracted and shown in percent from high, in the indicator.

Two, is on the chart itself, as a cloud above any lower price action. Essentially, new highs dictate the new level, and anytime price goes under the recent high, a cloud level remains above it, almost like the stock is going underwater.

If anyone is keen on giving a try at coding this, I'm happy to work with you on it ... in concept. I am not a very skilled programmer. I could probably figure this out, and will try this weekend if no one steps forward, but it'd be great if anyone had the interest and talent to help code it.

Looking forward to seeing how far this goes!
 
Last edited:
@evanevans Here's something, maybe. I'm not a skilled/professional programmer either, but the idea was interesting, and I had spare time. :D

Code:
#Drawdown Cloud with Label

def hh = if high > hh[1] then high else hh[1];
plot line = hh;
     line.setdefaultcolor(color.gray);
AddCloud(line,high,color.gray,color.gray);

def h = HighestAll(high);
def below = (h - close)/h;
addlabel(1, "% Below High = " + AsPercent(below), color.light_gray);

#end code

Zg5wnlL.png
 
@Pensar really nice work. This made me realize, that it could also be a really cool POSITION PROFIT/LOSS indicator. Unrealized Profit would be a green cloud below rising price from the point of origin (your order and price), and unrealized loss moments would be a red cloud above falling prices from the point of origin (order).

What do you think about that? You just go by Average fill position price.
 
partially, i havent looked at it in about a month as ive been working on another project, ill get back to this soon though to finish it up.
 
don't know where i got this -- this site, prolly -- but here's a label for current drawdown, with input for number of days to look back:

Code:
#HINT: This chart label shows the percent change down from the high.above \n\n IMPORTANT: If a new IPO you need to change the length to max of number of days since IPO release.

input length = 252;  #HINT length: There are 252 trading days in a year
input show_label = yes;
input Label_Color_Choice = {"magenta", "green", "pink", "cyan", "orange", default "red", "blue", "gray", "violet"};

def top = highest(high(period = AggregationPeriod.DAY), length);
def prctDrop = ((close(period = AggregationPeriod.DAY)/top)-1);

def NewHigh = high == top;

AddLabel(show_label and !NewHigh, "Percent down off high: ( " +  AsPercent(prctDrop) + " )  ", GetColor(Label_Color_Choice));
 
Working out some bugs, just built it over the weekend. Going to test it this week before releasing code.

Here's a preview. any other ideas before I release it? @evanevans

aG8kdvT.png
Hey, good work. I would say that it doesn't look fully like a typical drawdown chart, in that as you can see in the stock chart, it's clearly up trending. That usually produces periods where there is no drawdown "fill". But very clever for sure, and I like that you approached it from the LOW. Those can definitely be options on it. Well done. Let me know when you've got the code up. Best, Evan Evans.
 
Last edited by a moderator:
i think this might work i combined everything that was put here.

Fs4Z2fp.png

Code:
declare lower;

declare lower;

input n= 21;

def hh = if high > hh[1] then high else hh[1];
 
def h = HighestAll(high);
def below = (h - close)/h;
addlabel(1, "% Below High = " + AsPercent(below), color.light_gray);
plot zerloline= 0;

plot drwdown= close-hh;

AddCloud(drwdown,zerloline,color.red);
drwdown.setDefaultColor(color.yellow);

plot average= inertiaAll(drwdown);
 
Last edited:
Hey, good work. I would say that it doesn't look fully like a typical drawdown chart, in that as you can see in the stock chart, it's clearly up trending. That usually produces periods where there is no drawdown "fill". But very clever for sure, and I like that you approached it from the LOW. Those can definitely be options on it. Well done. Let me know when you've got the code up. Best, Evan Evans.
yes from the low would be considered MAX Drawdown for that bar and from the Close would be the drawdown from the closing price. I just have to finish up the labels and clean up the code, i havent worked on it in a while, i start something and then something else pops up or i get sidetracked. ill try to finish it this week.
 
i think this might work i combined everything that was put here.

Fs4Z2fp.png

Code:
declare lower;

declare lower;

input n= 21;

def hh = if high > hh[1] then high else hh[1];

def h = HighestAll(high);
def below = (h - close)/h;
addlabel(1, "% Below High = " + AsPercent(below), color.light_gray);
plot zerloline= 0;

plot drwdown= close-hh;

AddCloud(drwdown,zerloline,color.red);
drwdown.setDefaultColor(color.yellow);

plot average= inertiaAll(drwdown);
That looks correct. However, when I tried it on SPX, the numbers were too big (ie: 300%+). Perhaps something isn't mapping as percent correctly?
 
Hi @germanburrito can you please share the code for gann fan? The code you have gave me for gann angle does repaint a bit. Do you have any solution for that? Thank you very much in advance.

There is no real solution to repainting for any indicator that repaints... You can try larger timeframes or basing indicators off the previous candle/bar but that defeats the overall purpose of some indicators... And some indicators even repaint several candles/bars after painting...
 
There is no real solution to repainting for any indicator that repaints... You can try larger timeframes or basing indicators off the previous candle/bar but that defeats the overall purpose of some indicators... And some indicators even repaint several candles/bars after painting...
Yes, you are right. Thank you for your quick reply.
 
i think this might work i combined everything that was put here.

Fs4Z2fp.png

Code:
declare lower;

declare lower;

input n= 21;

def hh = if high > hh[1] then high else hh[1];

def h = HighestAll(high);
def below = (h - close)/h;
addlabel(1, "% Below High = " + AsPercent(below), color.light_gray);
plot zerloline= 0;

plot drwdown= close-hh;

AddCloud(drwdown,zerloline,color.red);
drwdown.setDefaultColor(color.yellow);

plot average= inertiaAll(drwdown);
Hey @germanburrito thank you so much for this, have been using it the past few weeks and I'm loving it. I am in the process of coding a strat but for the life of me I am not sure how to convert the y-axis into percent, is that possible? Sorry, I'm still learning bit by bit any help would be great.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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