Williams AD Indicator with Moving Average Crossover for ThinkorSwim

R

RyanC

New member
thinkorswim does have a "WilliamsAD" study but it is missing the simple moving average and does not show crossovers.


Code:
declare lower;

input length = 20;

plot ad = AccumDistBuyPr();
plot smoothed = SimpleMovingAvg(ad, length=length);

smoothed.AssignValueColor(Color.WHITE);

ad.DefineColor("Up", Color.GREEN);
ad.DefineColor("Down", Color.RED);
ad.AssignValueColor(if ad > smoothed then ad.color("Up") else ad.color("Down"));
 
markos

markos

Well-known member
VIP
Warehouse
Try this, hopefully you can customize it. Generally, if TOS takes something out, it is because the Citizen CMT's asked for it that way when it was built. Sometimes it can be an error that gets thrown because of the original programming.
Did you check Williams books or papers to see if he had a preference? I'm just asking as I don't know.
This is an old version from what I can tell. Let us know what's going on. Thanks!
Code:
#
# thinkorswim, inc. (c) 2007
#

declare lower;

input length = 57;
input displace = 0;

def clMax = Max(close[1], high);
def clMin = Min(close[1], low);

def result = TotalSum(if close > close[1] then close - clMin else if close < close[1] then close - clMax else 0);

def ad_ma = Average(data = result[-displace], length = length);

plot WAD = result;
WAD.SetDefaultColor(GetColor(1));
WAD.HideBubble();

plot ADMA = ad_ma;
ADMA.SetDefaultColor(CreateColor(153,153,0));
ADMA.HideBubble();
Some notes from ThinkScript Lounge August 1, 2018:
14:30 Mobius: Scan for WilliamsAd is

AccumDistBuyPR() crosses above 0

14:30 Mobius: or below 0 or > 0 or < 0 whatever floats your boat
14:31 Mobius: if you use crosses it'd be best for it to be a dynamic watchlist scan
14:32 KC_Mama: Thank you everyone! I think I can do it now.
14:33 Mobius: lol it was just provided for you what's to do
14:34 KC_Mama: LOL!
14:34 Mobius: WillimsAD is the same code as AccumDistBuyPr() in TOS The WilliamsAD just references that code
14:36 Nube: Drats, now I gotta check to see if we can pass arguments to AccumDistBuyPr()
14:37 Nube: But also nice to know.
14:37 Mobius: What won't make sense to you is that when you get a signal from the scanner it's looking at the TotalSum of bars in a fixed range that may of may not match your charts range.
 
Last edited:
R

RyanC

New member
No, I could not find it in thinkorswim so I added the missing SMA to it with crossover colors. 57 might be the default value in books.
 
H

horserider

Well-known member
VIP
Warehouse
Markos gave you the code. It is also in ToS named "AccumDistBuyPr "
 
T

tomsk

Well-known member
VIP
Warehouse
It is interesting to note that in the study that @markos posted above, a length of 57 was used in the Williams AD moving average, must be some sort of default period

I have cobbled up a simple version of the Williams AD based on the ThinkorSwim standard Williams AD study
Added a simple moving average of the 57 period, as well as added vertical lines that signify whenever a cross up or cross down occurred
Note that the simple moving average line is color coded depending on whether it is above or below the calculated Williams AD line

Here's the code

Code:
# Williams AD
# tomsk
# 11.26.2019

declare lower;

input MAlength = 57;

plot WAD = AccumDistBuyPr();
plot ZeroLine = 0;
WAD.SetDefaultColor(Color.Orange);
ZeroLine.SetDefaultColor(GetColor(5));

plot SMA = Average(WAD, MAlength) ;
SMA.SetDefaultColor(Color.Orange);
SMA.AssignValueColor(if SMA > WAD then Color.Green else Color.Red);

AddVerticalLine(WAD crosses above SMA, "Cross Up", Color.Green, Curve.Points);
AddVerticalLine(WAD crosses below SMA, "Cross Down", Color.Yellow, Curve.Points);
# End Williams AD
 
Last edited:
markos

markos

Well-known member
VIP
Warehouse
Hey @tomsk That script at the top was something either I found or JQ scrounged up. Being from 2007, it predates TDA.
Curious as to the 57 DMA, I have no idea why it's there. Didn't Williams trade Commodities mostly?
 
T

tomsk

Well-known member
VIP
Warehouse
@markos For some reason even a Williams AD script that BLT posted in 2016 also used the 57 period.
It must be some sort of default that is generally used
 
markos

markos

Well-known member
VIP
Warehouse
@tomsk if you are inclined to, could you, someday, ask BLT under what conditions, time frame, etc. he used it? Curious to know. ;)
 
T

tomsk

Well-known member
VIP
Warehouse
@markos I will do so the next time when we exchange holiday pleasantries. Knowing his trading style, it was probably written for some user requester who had specific requirements
 
T

tomsk

Well-known member
VIP
Warehouse
@markos, as a follow up I did check in with him over the holidays, says he just used whatever period the requester had indicated for that Williams AD.
 
markos

markos

Well-known member
VIP
Warehouse
@tomsk thanks for asking. We appreciate the follow up!
 

Top