Archive for February, 2009

UPDATED TOS TEMPLATES

Tuesday, February 24th, 2009

Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:0000000111 EndFragment:0000006074

12:08 MS: SB Code W/ 50 line below:       # # Study: FW_SnapBack # # Adapted from ToS CCI and RSI_EMA studies, # and configured as used by David Elliott as of 1/7/09. # # Mostly copywrite thinkorswim, inc. (2007) # # Modifications by ToS User: davidinc (david135@pc3i.com) # If you find any problems please let me know and refer # to the version number and date. Thanks. # # Revision history: # Vers Date        Change Descripton # ---- ---------   ----------------- #  0.0 2009-01-06  Original #  0.1 2009-01-12  Updated RSI section with code provided by kmktroy. #  0.2 2009-01-12  Updated RSI section with code provided by Sidewinder747 # declare lower; declare all_for_one;  input smoothingType = 1;  def   over_bought   = 80; def   over_sold     = 20; def   priceH        = high; def   priceL        = low; def   priceC        = close;  def KPeriod_0211 =  2; def DPeriod_0211 = 1; def slowing_period_0211 = 1; def KPeriod_0232 =  2; def DPeriod_0232 = 3; def slowing_period_0232 = 2; def KPeriod_0533 =  5; def DPeriod_0533 = 3; def slowing_period_0533 = 3; def KPeriod_0835 =  8; def DPeriod_0835 = 3; def slowing_period_0835 = 5; def KPeriod_1735 = 17; def DPeriod_1735 = 3; def slowing_period_1735 = 5; def KPeriod_4832 = 48; def DPeriod_4832 = 3; def slowing_period_4832 = 2;  def c1_0211  = priceC - Lowest(priceL, KPeriod_0211); def c1_0232  = priceC - Lowest(priceL, KPeriod_0232); def c1_0533  = priceC - Lowest(priceL, KPeriod_0533); def c1_0835  = priceC - Lowest(priceL, KPeriod_0835); def c1_1735  = priceC - Lowest(priceL, KPeriod_1735); def c1_4832  = priceC - Lowest(priceL, KPeriod_4832);  def c2_0211 = Highest(priceH, KPeriod_0211) - Lowest(priceL, KPeriod_0211); def c2_0232 = Highest(priceH, KPeriod_0232) - Lowest(priceL, KPeriod_0232); def c2_0533 = Highest(priceH, KPeriod_0533) - Lowest(priceL, KPeriod_0533); def c2_0835 = Highest(priceH, KPeriod_0835) - Lowest(priceL, KPeriod_0835); def c2_1735 = Highest(priceH, KPeriod_1735) - Lowest(priceL, KPeriod_1735); def c2_4832 = Highest(priceH, KPeriod_4832) - Lowest(priceL, KPeriod_4832);  def FastK_0211 = c1_0211 /c2_0211 * 100; def FastK_0232 = c1_0232 /c2_0232 * 100; def FastK_0533 = c1_0533 /c2_0533 * 100; def FastK_0835 = c1_0835 /c2_0835 * 100; def FastK_1735 = c1_1735 /c2_1735 * 100; def FastK_4832 = c1_4832 /c2_4832 * 100;  plot FullK_4832; plot FullK_1735; plot FullK_0835; plot FullK_0533; plot FullK_0232; plot FullK_0211;  if smoothingType == 1 then { FullK_0211 = Average(FastK_0211, slowing_period_0211);   FullK_0232 = Average(FastK_0232, slowing_period_0232);   FullK_0533 = Average(FastK_0533, slowing_period_0533);   FullK_0835 = Average(FastK_0835, slowing_period_0835);   FullK_1735 = Average(FastK_1735, slowing_period_1735);   FullK_4832 = Average(FastK_4832, slowing_period_4832); } else {   FullK_0211 = ExpAverage(FastK_0211, slowing_period_0211);   FullK_0232 = ExpAverage(FastK_0232, slowing_period_0232);   FullK_0533 = ExpAverage(FastK_0533, slowing_period_0533);   FullK_0835 = ExpAverage(FastK_0835, slowing_period_0835);   FullK_1735 = ExpAverage(FastK_1735, slowing_period_1735);   FullK_4832 = ExpAverage(FastK_4832, slowing_period_4832); }  FullK_0211.SetDefaultColor(Color.White); FullK_0211.SetStyle(Curve.Short_Dash); FullK_0232.SetDefaultColor(Color.White); FullK_0533.SetDefaultColor(Color.Yellow); FullK_0835.SetDefaultColor(Color.Green); FullK_1735.SetDefaultColor(Color.Red); FullK_4832.setDefaultColor(Color.Cyan);  FullK_0211.SetLineWeight(1); FullK_0232.SetLineWeight(1); FullK_0533.SetLineWeight(1); FullK_0835.SetLineWeight(1); FullK_1735.SetLineWeight(1); FullK_4832.SetLineWeight(1);   # RSI snapback studies - this piece is courtesy of Sidewinder747. Thanks. # updated 1/12/09.  input RSI_length = 2;  def diff = if close > close[1] then close - close[1] else 0; def diff2 = if close < close[1] then close[1] - close else 0;  rec avg = compoundValue(1, 2 / (RSI_length + 1) * diff + (RSI_length - 1) / (RSI_length + 1) * avg[1], diff * 2 / (RSI_length + 1)); rec avg2 = compoundValue(1, 2 / (RSI_length + 1) * diff2 + (RSI_length - 1) / (RSI_length + 1) * avg2[1], diff2 * 2 / (RSI_length + 1));  rec avgSMA = compoundValue(1, (avgSMA[1] + diff) / 2, diff); rec avgSMA2 = compoundValue(1, (avgSMA2[1] + diff2) / 2, diff2);  def value = if avg2 != 0 then 100 - 100 / (1 + avg / avg2) else 0; def valueSMA = if avg2 != 0 then 100 - 100 / (1 + avgSMA / avgSMA2) else 0;  plot RSI_EMA = ExpAverage(value, 2); plot RSI_SMA = Average(valueSMA, 2);  RSI_EMA.SetDefaultColor(Color.DARK_ORANGE); RSI_EMA.SetLineWeight(1); RSI_SMA.SetDefaultColor(Color.MAGENTA); RSI_SMA.SetLineWeight(1);  plot Zeroline = 50;Zeroline.setdefaultColor (color.GREEN);zeroline.setStyle (curve.SHORT_DASH);

THINKORSWIM STUDIES

Tuesday, February 17th, 2009

SNAP BACK WITH STOCH AND RSI STUDIES.

declare lower;
declare all_for_one;

input smoothingType = 1;
input length = 2;

def priceH = high;
def priceL = low;
def priceC = close;

def KPeriod48 = 48;
def DPeriod48 = 3;
def slowing48 = 2;

def KPeriod17 = 17;
def DPeriod17 = 3;
def slowing17 = 5;

def KPeriod8 = 8;
def DPeriod8 = 3;
def slowing8 = 5;

def KPeriod5 = 5;
def DPeriod5 = 3;
def slowing5 = 3;

def KPeriod22 = 2;
def DPeriod22 = 3;
def slowing22 = 2;

def KPeriod211 = 2;
def DPeriod211 = 1;
def slowing211 = 1;
#### Stoc48 ####
def c148 = priceC – Lowest(priceL, KPeriod48);
def c248 = Highest(priceH, KPeriod48) – Lowest(priceL, KPeriod48);
def FastK48 = c148/c248*100;
plot FullK48;
if smoothingType == 1
then {
    FullK48 = Average(FastK48, slowing48);
} else {
    FullK48 = ExpAverage(FastK48, slowing48);
}
FullK48.setDefaultColor(Color.CYAN);
FullK48.SetLineWeight(2);

#### Stoc17 ####
def c117 = priceC – Lowest(priceL, KPeriod17);
def c217 = Highest(priceH, KPeriod17) – Lowest(priceL, KPeriod17);
def FastK17 = c117/c217*100;
plot FullK17;
if smoothingType == 1
then {
    FullK17 = Average(FastK17, slowing17);
} else {
    FullK17 = ExpAverage(FastK17, slowing17);
}
FullK17.setDefaultColor(Color.RED);
FullK17.SetLineWeight(2);

#### Stoc8 ####
def c18 = priceC – Lowest(priceL, KPeriod8);
def c28 = Highest(priceH, KPeriod8) – Lowest(priceL, KPeriod8);
def FastK8 = c18/c28*100;
plot FullK8;
if smoothingType == 1
then {
    FullK8 = Average(FastK8, slowing8);
} else {
    FullK8 = ExpAverage(FastK8, slowing8);
}
FullK8.setDefaultColor(Color.GREEN);
FullK8.SetLineWeight(2);

#### Stoc5 ####
def c15 = priceC – Lowest(priceL, KPeriod5);
def c25 = Highest(priceH, KPeriod5) – Lowest(priceL, KPeriod5);
def FastK5 = c15/c25*100;
plot FullK5;
if smoothingType == 1
then {
    FullK5 = Average(FastK5, slowing5);
} else {
    FullK5 = ExpAverage(FastK5, slowing5);
}
FullK5.setDefaultColor(Color.YELLOW);
FullK5.SetLineWeight(2);

#### Stoc223 ####
def c122 = priceC – Lowest(priceL, KPeriod22);
def c222 = Highest(priceH, KPeriod22) – Lowest(priceL, KPeriod22);
def FastK22 = c122/c222*100;
plot FullK22;
if smoothingType == 1
then {
    FullK22 = Average(FastK22, slowing22);
} else {
    FullK22 = ExpAverage(FastK22, slowing22);
}
FullK22.setDefaultColor(Color.WHITE);
FullK22.SetLineWeight(2);

#### Stoc211 ####
def c1211 = priceC – Lowest(priceL, KPeriod211);
def c2211 = Highest(priceH, KPeriod211) – Lowest(priceL, KPeriod211);
def FastK211 = c1211/c2211*100;
plot FullK211;
if smoothingType == 1
then {
    FullK211 = Average(FastK211, slowing211);
} else {
    FullK211 = ExpAverage(FastK211, slowing211);
}
FullK211.setDefaultColor(Color.WHITE);
FullK211.SetStyle(Curve.SHORT_DASH);
FullK211.SetLineWeight(1);

def diff = if close > close[1] then close – close[1] else 0;
def diff2 = if close < close[1] then close[1] - close else 0;

rec avg = compoundValue(1, 2 / (length + 1) * diff + (length - 1) / (length + 1) * avg[1], diff * 2 / (length + 1));
rec avg2 = compoundValue(1, 2 / (length + 1) * diff2 + (length - 1) / (length + 1) * avg2[1], diff2 * 2 / (length + 1));

rec avgSMA = compoundValue(1, (avgSMA[1] + diff) / 2, diff);
rec avgSMA2 = compoundValue(1, (avgSMA2[1] + diff2) / 2, diff2);

def value = if avg2 != 0 then 100 - 100 / (1 + avg / avg2) else 0;
def valueSMA = if avg2 != 0 then 100 - 100 / (1 + avgSMA / avgSMA2) else 0;

plot RSI_EMA = ExpAverage(value, 2);
plot RSI_SMA = Average(valueSMA, 2);

RSI_EMA.SetDefaultColor(Color.DARK_ORANGE);
RSI_EMA.SetLineWeight(2);
RSI_SMA.SetDefaultColor(Color.MAGENTA);
RSI_SMA.SetLineWeight(2);

CCI STUDIES

declare lower;

input length05 = 5;
input length20 = 20;
input length50 = 50;
input over_sold   = -100;
input over_bought =  100;

def price = (high + low + close);
def linDev05 = lindev(price, length05);
def linDev20 = lindev(price, length20);
def linDev50 = lindev(price, length50);

plot CCI05 = if linDev05 == 0 then 0 else (price – Average(price, length05)) / linDev05 / 0.015;
plot CCI20 = if linDev20 == 0 then 0 else (price – Average(price, length20)) / linDev20 / 0.015;
plot CCI50 = if linDev50 == 0 then 0 else (price – Average(price, length50)) / linDev50 / 0.015;

plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;

CCI05.SetDefaultColor(Color.MAGENTA);
CCI20.SetDefaultColor(Color.YELLOW);
CCI50.SetDefaultColor(Color.CYAN);

Overbought.SetDefaultColor(GetColor(5));
ZeroLine.SetDefaultColor(GetColor(5));
Oversold.SetDefaultColor(GetColor(5));