declare real_size in ThinkOrSwim

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
How To Overlay Indicators Of The Same Scale Onto Lower Charts:

When it comes to overlaying indicators on a lower chart, there are a few things to keep in mind.
If the indicators are not of the same scale, the results can be misleading, even if they look impressive at first glance.
ToS automatically resizes indicator outputs to fit on the chart, which can create a beautiful but ultimately meaningless overlaying pattern.

Even when overlaying studies of the same scale, you may still encounter issues. This is because ToS doesn't automatically recognize that they're the same scale and will still plot them relative to each other, leading to inaccurate results.

But don't worry - there is a solution! If you're overlaying studies of the same scale, simply insert the statement "declare real_size;" into each script, and you should see accurate and reliable results.

Just remember, this technique should not be used with indicators of differing scales.
Bound oscillators with non-comparable scales, need to be normalized to the same scale so they can be analyzed "relative" to each other.
read more here: https://usethinkscript.com/threads/normalized-macd-for-thinkorswim.9502/
WKh9trq.png
 
Last edited by a moderator:
Hello,

While looking at the /NQ futures chart with the Trendilo and ImpulseMACD indicators on it, I decided to overlap the indicators and noticed something interesting. Whenever the main Trendilo plot crossed below the ImpulseSignal line, it indicated a short. Likewise whenever the main Trendilo plot crossed above the ImpulseSignal line, it indicated a long.

The issue with overlapping indicators on TOS is that their positions change when scrolling. To combat that issue, I've attempted to combine the indicators into one (using default settings for both). The issue I'm having is that the Trendilo plot displays as a straight line when it should be anything but. It only displays correctly when I hide the ImpulseSignal line. I need them both to show.

Here's my code:

Code:
declare lower;

input src = hlc3;                 # 'Source'


#-- Trendilo
def Smoothing = 1;                # 'Smoothing'
def Lookback = 50;                # 'Lookback'
def almaOffset = 0.85;            # 'ALMA Offset'
def almaSigma = 6;                # 'ALMA Sigma'
def BandMultiplier = 1.0;         # 'Band Multiplier'
def useCustomBandLength = no;     # 'Custom Band Length ? (Else same as Lookback)')
def CustomBandLength = 20;        # 'Custom Band Length'

script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}

def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch = alma(pch, Lookback, almaOffset, almaSigma);
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def rms = BandMultiplier * Sqrt(Sum(avpch * avpch, blength) / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = Round(avpch, 4);
fplot.SetLineWeight(2);
#fplot.AssignValueColor(if cdir > 0 then Color.GREEN else if cdir < 0 then Color.RED else Color.GRAY);
#-- END OF CODE



#-- Impulse MACD
def lengthMA = 34;
def lengthSignal = 9;

script calc_smma {
    input src = close;
    input len = 34;
    def smma = if isNaN(smma[1]) then SimpleMovingAvg(src, len) else (smma[1] * (len - 1) + src) / len;
    plot return = smma;
}

script calc_zlema {
    input src = close;
    input length = 34;
    def ema1 = ExpAverage(src, length);
    def ema2 = ExpAverage(ema1, length);
    def d    = ema1 - ema2;
    def zelma = ema1 + d;
    plot return = zelma;
}

def hi = calc_smma(high, lengthMA);
def lo = calc_smma(low, lengthMA);
def mi = calc_zlema(src, lengthMA);

def md = if (mi > hi) then (mi - hi) else if (mi < lo) then (mi - lo) else 0;
def sb = SimpleMovingAvg(md, lengthSignal);

#-- plot
plot ImpulseSignal = sb;
ImpulseSignal.SetDefaultColor(Color.WHITE);
ImpulseSignal.SetLineWeight(2);
#-- End Code

Can someone show me what I'm doing wrong?

Thanks in advance.
 
Hello,

While looking at the /NQ futures chart with the Trendilo and ImpulseMACD indicators on it, I decided to overlap the indicators and noticed something interesting. Whenever the main Trendilo plot crossed below the ImpulseSignal line, it indicated a short. Likewise whenever the main Trendilo plot crossed above the ImpulseSignal line, it indicated a long.

The issue with overlapping indicators on TOS is that their positions change when scrolling. To combat that issue, I've attempted to combine the indicators into one (using default settings for both). The issue I'm having is that the Trendilo plot displays as a straight line when it should be anything but. It only displays correctly when I hide the ImpulseSignal line. I need them both to show.

Here's my code:

Code:
declare lower;

input src = hlc3;                 # 'Source'


#-- Trendilo
def Smoothing = 1;                # 'Smoothing'
def Lookback = 50;                # 'Lookback'
def almaOffset = 0.85;            # 'ALMA Offset'
def almaSigma = 6;                # 'ALMA Sigma'
def BandMultiplier = 1.0;         # 'Band Multiplier'
def useCustomBandLength = no;     # 'Custom Band Length ? (Else same as Lookback)')
def CustomBandLength = 20;        # 'Custom Band Length'

script ALMA {
    input series = close;
    input windowsize = 9;
    input Offset = 0.85;
    input Sigma = 6;
    def m = Offset * (windowsize - 1);
    def s = windowsize / Sigma;
    def norm  = fold z = 0 to windowsize with CW do
         CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
    def sum  = fold y = 0 to windowsize with WS do
         WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
    plot ALMA = sum  / norm ;
}

def change = src - src[Smoothing];
def pch = change / src * 100;
def avpch = alma(pch, Lookback, almaOffset, almaSigma);
def blength = if useCustomBandLength then CustomBandLength else Lookback;
def rms = BandMultiplier * Sqrt(Sum(avpch * avpch, blength) / blength);
def cdir = if avpch > rms then 1 else if avpch < -rms then -1 else 0;

#-- plot
plot fplot = Round(avpch, 4);
fplot.SetLineWeight(2);
#fplot.AssignValueColor(if cdir > 0 then Color.GREEN else if cdir < 0 then Color.RED else Color.GRAY);
#-- END OF CODE



#-- Impulse MACD
def lengthMA = 34;
def lengthSignal = 9;

script calc_smma {
    input src = close;
    input len = 34;
    def smma = if isNaN(smma[1]) then SimpleMovingAvg(src, len) else (smma[1] * (len - 1) + src) / len;
    plot return = smma;
}

script calc_zlema {
    input src = close;
    input length = 34;
    def ema1 = ExpAverage(src, length);
    def ema2 = ExpAverage(ema1, length);
    def d    = ema1 - ema2;
    def zelma = ema1 + d;
    plot return = zelma;
}

def hi = calc_smma(high, lengthMA);
def lo = calc_smma(low, lengthMA);
def mi = calc_zlema(src, lengthMA);

def md = if (mi > hi) then (mi - hi) else if (mi < lo) then (mi - lo) else 0;
def sb = SimpleMovingAvg(md, lengthSignal);

#-- plot
plot ImpulseSignal = sb;
ImpulseSignal.SetDefaultColor(Color.WHITE);
ImpulseSignal.SetLineWeight(2);
#-- End Code

Can someone show me what I'm doing wrong?

Thanks in advance.
https://usethinkscript.com/threads/declare-real_size-in-thinkorswim.14506/#post-119945
 
@SleepyZ @Sammy800 @MerryDay
I have been using a combination of AccumDistrBuyPr and SchocasticSlow from Thinkorswim in a lower chart to infer lows. see attached (inserted)

1742508637746.png


While it is easier to overlay these on a chart, I am having difficulties combining the codes to work for a scan. I did use the traditional thinkorswim scan filter
1742508790052.png

Basically, I ask for a scan when the accumdistrBuyPr line coincides with the 0 or less than 1 line of Scholastic slow when the OS % is set to 1.

This works, but the problem is I still get tickers in the scan that in no way meets the criteria.
Could you help check, what am I doing wrong.

Thanks
 
@SleepyZ @Sammy800 @MerryDay
I have been using a combination of AccumDistrBuyPr and SchocasticSlow from Thinkorswim in a lower chart to infer lows. see attached (inserted)

View attachment 24332

While it is easier to overlay these on a chart, I am having difficulties combining the codes to work for a scan. I did use the traditional thinkorswim scan filter

Basically, I ask for a scan when the accumdistrBuyPr line coincides with the 0 or less than 1 line of Scholastic slow when the OS % is set to 1.

This works, but the problem is I still get tickers in the scan that in no way meets the criteria.
Could you help check, what am I doing wrong.

Thanks


Your indicators are of different scales.
The AccumDistBuyPr is a tiny little elf
The StochasticSlow is a jolly green giant
As you can see from the number scale on the right-side of the chart
d1KZI3j.png


When you asked ToS to stuff them into the same lower chart.
It produced a lower chart that does not exist in reality.

Here is what they really look like in reality, when stuffed into the same lower chart using function:
declare real_size;

vXEe3yD.png


Bound oscillators can be normalized to the same scale, so they can be analyzed "relative" to each other.

Sadly, AccumDistBuyPr is an unbound oscillator (it has no consistent upper and lower boundary); which means that is cannot be normalized.

Conclusion: there is no relative movement between Stoch and AccumDist that can be analyzed.

Read through the whole above thread to learn more about overlaying indicators into the same lower chart.
 
Last edited:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
282 Online
Create Post

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