Convert TradingView Accumulation/Distribution into Thinkorswim


Category:
0
0

Hello Mr Hahn,

Can you please help convert the trading view ” Accumulation-Distribution Line into 200 EMA” for thinkorswim as shown below:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jbneto

//@version=4
study(title="Accumulation/Distribution", shorttitle="Accum/Dist, 200 EMA", overlay=false)
ad = cum(close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume)

plot(ad, title = "Accumulation/Distribution", color=#808000)
plot(ema(ad, 200), color=#FF7000, linewidth=1, title='200 Day EMA')"

 

 

 

Thank you

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 14, 2023 1:54 pm
332 views
0
Private answer

I really have no idea why on earth anyone would think to use a length of 200 on an exponential moving average. That requires 1,400 bars before it's fully computed. Not very smart. So the solution I have presented here includes adjustable inputs so folks can change the moving average type and length.

For those looking for some guidance. Exponential moving averages should be use for lengths less than 50. Anything greater than 50 periods should be set to simple moving average. That's just common sense. But most folks don't understand how exponential moving averages are computed. So I have the following article to help spread the word:

https://www.hahn-tech.com/moving-averages-exponential-problems/

Here is the Thinkorswim version of that code you provided from TradingView:

declare lower;
input maLengthOne = 200;
input maTypeOne = AverageType.EXPONENTIAL;
plot adLine = TotalSum(if close == high and close == low or high == low then 0 else ((2 * close - low - high) / (high - low)) * volume);
plot maOne = MovingAverage(maTypeOne, adLine, maLengthOne);

And one last bit of helpful information. Thinkorswim provides it's own version of Accumulation/Distribution and that study is named: "AccDist". However that study does not include a moving average.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 14, 2023 2:54 pm
0
Thank you Mr Hahn
( at January 14, 2023 3:15 pm)