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:

Pensar

Well-known member
VIP
@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
 

evanevans

Active member
@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.
 

XeoNoX

Well-known member
VIP
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.
 

floydddd

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

evanevans

Active member
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:

germanburrito

Active member
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:

XeoNoX

Well-known member
VIP
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.
 

evanevans

Active member
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?
 

rad14733

Well-known member
VIP
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...
 

astro_phx

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

Ghostwar19

Member
VIP
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.
 
Thread starter Similar threads Forum Replies Date
K Opening Range Breakout Indicator with Fibs Questions 1
C Divergence indicator using Fold not working correctly Questions 1
T Upside down Plots for indicator Questions 8
C Price Action Indicator Questions 3
D Best Reversal Indicator? Questions 1

Similar threads

Top