Wednesday, March 31, 2010

Bill Williams Alligator for Think or Swim

Coming from the forex world, Metatrader is well-equipped to handle trading based on Bill Williams understanding of chaos theory and fractal analysis, however Think or Swim is not. I have scoured the web for suitable indicators, but in the end, I had to write my own in thinkscript.

What Think or Swim Has:
Accelerator Oscillator - for the purists who enjoy Bill's older books
Awesome Oscillator - the 5,34 macd where you can count the elliot wave, etc

What TOS lacks:
The Alligator on the chart
Fractal Indicator on the chart


The Alligator

####
# Bill Williams Alligator for Think or Swim
# Mike Lapping 2010

# Extra steps were taken because I cannot find proper
# documentation of the average() function
# can be used and modified by anyone for any reason. do not sell.
#
####

## we will now work on the SSMA called jaws

def JOffset = 8;
def Javg13 = ((high[12 + JOffset] + low[12 + JOffset]) / 2);
def Javg12 = ((high[11 + JOffset] + low[11 + JOffset]) / 2);
def Javg11 = ((high[10 + JOffset] + low[10 + JOffset]) / 2);
def Javg10 = ((high[9 + JOffset] + low[9 + JOffset]) / 2);
def Javg9 = ((high[8 + JOffset] + low[8 + JOffset]) / 2);
def Javg8 = ((high[7 + JOffset] + low[7 + JOffset]) / 2);
def Javg7 = ((high[6 + JOffset] + low[6 + JOffset]) / 2);
def Javg6 = ((high[5 + JOffset] + low[5 + JOffset]) / 2);
def Javg5 = ((high[4 + JOffset] + low[4 + JOffset]) / 2);
def Javg4 = ((high[3 + JOffset] + low[3 + JOffset]) / 2);
def Javg3 = ((high[2 + JOffset] + low[2 + JOffset]) / 2);
def Javg2 = ((high[1 + JOffset] + low[1 + JOffset]) / 2);
def Javg1 = ((high[0 + JOffset] + low[0 + JOffset]) / 2);

def SSMAJaws = ( Javg1 + Javg2 + Javg3 + Javg4 + Javg5 + Javg6 + Javg7 + Javg8 + Javg9 + Javg10 + Javg11 + Javg12 + Javg13) / 13;

Plot Jaws = SSMAJaws;

######### Now working on Lips
def LOffset = 5;
def Lavg8 = ((high[7 + LOffset] + low[7 + LOffset]) / 2);
def Lavg7 = ((high[6 + LOffset] + low[6 + LOffset]) / 2);
def Lavg6 = ((high[5 + LOffset] + low[5 + LOffset]) / 2);
def Lavg5 = ((high[4 + LOffset] + low[4 + LOffset]) / 2);
def Lavg4 = ((high[3 + LOffset] + low[3 + LOffset]) / 2);
def Lavg3 = ((high[2 + LOffset] + low[2 + LOffset]) / 2);
def Lavg2 = ((high[1 + LOffset] + low[1 + LOffset]) / 2);
def Lavg1 = ((high[0 + LOffset] + low[0 + LOffset]) / 2);

def SSMALips = (Lavg1 + Lavg2 + Lavg3 + Lavg4 + Lavg5 + Lavg6 + Lavg7 + Lavg8) / 8;

Plot Lips = SSMALips;

######## Work on teeth
def TOffset = 3;

def Tavg5 = ((high[4 + TOffset] + low[4 + TOffset]) / 2);
def Tavg4 = ((high[3 + TOffset] + low[3 + TOffset]) / 2);
def Tavg3 = ((high[2 + TOffset] + low[2 + TOffset]) / 2);
def Tavg2 = ((high[1 + TOffset] + low[1 + TOffset]) / 2);
def Tavg1 = ((high[0 + TOffset] + low[0 + TOffset]) / 2);

def SSMATeeth = (Tavg1 + Tavg2 + Tavg3 + Tavg4 + Tavg5) / 5;

Plot Teeth = SSMATeeth;

## Set Colors for the balance lines

Jaws.SetDefaultColor(Color.BLUE);
Lips.SetDefaultColor(Color.UPTICK);
Teeth.SetDefaultColor(Color.DOWNTICK);

Remember to time shift the chart at least 9 bars so that you can have the full effect of the alligator. This is done by:

Right click on chart > Style > Settings.

In the new window, go to the "Scale and Axis" tab, half way down, change the value for "Expansion" to 8 or more. The Jaws are projected 8 bars into the future.

Hope everyone benefits from this!

-Mike

2 comments: