Saturday, October 15, 2011

Mobius Squeeze

TTM Squeeze and TTM Wave are two of the most requested study's for TOS and Prodigio. The code has not been published for  public use by John Carter so this is an approximation of those study's as found in ThinkOrSwim.
This is a combination of the two studies:
1.) Bollinger Band, Keltner Channel squeeze rule stating first the Upper Bollinger Band is below the Upper   Keltner channel band sequenced to the Upper Bollinger Band  Above the Upper Keltner Channel. This may be altered to state that the Bollinger Band has Crossed Above the Keltner Channel  but it makes the rule much more restrictive.
Note: Since the lower and upper Bollinger Bands cross the Keltner Channel at the same time is is only necessary to have a statement for on or the other of the bands.
2.) Two pairs of  Moving Averages Crossing converted into a histogram create the waves.

Screen Shot:



ThinkScript:


# Mobius Wave Squeeze Alert
# Mobius.rts@gmail.com
# Revision V01.02.22.12
# Addition of the Bollinger Band Percent B chart label
# Hint: The %B during the squeeze give directional indication,
#       above 50% resolution of the squeeze is likely upward,
#       below 50% resolution of the squeeze is likely downward.
# Addition of LRR Volume Shift
# Addition of ParabolicSAR
# Hint: White squares at the index line are volume shifts.
#       Yellow dots at the index line are Bollinger Band / Keltner Channel squeeze indicators.
#       Green and Red arrows at the index line are Parabolic Stop and Reverse indicators.
#       Optimal Long sequence; (1) Histogram shift from light red to dark red with values increasing
#             toward the index line confirming a shift from distribution to accumulation.
#         (2) White square or multiple white squares at the index line confirming a volume increase.
#         (3) The presence of yellow dots on the index line indicating compression of the Bollinger Bands
#             and a volatility increase.
#         (4) A green up arrow indicating the Parabolic Stop and Reverse as gone positive.
#        Optimal Short sequence; The reverse of the above.

declare lower;

input price1 = CLOSE;
input ShortLength1 = 5;
input ShortLength2 = 14;
input ShortLength3 = 5;
input LongLength1 = 12;
input LongLength2 = 55;
input LongLength3 = 7;
input nK = 1.5;

input nBB = 2.0;
input alertLine = 1.0;

  def MS = Average(Average(price1, ShortLength1) - Average(price1, ShortLength2), ShortLength3);
  def MS2 = Average(Average(price1, LongLength1) - Average(price1, LongLength2), LongLength3);
  def MSGreens = if (MS >= 0, MS, 0);

  plot MS_Pos = MSGreens;
     MS_Pos.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
     MS_Pos.AssignValueColor(if MSGreens < MSGreens[1] then Color.Green else Color.Dark_Green);
     MS_Pos.SetLineWeight(4);

  def MSReds = if (MS < 0, MS, 0);

  plot MS_Neg = MSReds;
     MS_Neg.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
     MS_Neg.AssignValueColor(if MSReds < MSReds[1] then Color.Red else Color.Dark_Red);
     MS_Neg.SetLineWeight(4);

  def MS2Blues = if (MS2 >= 0, MS2, 0);

  plot MS2_Pos = MS2Blues;
     MS2_Pos.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
     MS2_Pos.AssignValueColor(if MS2Blues < MS2Blues[1] then Color.Blue else Color.CYAN);
     MS2_Pos.SetLineWeight(4);

  def MS2Yellow = if (MS2 < 0, MS2, 0);

  plot MS2_Neg = MS2Yellow;
     MS2_Neg.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
     MS2_Neg.AssignValueColor(if MS2Yellow < MS2Yellow[1] then Color.Yellow else Color.light_Red);
     MS2_Neg.SetLineWeight(4);


Input LengthATR = 20;
Input PriceATR = Close;
Input minPriceMove = 1;
Input priceIncrement = 0.01;
Input SqueezeOnColor = 2;
Input SqueezeOffColor = 6;

  def LHMult = if (priceIncrement <> 0, (minPriceMove / priceIncrement), 0);
  def ATR = AvgTrueRange(high, close, low, LengthATR);
  def SDev = stdev(PriceATR, LengthATR);
  def Denom = (nK * ATR);
  def BBS_Ind = if (Denom <> 0, ((nBB * SDev) / Denom), 0);

  plot BBS_Ind1 = if IsNaN(close) or !MS then Double.NaN else 0;
       BBS_Ind1.AssignValueColor(if BBS_Ind < Alertline then Color.Yellow else CreateColor(55,20,220));
       BBS_Ind1.SetStyle(4);
       BBS_Ind1.SetLineWeight(4);
   def BBSMA = Average(PriceAtr, LengthATR);
   def BBSMAL = BBSMA + (-2 * SDev);
   def BBSMAU = BBSMA + (2 * SDev);
   def PerB = Roundup((priceATR - BBSMAL) / (BBSMAU - BBSMAL) * 100, 0);
AddChartlabel(yes, concat("%B: ",Roundup((priceATR - BBSMAL) / (BBSMAU - BBSMAL) * 100, 0)),
if PerB < 0 then color.Yellow else if PerB > 0 and PerB[1] < 0 then color.Green else color.white) ;

input LRRLengthV = 100;

  rec inertV = Inertia(volume, LRRLengthV);
  rec LRRV = if inertV >= inertV[1] then 1 else -1;
  rec AlertLineV = 0;
  rec LRR_VolumeAlert = if (LRRV > LRRV[1] and (LRRV > AlertLineV) and (LRRV[1] < AlertLineV), .001, 0);

  plot LRR_VolSwitchAlert = if LRR_VolumeAlert > 0 then LRR_VolumeAlert else Double.NaN;
       LRR_VolSwitchAlert.SetPaintingStrategy(PaintingStrategy.Line_Vs_Squares);
       LRR_VolSwitchAlert.SetLineWeight(5);
       LRR_VolSwitchAlert.AssignValueColor(Color.White);

# Parabolic SAR Signal

input accelerationFactor = 0.0275;
input accelerationLimit = 0.2;
input crossingType = {default Bearish, Bullish};

  def sar = ParabolicSAR(accelerationFactor=accelerationFactor, accelerationLimit=accelerationLimit);
  def signald = IF (crosses(sar, price1, CrossingType == CrossingType.Bearish) and
                  sar >= price1[1]) then 1 else Double.NaN ;
  plot signaldown = signald == 1 and 0;
       signaldown.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
       signaldown.SetLineWeight(4);
       signaldown.AssignValueColor(Color.RED);

  def signalu = IF (crosses(sar, price1, CrossingType == CrossingType.Bullish) and
                  sar <= price1[1]) then 1 else Double.NaN ;
  plot signalup = signalu == 1 and 0;
       signalup.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
       signalup.SetLineWeight(4);
       signalup.AssignValueColor(Color.Green);

#End Code.................

No comments:

Post a Comment