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.