Williams % R Crossover Scan, Watchlist, Labels For ThinkOrSwim

poparhon

New member
Need help in plotting the -50 into the code, a dashed black line ,appreciate any help Thanks
Code:
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

declare lower;

input length = 10;
input overBought = -20;
input overSold = -80;

def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

plot WR = if result > 0 then 0 else result;
WR.SetDefaultColor(GetColor(1));

plot Over_Sold = overSold;
Over_Sold.SetDefaultColor(GetColor(8));

plot Over_Bought = overBought;
Over_Bought.SetDefaultColor(GetColor(8));
 

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

Add this to the end of the script:
Code:
plot negative_fifty = -50;
 
Looking for some assistance in adding the overbought and oversold clouds to the W%R. On the overbought from the 0 to -20 and oversold from -80 to -100. On the same idea as the RSI Lagueere or TMO Thanks

PiEVbWZ.png


Code:
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

declare lower;

input length = 10;
input overBought = -20;
input overSold = -80;

def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

plot WR = if result > 0 then 0 else result;
WR.SetDefaultColor(GetColor(1));

plot Over_Sold = overSold;
Over_Sold.SetDefaultColor(GetColor(8));

plot Over_Bought = overBought;
Over_Bought.SetDefaultColor(GetColor(8));

plot negative_fifty = -50;
plot negative_onehundred = -100;
plot zerobase = 0;
 
Add the following snippet to the end of your script:

Code:
AddCloud(zerobase, Over_bought);
AddCloud(over_sold, negative_onehundred);

Use it as a baseline for your whichever indicator you hope to do the same for.
 
Similar to the Savage Oscillator Arrows (Stand Alone Arrows) - https://usethinkscript.com/threads/savage-oscillator-for-thinkorswim.4214/

Was wondering if anyone is able to create a Williams Percent Stand Alone Arrows - Arrow up when it hits a certain number (negative_onehundred or if you can just manually plot it to any number) and an Arrow down when it hits a certain number (zerobase or if you can just manually plot to any number)?

I took a stab at this myself but I had a gazillion arrows and lines flying off my screen and into my living reality to where you could literally touch them -- it was a scene man. Alright, thanks in advance

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

declare lower;

input length = 10;
input overBought = -10;
input overSold = -90;

def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

plot WR = if result > 0 then 0 else result;
WR.SetDefaultColor(GetColor(1));

plot Over_Sold = overSold;
Over_Sold.SetDefaultColor(GetColor(8));

plot Over_Bought = overBought;
Over_Bought.SetDefaultColor(GetColor(8));

plot negative_fifty = -50;
plot negative_onehundred = -100;
plot zerobase = 0;

AddCloud(zerobase, Over_bought);
AddCloud(over_sold, negative_onehundred);
 
Add this to the bottom of your script:

Code:
def condition1 = WR crosses below over_bought;
def condition2 = WR crosses above over_sold;

plot bearish = if condition1 then over_bought else double.nan;
plot bullish = if condition2 then over_sold else double.nan;

bullish.SetDefaultColor(Color.UPTICK);
bullish.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bearish.SetDefaultColor(Color.DOWNTICK);
bearish.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
I'm really bad at coding, I've been trying to figure out how to do this by looking at other code with buy/sell arrows but I can't get it to work. Basically I just need an up arrow when the %R crosses above oversold and a down arrow when %R crosses below overbought. I would also like the option to change the color of the arrows and also the option to plot them or not, but these two are really not necessary. The arrows are the most important part.

Here's my attempt, top half is the copy/pasted W%R and the bottom half is my attempt :

Code:
declare lower;

input length = 10;
input overBought = -20;
input overSold = -80;

def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

plot WR = if result > 0 then 0 else result;
WR.SetDefaultColor(GetColor(1));

plot Over_Sold = overSold;
Over_Sold.SetDefaultColor(GetColor(8));

plot Over_Bought = overBought;
Over_Bought.SetDefaultColor(GetColor(8));

#My code-------------

plot UpSignal;
plot DownSignal;
UpSignal = if WR > overBought;
DownSignal = if WR < overSold;

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Last edited:
The TOS plot statement is used to state where you want the arrow to plot an example would be:
Ruby:
plot UpSignal = if WR > overBought then WR  else Double.NaN ;
plot DownSignal = if WR < overSold then WR else Double.NaN ;

You already have the ability to change color or plot your arrows. Click on the gear icon next to the study in your chart. Unclick plot if you don't want to plot. Click on the color to change the color.
 
Last edited:
The TOS plot statement is used to state where you want the arrow to plot an example would be:
Ruby:
plot UpSignal = if WR > overBought then WR  else Double.NaN ;
plot DownSignal = if WR < overSold then WR else Double.NaN ;

You already have the ability to change color or plot your arrows. Click on the gear icon next to the study in your chart. Unclick plot if you don't want to plot. Click on the color to change the color.
Thanks for the response dude, but that code didn't work for me. It came out looking like this after I fixed the parameters:
RgwEUvT.png


This was the code I added:
Code:
plot UpSignal = if WR > overSold then WR  else Double.NaN ;
plot DownSignal = if WR < overBought then WR else Double.NaN ;

The first issue was obviously it being highlighted everywhere. Second issue was it didn't even turn red after the crossunders like before 6:35 and at 6:45, and thirdly it isn't an up/down arrow it just highlights the line. So I tried something like this:
Code:
plot UpSignal = if WR crosses above overSold then WR  else Double.NaN ;
plot DownSignal = if WR crosses below overBought then WR else Double.NaN ;

That didn't work either. Then finally I tried this:
Code:
plot ARROW_UP = if WR crosses above overSold then WR  else Double.NaN ;
plot ARROW_DOWN = if WR crosses below overBought then WR else Double.NaN ;

And this didn't work either. So I don't really know what to do. For reference, here's the whole code:
Code:
declare lower;

input length = 10;
input overBought = -20;
input overSold = -80;

def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

plot WR = if result > 0 then 0 else result;
WR.SetDefaultColor(GetColor(1));

plot Over_Sold = overSold;
Over_Sold.SetDefaultColor(GetColor(8));

plot Over_Bought = overBought;
Over_Bought.SetDefaultColor(GetColor(8));

#My code below-----

plot ARROW_UP = if WR crosses above overSold then WR  else Double.NaN ;
plot ARROW_DOWN = if WR crosses below overBought then WR else Double.NaN ;
 
@fungus12
Code:
declare lower;

input length = 10;
input overBought = -20;
input overSold = -80;
input plot_up = yes;
input plot_dn = yes;

def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

plot WR = if result > 0 then 0 else result;
WR.SetDefaultColor(GetColor(1));

plot Over_Sold = overSold;
Over_Sold.SetDefaultColor(GetColor(8));

plot Over_Bought = overBought;
Over_Bought.SetDefaultColor(GetColor(8));

#My code below-----

plot ARROW_UP = if plot_up and WR crosses above overSold then overSold else Double.NaN ;
plot ARROW_DOWN = if plot_dn and WR crosses below overBought then overBought else Double.NaN ;

ARROW_UP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ARROW_DOWN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Hello,

I have placed a "Buy Custom" "With Bracket OCO" order for VXX when the WR crosses above -80 Buy, when WR crosses below the -20 Sell.

I created a link but i don't think it gives all the details, let me know if it does - http://tos.mx/2rbXmhD

In this order i have the Buy trigger set to Study - Williams R and if i edit that in thinkScript Editor it comes out to this

WilliamsPercentR()."WR" crosses above WilliamsPercentR()."Over_Sold"

Now if i try to modify that to something like this

Ruby:
input lengthIntraday = 1;
input lengthDaily = 1;
plot data;
if GetAggregationPeriod() < AggregationPeriod.DAY {
    data = Average(close, lengthIntraday);
} else {
    data = Average(close, lengthDaily);
}

WilliamsPercentR()."WR" crosses above WilliamsPercentR()."Over_Sold"

It gives me an error.

How do i make this Buy Trigger look the williams R indicator on a 1 min candle timeline?
also what time frame/timeline does it look at by default?

Thanks!
 
Update: Corrected script, less cumbersome image.

I keep coming back and throw this on my charts, thought I'd share and try to give back something.

Basically provides some color coded wedges whenever we cross over bought, oversold and midpoint.

I mainly trade daily charts end of day so I'm one of those with a messy chart but the decision to Buy Sell or Hold can be made at a glance (30 sec)

The cross overs add a warm fuzzy feeling to confirm a buy or sell signal when they're in sync.

Also added a label of current status, Overbought Oversold above below -50 etc
You can turn labels on or off, set length, midpoint, overbought, oversold and if you want to trade them or not ( turns on/off oversold, overbought, and midpoint.

Originally I had this code in a trade strategy, mainly as a fail-safe to sell at midpoint.

Not a coder per say so any thoughts for improvement




Code:
# Williams %R Trader
#Mod: atcsam 04/19/22

input length = 10;
input overBought = -20;
input overSold = -80;
input midpoint = -50;
input Label = Yes;
input TradeMidpoint = Yes;
input TradeOverBought = Yes;
input TradeOverSold = Yes;


def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);

def WR = if result > 0 then 0 else result;


## Midpoint
def BuyMidX = if WR crosses above midpoint and TradeMidpoint then midpoint else  Double.NaN;


def SellMidX = if WR crosses below midpoint and TradeMidpoint then midpoint else Double.NaN;

plot AboveMid = BuyMidX;
AboveMid.SetDefaultColor(Color.WHITE);
AboveMid.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);


plot BelowMid = SellMidX;
BelowMid.SetDefaultColor(Color.WHITE);
BelowMid.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

## OverBought

def BuyOverBoughtX = if WR crosses above overBought and TradeOverBought then overBought else  Double.NaN;

def SellOverBoughtX = if WR crosses below overBought and TradeOverBought then overBought else  Double.NaN;


plot AboveOB = BuyOverBoughtX;
AboveOB.SetDefaultColor(Color.YELLOW);
AboveOB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);


plot BelowOB = SellOverBoughtX;
BelowOB.SetDefaultColor(Color.YELLOW);
BelowOB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

## OverSold

def BuyOverSoldX = if WR crosses above overSold and TradeOverSold then overSold else  Double.NaN;

def SellOverSoldX = if WR crosses below overSold and TradeOverSold then overSold else  Double.NaN;


plot AboveOS = BuyOverSoldX;
AboveOS.SetDefaultColor(Color.CYAN);
AboveOS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);


plot BelowOS = SellOverSoldX;
BelowOS.SetDefaultColor(Color.CYAN);
BelowOS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

# Labels

AddLabel (yes, if Label then " W%R:" else "", Color.WHITE);

AddLabel (yes, if Label and (WR > -20) and (WR > WR[1]) then "Over Bought Rising " else if Label and (WR > -20) and (WR < WR[1]) then "Over Bought Falling" else
if (WR < -80) then "Over Sold" else "", if (WR > -20) then Color.YELLOW else if (WR < -80) then Color.LIGHT_GREEN else Color.LIGHT_GRAY );

AddLabel(yes, 
if ((WR > -50  and WR < -20) and (WR > WR[1])) then "Above 50 & Rising" else 
if ((WR > -50  and WR < -20) and (WR < WR[1])) then "Above 50 & Falling" else 
if ((WR < -50 and WR > -80) and (WR < WR[1])) then "Below 50 & Falling" else
if ((WR < -50 and WR > -80) and (WR > WR[1])) then "Below 50 & Rising" else
"",

if ((WR > -50) and (WR > WR[1])) then Color.GREEN else  
if ((WR > -50) and (WR < WR[1])) then Color.PINK else  
if ((WR < -50) and (WR < WR[1])) then Color.LIGHT_RED else
if ((WR < -50) and (WR > WR[1])) then Color.LIME else
Color.RED);

TQQQ
Basicichart indicator only. You can see Cyan Hats (Oversold) alternating on its way down, crossing below oversold again today. Downtrend started when it bounced in out of overbought, into overbought (yellow wedges) , below midpoint (white wedge), bouncing oversold remainder of the way down.

HKQybncjSDPw0?width=1920&height=1080&cropmode=none.png
 
Last edited:
Hi atc,

Not able to load. I get a script error on line 34 (plot BelowMid = Sell Midx;) says no such variable on both.
 
Hi atc,

Not able to load. I get a script error on line 34 (plot BelowMid = Sell Midx;) says no such variable on both.
My apologies, Just updated script. Direct copy and paste from TOS. Might contain some unused code/comments.
 
Refer to Post:
https://usethinkscript.com/threads/williams-r-crossover-for-thinkorswim.11011/

Is it possible to modify the following script to use as a watchlist script with the over bought cross (-10) being shown as a Red color; the over sold cross (-90_ being a green bar and have a neutral color (white) for when no cross is occurring? Thank you for taking a look.

# Williams %R Trader
#Mod: atcsam 04/19/22

input length = 10;
input overBought = -20;
input overSold = -80;
input midpoint = -50;
input Label = Yes;
input TradeMidpoint = Yes;
input TradeOverBought = Yes;
input TradeOverSold = Yes;


def hh = Highest(high, length);
def ll = Lowest(low, length);
def result = if hh == ll then -100 else (hh - close) / (hh - ll) * (-100);
 
What would be the correct logic to identify a "double tap" of the Williams indicator? Something that approached and may or may not fully cross over the -80 line. I was thinking I could look for slope changes from positive to negative along with a peak value that was say greater than -70?

y90hDMv.png
 
Last edited:
What would be the correct logic to identify a "double tap" of the Williams indicator? Something that approached and may or may not fully cross over the -80 line. I was thinking I could look for slope changes from positive to negative along with a peak value that was say greater than -70?

y90hDMv.png
I do not know the answer to your question. I am hoping some one can convert the above script so it can be used on TOS watchlist. However, here is a photo of Williams%r with a 13 EMA overlaid on it.


npqWaVH.png


I think this is an excellent way to get an early signal.

You may want to try to change the over bought to -10 and the over sold to -90.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
465 Online
Create Post

Similar threads

Similar threads

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