Super Smooth Stochastic for ThinkorSwim

Pensar

Expert
VIP
Lifetime
This is another code written by Mobius, titled Super Smooth Stochastic. It is rather similar to the True Momentum Oscillator posted here. Notes are in the code.

Stochastic.png

Code:
#Here's a Super Smooth Stochastic written for a trading room. As Volatility increases and so does intraday range oscillators will become useful signals again.  
#Mobius: The above code is particularly good at short aggs like 2min with futures using good Risk management - Risk Off trades 
# Super Smooth Stochastic 
# Mobius 
# V01.02.2018 
#Hint: Suggest 13 and above for Daily and 8 or less for Intraday 
 
input length = 8; #hint length: Good starting points 13 Daily, 8 Intraday 
input Arrows = no; 
 
declare lower; 
 
script g { 
    input data = close; 
    def w = (2 * Double.Pi / 20); 
    def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / 10) - 1 ); 
    def alpha = (-beta + Sqrt(beta * beta + 2 * beta)); 
    def G = Power(alpha, 4) * data +  
                 4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +  
                 4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4]; 
    plot Line = G; 
} 
 
def o = g(data = open); 
def h = g(data = high); 
def l = g(data = low); 
def c = g(data = close); 
def RSV = ((c - Lowest(l, length)) / (Highest(h, length) - Lowest(l, length))) * 100; 
plot K = g(data = RSV); 
     K.SetDefaultColor(color.green); 
plot D = g(data = K); 
     D.SetDefaultColor(color.red); 
plot OB = if isNaN(c) then double.nan else 80; 
     OB.SetDefaultColor(Color.Gray); 
     OB.HideBubble(); 
     OB.HideTitle(); 
plot OS = if isNaN(c) then double.nan else 20; 
     OS.SetDefaultColor(Color.Gray); 
     OS.HideBubble(); 
     OS.HideTitle(); 
 
AddCloud(K, D, color.green, color.red); 
 
plot upArrow = if Arrows and K < OS and K crosses above D 
               then K 
               else double.nan; 
    upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP); 
     upArrow.SetDefaultColor(Color.Green); 
     upArrow.HideBubble(); 
     upArrow.HideTitle(); 
plot dnArrow = if Arrows and K > OB and K crosses below D 
               then K 
               else double.nan; 
    dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN); 
     dnArrow.SetDefaultColor(Color.Red); 
     dnArrow.HideBubble(); 
     dnArrow.HideTitle(); 
 
# End Code Stochastic Super Smooth
 
Can you please create Super Smooth Stochastic for ThinkorSwim as a multiple time frame indicator? Thanks
 
If you take a 10/3 stochastic and compare it to a 50/3 stochastic , that should tell you the difference between what the 10/3 stochastic is vs what the 10/3 stochastic is on a time frame that is 5X the base TF.

When you add MTF into any indicator, you add a RE_Paint factor into the equation
 
here is the code for 2 stochastic lengths
Code:
declare lower;
input APC = 0;
Input Dotsize = 1;
input showBreakoutSignals1 = {default "No", "On FullK1", "On FullD1", "On FullK1 & FullD1"};
input showBreakoutSignals2 = {default "No", "On FullK2", "On FullD2", "On FullK2 & FullD2"};
input showBreakoutSignals4 = {default "No", "On upX1", "On dnX1", "On upX1 & dnX1"};
input showBreakoutSignals5 = {default "No", "On upX2", "On dnX2", "On upX2 & dnX2"};
input over_bought = 80;
input Middle = 50;
input over_sold = 20;
input KPeriod1 = 10;
input DPeriod1 = 3;
input KPeriod2 = 50;
input DPeriod2 = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;

def lowest_k = Lowest(priceL, KPeriod1);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod1) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
Def FullK = MovingAverage(averageType, FastK, slowing_period-1);
plot FullD = MovingAverage(averageType, FullK, DPeriod1);
plot SlowD = MovingAverage(averageType, FullD, Slowing_Period-1);
FullD.HideBubble();
SlowD.HideBubble();

def lowest_k2 = Lowest(priceL, KPeriod2);
def c12 = priceC - lowest_k2;
def c22 = Highest(priceH, KPeriod2) - lowest_k2;
def FastK2 = if c22 != 0 then c12 / c22 * 100 else 0;
Def FullK2 = MovingAverage(averageType, FastK2, slowing_period);
plot FullD2 = MovingAverage(averageType, FullK2, DPeriod2);
plot SlowD2 = MovingAverage(averageType, FullD2, slowing_period);
FullD2.HideBubble();
SlowD2.HideBubble();

plot OverBought = over_bought;
Plot Mid = Middle;
plot OverSold = over_sold;
OverBought.HideBubble();
Mid.HideBubble();
OverSold.HideBubble();

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;
def upK2 = FullK2 crosses above OverSold;
def upD2 = FullD2 crosses above OverSold;
def downK2 = FullK2 crosses below OverBought;
def downD2 = FullD2 crosses below OverBought;
def upX1 = FullD crosses above SlowD;
def dnX1 = FullD crosses below SlowD;
def upX2 = FullD2 crosses above SlowD2;
def dnX2 = FullD2 crosses below SlowD2;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals1) {
case "No":
    UpSignal = Double.NaN;
    DownSignal= Double.NaN;
case "On FullK1":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;
case "On FullD1":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;
case "On FullK1 & FullD1":
    UpSignal = if upK or upD then OverSold else Double.NaN;
    DownSignal = if downK or downD then OverBought else Double.NaN;
}

UpSignal.setHiding(showBreakoutSignals1 == showBreakoutSignals1."No");
DownSignal.setHiding(showBreakoutSignals1 == showBreakoutSignals1."No");

plot UpSignal2;
plot DownSignal2;
switch (showBreakoutSignals2) {
case "No":
    UpSignal2 = Double.NaN;
    DownSignal2 = Double.NaN;
case "On FullK2":
    UpSignal2 = if upK2 then OverSold else Double.NaN;
    DownSignal2 = if downK2 then OverBought else Double.NaN;
case "On FullD2":
    UpSignal2 = if upD2 then OverSold else Double.NaN;
    DownSignal2 = if downD2 then OverBought else Double.NaN;
case "On FullK2 & FullD2":
    UpSignal2 = if upK2 or upD2 then OverSold else Double.NaN;
    DownSignal2 = if downK2 or downD2 then OverBought else Double.NaN;
}

UpSignal2.setHiding(showBreakoutSignals2 == showBreakoutSignals2."No");
DownSignal2.setHiding(showBreakoutSignals2 == showBreakoutSignals2."No");

plot UpSignal4;
plot DownSignal4;
switch (showBreakoutSignals4) {
case "No":
    UpSignal4 = Double.NaN;
    DownSignal4= Double.NaN;
case "On upX1":
    UpSignal4 = if upX1 then SlowD else Double.NaN;
    DownSignal4 = if dnX1 then SlowD else Double.NaN;
case "On dnx1":
    UpSignal4 = if upx1 then SlowD else Double.NaN;
    DownSignal4 = if dnX1 then SlowD else Double.NaN;
case "On upX1 & dnX1":
    UpSignal4 = if upX1 or upD then SlowD else Double.NaN;
    DownSignal4 = if dnX1 or downD then SlowD else Double.NaN;
}

UpSignal4.setHiding(showBreakoutSignals4 == showBreakoutSignals4."No");
DownSignal4.setHiding(showBreakoutSignals4 == showBreakoutSignals4."No");

plot UpSignal5;
plot DownSignal5;
switch (showBreakoutSignals5) {
case "No":
    UpSignal5 = Double.NaN;
    DownSignal5= Double.NaN;
case "On upX2":
    UpSignal5 = if upX2 then SlowD2 else Double.NaN;
    DownSignal5 = if dnX2 then SlowD2 else Double.NaN;
case "On dnx2":
    UpSignal5 = if upx2 then SlowD2 else Double.NaN;
    DownSignal5 = if dnX2 then SlowD2 else Double.NaN;
case "On upX2 & dnX2":
    UpSignal5 = if upX2 or upD2 then SlowD2 else Double.NaN;
    DownSignal5 = if dnX2 or downD2 then SlowD2 else Double.NaN;
}

UpSignal5.setHiding(showBreakoutSignals5 == showBreakoutSignals5."No");
DownSignal5.setHiding(showBreakoutSignals5 == showBreakoutSignals5."No");


FullD.SetDefaultColor(Color.Cyan);
SlowD.SetDefaultColor(Color.Pink);
FullD2.SetDefaultColor(Color.Blue);
SlowD2.SetDefaultColor(Color.Red);
AddCloud(FullD,SlowD,Color.Cyan,Color.Pink);
AddCloud(FullD2,SlowD2,Color.Blue,Color.Red);

OverBought.SetDefaultColor(Color.Yellow);
Mid.SetDefaultColor(Color.Gray);
OverSold.SetDefaultColor(Color.Yellow);
UpSignal.SetDefaultColor(Color.Cyan);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(Dotsize);
DownSignal.SetDefaultColor(Color.Pink);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(Dotsize);
UpSignal2.SetDefaultColor(Color.Blue);
UpSignal2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal2.SetLineWeight(Dotsize+1);
DownSignal2.SetDefaultColor(Color.Red);
DownSignal2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal2.SetLineWeight(Dotsize+1);
UpSignal4.SetDefaultColor(Color.Green);
UpSignal4.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal4.SetLineWeight(Dotsize);
DownSignal4.SetDefaultColor(Color.Dark_Orange);
DownSignal4.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal4.SetLineWeight(Dotsize);
UpSignal5.SetDefaultColor(Color.Cyan);
UpSignal5.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal5.SetLineWeight(Dotsize+1);
DownSignal5.SetDefaultColor(Color.Pink);
DownSignal5.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal5.SetLineWeight(Dotsize+1);

AssignPriceColor(If APC ==1 && FullD >=SlowD then Color.Green else
If APC ==1 && FullD < SlowD then Color.Dark_Orange else
If APC ==2 && FullD2 >=SlowD2 then Color.Cyan else
If APC ==2 && FullD2 < SlowD2 then Color.Pink else
 Color.Current);
 

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
600 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