Thinkorswim Chart Study and Thinkscript Plot Hierarchy

rad14733

Well-known member
VIP
Thinkorswim Chart Study and Thinkscript Plot Hierarchy

Chart study hierarchy within Thinkorswim is one concept that I haven’t found any information on so I had to do some experimenting in order to determine the dirty details… During my research I discovered that hierarchy differs between the chart study panels and thinkscript code itself… I’ll cover the nuances of each here in an effort to shed light on the subject…

Let’s go over the upper chart panel hierarchy first… Have you ever wanted one study to display on top of another rather than vise versa…??? For example, I wanted my Day_Highs_and_Lows indicator lines to be in the background with my chart panel RSI to be in front of most other studies… What I discovered is that the closer to the top of the list a study is, the further in the background that chart layer paints and the closer to the bottom of the study stack a study is, the closer to the foreground that chart layer paints… Either using the up and down arrows in the study controls on the right of the panel or dragging and dropping into the preferred hierarchy achieves this task… The same goes for some but not all studies in the lower chart panel when stacked in a single lower section… The figures below illustrate the difference in stack painting order within chart study panels...


RSI Indicator Under Day_Highs_and_Lows Indicator

wqqtQtW.jpg


RSI Indicator Over Day_Highs_and_Lows Indicator

nBUTWY0.jpg


Now onto plot hierarchy within thinkscript code… The hierarchy is the exact opposite for study and strategy scripts where plots are painted… If the script has more than one plot then hierarchy comes into play… For the example here we’ll cover the Waddah_Attar_Explosion study… In the default code I use the ex and xLine plots were painting behind the histogram which wasn’t the most ideal location for such important components… Within script code the foreground plots need to be at the top of the plot stack and background plots should be at the bottom of the plot stack… By moving the ex and xLine plots to the top of the stack they now paint on top of the histogram… I have my xLine line painting on top of ex to make it easier to see when ex has dipped below xLine which indicates a no trade scenario when settings are correctly calibrated… To accomplish all of this I moved the xLine plot to the top of the stack with xLine directly below ex with the histogram plots at the bottom of the stack… The figures below illustrate the difference in stack painting order within chart study scripts...

ex and xLine Behind Histogram

rOCF83q.jpg


ex and xLine Over Histogram

LqhluSu.jpg


Edited to add: The image above show a No-Trade condition where the white ex line has dipped behind and below the blue xLine, even if the a green bar painted above the lines it would still be a No-Trade condition unless multiple other indicators signal otherwise... And without even seeing the chart I can tell that the instrument is in a stretch of chop, probably downtrend...

I hope someone will find this information helpful… I am forever tweaking thinkscript code and like seeing data plotted and painted in a manner that suits my preferences best… Data is only worthwhile if we can interpret it rapidly and accurately...
 
Last edited:

Splinter

Member
VIP
Hi all,
I was hoping I could find out how to have the moving average line in front of the histogram for easier reading. Is it possible to reorder indicator elements?
I appreciate your time, thanks!
Code:
# Volatility Gauge

# Measures Volatility using price range and plots a stochastic of price range

# Typical Progression: Volatility to trending to low volatilty. (Price may continue trending after low volatility for quite a few bars before expanding again) High Volatility will typically mark a pivot ara low. 

# Mobius

# V01.10.2018

declare lower;

input n = 8;
input AvgType = AverageType.Exponential;


def h = high;
def l = low;
def c = close;
def max = max(h, c[1]);
def min = min(l, c[1]);
def r = max - min;
def hR = highest(r, n);
def lR = lowest(r, n);
def Vol_r = (r - lR) / (hR - lR);

plot avg = MovingAverage(AvgType, Vol_r, n);
     avg.SetPaintingStrategy(PaintingStrategy.Histogram);
     avg.SetLineWeight(3);
     avg.AssignValueColor(if avg < .382 
                          then color.red 
                          else if avg > .618 
                               then color.green 
                               else color.blue);

def hh = highest(h, n);
def ll = lowest(l, n);
plot stoch = MovingAverage(AvgType, (c - ll) / (hh - ll), n);
     stoch.SetLineWeight(2);
     stoch.AssignValueColor(if stoch > stoch[1]
                            then color.green
                            else color.red);

addLabel(1, if avg < .382 
            then "Low Volatility"
            else if avg > .618 
                 then "High Volatility Look for Pivot Low"
                 else "Normal / Trending",
            avg.TakeValueColor());
# End Code Volatility Gauge
 

Similar threads

Top