Williams Alligator For ThinkOrSwim

diazlaz

Well-known member
2019 Donor
VIP
Its interesting, i'm noticing differences in the candle price data from ToS and Trading View. Some of the candles have different values, but overall, It looks like it's working correctly. This observation on the data differences is when looking at it in the 1 minute candle.

Original:
SGOz4io.png


Port:
P0pWHLs.png


Code:

Ruby:
# Bill William Bull/Bear divergent bars
# See: Book, Trading Chaos by Bill Williams
#
# https://www.tradingview.com/script/lLgCdjag-Bill-Williams-Divergent-Bars/
# Author: polyclick
#
# A bullish (green) divergent bar, signals a trend switch from bear -> bull
# The current bar has a lower low than the previous bar, but closes in the
# upper half of the candle.
# This means the bulls are pushing from below and are trying to take over,
# potentially resulting in a trend switch to bullish.
# We also check if this bar is below the three alligator lines to avoid false positives.
#
# A bearish (red) divergent bar, signals a trend switch
# from bull -> bear
# The current bar has a higher high than the previous bar, but closes in
# the lower half of the candle.
#
# This means the bears are pushing the price down and are taking over,
# potentially resulting in a trend switch to bearish.
# We also check if this bar is above the three alligator lines to avoid false positives.
#
#
# @@EMMA request
#
# 2019.12.13 @diazlaz - logic bug fixes.
# 2019.12.13 @diazlaz - initial port/interpretation.
#

# LOGIC
def price = hl2;
def jawLength = 13;
def teethLength = 8;
def lipsLength = 5;
def jawDisplace = -8;
def teethDisplace = -5;
def lipsDisplace = -3;
def averageType = AverageType.WILDERS;

def lips = MovingAverage(averageType, price[-lipsDisplace], lipsLength);
def jaw = MovingAverage(averageType, price[-jawDisplace], jawLength);
def teeth = MovingAverage(averageType, price[-teethDisplace], teethLength);

def bullDivSignal = low  < low[1]  and close > hl2 and high < lips and high < teeth and high < jaw;
def bearDivSignal = high > high[1] and close < hl2 and low  > lips and low  > teeth and low  > jaw;
def sState = if bullDivSignal then 100 else if bearDivSignal then -100 else sState[1];

# ARROWS
input showArrows = yes;
plot pUP = showArrows  and bullDivSignal;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = showArrows  and bearDivSignal;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);#

#COLORBARS
input showColorBars = yes;
AssignPriceColor(if showColorBars then
if sState > 0 then Color.GREEN
  else Color.RED
else
  COLOR.CURRENT
);

#LABELS
input showLabels = yes;
AddLabel(showLabels, "Buy",
if isNaN(sState) then COLOR.DARK_GRAY else
If bullDivSignal then COLOR.GREEN else COLOR.DARK_GRAY);

AddLabel(showLabels, "Sell",
if isNaN(sState) then COLOR.DARK_GRAY else
If bearDivSignal then COLOR.RED else COLOR.DARK_GRAY);

# END OF Bill William Bull/Bear divergent bars
 
Last edited by a moderator:
Can someone please make a williams alligator crossover scan for tos? I would say one for when the green crosses above the green and another for when it crosses below the red. Thanks in advance!
 
I just added the indicator to my chart and I see 3 different colors: green, red, and blue. Regardless, you can still setup the scanner using a condition like this:

Example: Jaw (blue) crosses above Teeth (red).

mGqEyl4.png
 
Hello, I was wondering if someone could help me right the script for William's Alligator Crossover? Was just looking for a simple crossover that's shown with up/down arrows rather than having to follow the lines.
 
@Gabrielx77 There are 3 lines in the indicator. Can you specify the crossover?
Of course. I wanted a crossover of 3 simple moving averages, each one being the 5 sma with 3 displacement, the 8 sma with 5 displacement, and the 13 sma with 8 displacement. The up arrow would basically come when the 5 sma cross over both the 8 and 13 sma. The down arrow would come when the 5 sma cross under the 8 and 13 sma.

PS If the arrows could appear only when the 5 sma crosses over/under the 13 sma first, before the 8 sma crosses over/under the 13 sma, that would be awesome.
 
Last edited:
Many years ago I read the Bill Williams book, "Trading Chaos" (1995) which discussed the Alligator Indicator. I keep track of all books that I read, and also rate them. I gave this book an "excellent." So I think it is a good read, if only to glean one or two ideas from it. It should be noted that Bill Williams should not be confused with Larry Williams, who is considerably more famous. I proceeded to code this indicator in MS Excel and in Metastock's language. After considerable testing, I found that it was "average" in its effectiveness, meaning there are many other indicators that are more promising. Granted, I only traded (and still trade) NASDAQ 100 products and its derivatives, so there is that. :) I guess the fact remains that anyone can use any indicator with varying amounts of success as long as they tweak it or employ it within the framework of their own abilities and expectations. I look forward to seeing what results traders here get from using it in scanning and trading.
 
Last edited:
@Gabrielx77 Try this:

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

input price = hl2;
input jawLength = 13;
input teethLength = 8;
input lipsLength = 5;
input jawDisplace = -8;
input teethDisplace = -5;
input lipsDisplace = -3;
input averageType = AverageType.WILDERS;

plot Jaw = MovingAverage(averageType, price[-jawDisplace], jawLength);
plot Teeth = MovingAverage(averageType, price[-teethDisplace], teethLength);
plot Lips = MovingAverage(averageType, price[-lipsDisplace], lipsLength);

Jaw.SetDefaultColor(Color.BLUE);
Teeth.SetDefaultColor(Color.RED);
Lips.SetDefaultColor(Color.GREEN);

plot UpSignal = if Lips crosses above Jaw then low else Double.NaN;
plot DownSignal = if Lips crosses below Jaw then high else Double.NaN;

UpSignal.SetDefaultColor(Color.MAGENTA);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.CYAN);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
This question is in regards to the Gator Oscillator. Can a scan be developed to identify the 4 phases of the Gator Oscillator ?
  • Sleeping Phases
  • Awakening Phases
  • Eating Phases
  • Sated Phases
Also can the code be modified to plot the 4 different phases on the Chart, such as a arrow for the sleeping phases, a circle for the awakening phase, a triangle for eating phase etc.

Here is the code: Any help or suggestion would be very appreciated. Thanks

Code:
declare lower;

input price = hl2;
input jawLength = 13;
input teethLength = 8;
input lipsLength = 5;
input jawDisplace = -8;
input teethDisplace = -5;
input lipsDisplace = -3;
input averageType = AverageType.WILDERS;

def jaw = WilliamsAlligator(price, jawLength, teethLength, lipsLength, jawDisplace, teethDisplace, lipsDisplace, averageType).Jaw;
def teeth = WilliamsAlligator(price, jawLength, teethLength, lipsLength, jawDisplace, teethDisplace, lipsDisplace, averageType).Teeth;
def lips = WilliamsAlligator(price, jawLength, teethLength, lipsLength, jawDisplace, teethDisplace, lipsDisplace, averageType).Lips;

plot Top = AbsValue(jaw - teeth);
plot Bottom = -AbsValue(teeth - lips);
plot ZeroLine = 0;

Top.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Top.DefineColor("Up", Color.UPTICK);
Top.DefineColor("Down", Color.DOWNTICK);
Top.AssignValueColor(if Top > Top[1] then Top.Color("Up") else Top.Color("Down"));
Bottom.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Bottom.DefineColor("Up", Color.UPTICK);
Bottom.DefineColor("Down", Color.DOWNTICK);
Bottom.AssignValueColor(if Bottom < Bottom[1] then Bottom.Color("Up") else Bottom.Color("Down"));
ZeroLine.SetDefaultColor(GetColor(0));
 
Define the following:
  • Sleeping Phases
  • Awakening Phases
  • Eating Phases
  • Sated Phases
 
Interesting concept, looked at both indicators in TOS. Honestly, I dont see it very useful as it's in TOS right now.
 
Can someone help me combine these statements? I am using the color of the Bollinger band lines to filter out bad trades but I would like to have a third color to show a weaker buy or sell permission.
Buy Green = good to go, Cyan = good but low volume, Gray = no buy
Sell Red = good to go, Magenta = good but low volume, Gray = no buy
Here is my current code(section)


Code:
bb_upperband.AssignValueColor(if (Teeth > Jaw or Lips > Jaw)and (RangeRatio > RangeFactor) then Color.GREEN else Color.GRAY);

#the weaker buy signal
bb_upperband.AssignValueColor(if (Teeth > Jaw or Lips > Jaw) then Color.Cyan else Color.GRAY);


bb_lowerband.AssignValueColor(if (Teeth > Lips or Jaw > Lips)and (RangeRatio > RangeFactor) then Color.RED else Color.GRAY);

#the weaker sell signal
bb_lowerband.AssignValueColor(if (Teeth > Lips or Jaw > Lips) then Color.Magenta else Color.GRAY);
 
Last edited:
Figured it out. Here it is - I hope this helps anyone else

Code:
bb_upperband.AssignValueColor(if(Teeth > Jaw or Lips > Jaw)and (RangeRatio > RangeFactor) then Color.GREEN else if Teeth > Jaw or Lips > Jaw then Color.CYAN else Color.GRAY);

bb_lowerband.AssignValueColor(if(Teeth > Lips or Jaw > Lips)and (RangeRatio > RangeFactor) then Color.Red else if Teeth > Jaw or Lips > Jaw then Color.Orange else Color.GRAY);
 
I was hoping someone could help create an alert based on the CLOSE of a Bullish/Bearish Divergent Bar. (In whatever timeframe I happen to want to look at) that alerts me once the current candle closes and meets the definition of a Divergent bar.

Example: If I'm using a 1 hour chart, I should only get 1 alert after the bar closes and meets the criteria. Currently I'm receiving an alert every time the candle goes back and forth from being a divergent bar to not...etc. I'm getting too many Alerts that are "False"

Can any one code this?


Here is the code that I'm using to define a Divergent Bar:

Code:
# LOGIC
def price = hl2;
def jawLength = 13;
def teethLength = 8;
def lipsLength = 5;
def jawDisplace = -8;
def teethDisplace = -5;
def lipsDisplace = -3;
def averageType = AverageType.WILDERS;

def lips = MovingAverage(averageType, price[-lipsDisplace], lipsLength);
def jaw = MovingAverage(averageType, price[-jawDisplace], jawLength);
def teeth = MovingAverage(averageType, price[-teethDisplace], teethLength);

def bullDivSignal = low < low[1] and close > hl2 and high < lips and high < teeth and high < jaw;
def bearDivSignal = high > high[1] and close < hl2 and low > lips and low > teeth and low > jaw;
def sState = if bullDivSignal then 100 else if bearDivSignal then -100 else sState[1];

# ARROWS
input showArrows = yes;
plot pUP = showArrows and bullDivSignal;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);

plot pDown = showArrows and bearDivSignal;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);#

#COLORBARS
input showColorBars = yes;
AssignPriceColor(if showColorBars then
if sState > 0 then Color.GREEN
else Color.RED
else
COLOR.CURRENT
);

#LABELS
input showLabels = yes;
AddLabel(showLabels, "Buy",
if isNaN(sState) then COLOR.DARK_GRAY else
If bullDivSignal then COLOR.GREEN else COLOR.DARK_GRAY);

AddLabel(showLabels, "Sell",
if isNaN(sState) then COLOR.DARK_GRAY else
If bearDivSignal then COLOR.RED else COLOR.DARK_GRAY);

# END OF Bill William Bull/Bear divergent bars
 
Last edited by a moderator:
Please help! I need an alert that'll tell me when the Williams alligator lines are spreading and the alligator is waking.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
292 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