Stochastic Watchlist, Scan, Alert, Arrows & Other For ThinkOrSwim

There is a useful column study shared on here: https://usethinkscript.com/threads/...ossover-watchlist-column-for-thinkorswim.191/

I wanted to use this for Stochastic instead because I only want to look for long trades in my list of stocks when K crosses over D to the upside. K is the thinner line, D is the thicker line. I need the look back period to be zero (which doesn't seem to work), as I want to know if the stochastic is -currently- red and angling down, or -currently- green and angling up.

Summarily, long when D is green, short when D is red.

F3gkmKR.png


I am hoping that one of the experts in here could adjust the code in a way that makes it work. I know this is asking a lot as a stranger, but I have made several attempts at getting the result myself and only fall short each time.

FWIW here is my most recent attempt. It's embarrassing, I know:

Code:
declare lower;

input lookback= 1;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);

def bull_cross = FullK crosses above FullD;
def bear_cross = FullK crosses below FullD;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

plot signal = if bull_lookback then 2 else if bear_lookback then 1 else 0;
signal.AssignValueColor(if signal == 2 then Color.Dark_Green

else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);
AssignBackgroundCOlor(if signal == 2 then Color.Dark_Green

else if signal == 1 then Color.Dark_Red else Color.Dark_Orange);
 
Last edited:
Found this code on the web, i hope you find it useful. Also watch on the upper right side the FX Price Type, make sure it is the same as the one you have in your chart.

Code:
#######




input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC – lowest_k;
def c2 = Highest(priceH, KPeriod) – lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
#plot OverBought = over_bought;
#plot OverSold = over_sold;
#FullK.SetDefaultColor(GetColor(5));
#FullD.SetDefaultColor(GetColor(0));
#OverBought.SetDefaultColor(GetColor(1));
#OverSold.SetDefaultColor(GetColor(1));
#AssignPriceColor (if Fullk > FullD then color.green else color.red);
AssignBackgroundColor(if Fullk > FullD then color.green else color.red);
plot value = FullK;
 
Thanks a lot @hectorgasm this is great. I don't know what you mean by "upper right side the FX Price Type?" I'm only trading equities so I think it's fine as is as far as I can see right now -
 
Hello,

Can anyone convert the Stochastic Slow indicator from TradeStation to Thinkscrip or does anyone has that script already? I am trying to find one or edited it, with no luck.

Thanks in advance,
Tim
 
@timh It's as easy as searching it in your ThinkorSwim

QzPvtie.png
Yes, it is, but the numbers and setting is different between them, TS stochastic slow default setting is 14,3,3,1,20, TOS only has 10,10. Just couldn't find it anywhere, hopefully someone here has that script, thanks for your help.
 
Yes, it is, but the numbers and setting is different between them, TS stochastic slow default setting is 14,3,3,1,20, TOS only has 10,10. Just couldn't find it anywhere, hopefully someone here has that script, thanks for your help.
Just change the settings to match and it should paint fairly close to the same as in TradeStation...
 
Try this, may help
just change aggrationperiod

Code:
declare lower;

input over_bought = 80;
input sell_signal = 68;
input over_sold = 32;
input aggregationPeriod = AggregationPeriod.WEEK;
input KPeriod = 10;
input DPeriod = 3;
input slowing_period = 3;
#input slowk =10;
#input slowd = 3;
#input percentchg = close;
plot FullK = Average((close(period = aggregationPeriod) - Lowest(low(period = aggregationPeriod), KPeriod)) / (Highest(high(period = aggregationPeriod), KPeriod) - Lowest(low(period = aggregationPeriod), KPeriod)) * 100, slowing_period);
plot FullD = Average(Average((close(period = aggregationPeriod) - Lowest(low(period = aggregationPeriod), KPeriod)) / (Highest(high(period = aggregationPeriod), KPeriod) - Lowest(low(period = aggregationPeriod), KPeriod)) * 100, slowing_period), DPeriod);

plot OverBought = over_bought;
plot sellsignal = sell_signal;
plot OverSold = over_sold;

#plot close =  ((dperiod  / kperiod  )-1) * 100;
 
Sigh .... hey @BenTen, I am working on this indicator for my watchlist. This is what I have but it is not correct. IF you fix it for me could you explain where I went wrong, please? I am trying to get a red color box when the 1 hour (include after hours) stochslow (k=5) crosses below 81. SOS.
#StochasticSlow("k period" = 5, "d period" = 1)."SlowK" crosses below 81
Input StochasticSlow = 5;
Input stochasticCrossover = 81;

def StochasticSlowvalue = close [1] < stochasticslow and close > stochasticslow;
def stochasticCrossovervalue = close [1] < stochasticCrossovervalue [1] and close > stochasticCrossover;

plot scan = stochasticCrossovervalue;

assignBackgroundColor (if scan <= 1 then color.GREEN else color.BLACK);
scan.assignvaluecolor(if stochasticcrossovervalue >= 1 then color.BLACK else color.GREEN);
 
@MBF this code was created using the Conditional Wizard and Script Editor...

Ruby:
plot xover = StochasticSlow("k period" = 5, "d period" = 1)."SlowK" crosses below 80;
xover.AssignValueColor(if xover == 1 then color.green else color.black);
AssignBackgroundColor(if xover == 1 then color.green else color.black);
 
Hi. First of all, just wanted to say I love this community. Everyone is so helpful.

SO here's my question. I have a study that paints the bars based on the RSI. I find it useful.

But I was wondering if someone could help me with the TOS Stochastic Full Indicator - so that it paints the bars based on the FullD value with values for 0 - 100 - with a different definable color for 0, 10, 20 , 30, ... all the way to 100.

Here's the code for the TOS Stochastic Full indicator. Thanks for any help!

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

declare lower;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

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

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

FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Something like: if FullD is >= 10 then color.green, if FullD >= 20 then color.blue?

You need to give us the color template and values for each color so we can help.
 
Thanks BenTen!

Something like this:

Code:
AssignPriceColor(if FullD >= 0 then CreateColor (128,0,106)
else if FullD >= 10 then CreateColor (204,0,68)
else if FullD >= 20  then CreateColor (255,0,0)
else if FullD >= 30 then CreateColor (255,102,25)
else if FullD >= 40 then CreateColor (255,170,0)
else if FullD >= 50 then CreateColor (170,255,0)
else if FullD >= 60 then CreateColor (43,255,0)
else if FullD >= 70 then CreateColor (0,255,170)
else if FullD >= 80 then CreateColor (0,213,255)
else if FullD >= 90 then CreateColor (221,204,255)
else CreateColor (255,255,25) );

I don't know how to incorporate this into the script to make it paint the bars.
 
OK - I figured it out!!
I needed to reverse the order of them so they were listed highest to lowest, otherwise they were all being painted according to the first condition: if FullD >= 0 then CreateColor (128,0,106). Duh.

Thanks for helping me think!
 
JWrsb,

I went ahead and edited the code because I wanted to see what it looks like. Looks pretty cool. Here is the code....

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

declare lower;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

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

UpSignal.SetHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.SetHiding(showBreakoutSignals == showBreakoutSignals."No");

FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

AssignPriceColor(if FullD <= 0 then CreateColor (128,0,106)
else if FullD >= 90 then CreateColor (221,204,255)
else if FullD >= 80 then CreateColor (0,213,255)
else if FullD >= 70 then CreateColor (0,255,170)
else if FullD >= 60 then CreateColor (43,255,0)
else if FullD >= 50 then CreateColor (170,255,0)
else if FullD >= 40 then CreateColor (255,170,0)
else if FullD >= 30 then CreateColor (255,102,25)
else if FullD >= 20  then CreateColor (255,0,0)
else if FullD >= 10 then CreateColor (204,0,68)
else CreateColor (255,255,25) );

and here is the download link for thinkorswim... http://tos.mx/Y7UEcFj
 
Last edited by a moderator:
Thanks everyone. I think this will be useful spotting divergences in the price action and the stochastic indicator.

Here's the code. Try it out and let me know what you think. :)

Code:
# Cust_Stochastic_Full_ColorBars v1.1
# Coded using the StochasticFull code from TOS.
# Added the Color Bars to make spotting divergence in price action and Stochastic indicator easier to spot.
# Wallace Stochastic Full Color Bars
# Version 1.1


declare lower;

input KPeriod = 7;
input DPeriod = 2;
input slowing_period = 2;
input averageType = AverageType.SIMPLE;
input priceH = high;
input priceL = low;
input priceC = close;
input over_bought = 80;
input over_sold = 20;
input centerline = 50;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

input l1 = 6;
input l2 = 12;
input l3 = 20;
input l4 = 28;
input l5 = 35;
input m1 = 46;
input m2 = 54;
input h1 = 65;
input h2 = 72;
input h3 = 80;
input h4 = 90;
input h5 = 94;

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;
plot CenterL = centerline;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

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

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

FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

AssignPriceColor(
if FullD >= h5 then CreateColor (255,245,255)
else if FullD >= h4 then CreateColor (255,190,248)
else if FullD >= h3 then CreateColor (0,213,255)
else if FullD >= h2 then CreateColor (0,255,170)
else if FullD >= h1 then CreateColor (43,255,0)
else if FullD >= m2 then CreateColor (170,255,0)
else if FullD >= m1 then CreateColor (255,255,115)
else if FullD >= l5 then CreateColor (255,170,0)
else if FullD >= l4 then CreateColor (255,102,25)
else if FullD >= l3 then CreateColor (255,55,0)
else if FullD >= l2 then CreateColor (200,0,15)
else if FullD >= l1 then CreateColor (177,17,68)
else if FullD >= 0 then CreateColor (128,0,106)
else CreateColor (255,255,25) );
 
I brought the above two studies (post #6 by JWrsb and post #5 by drkellog) together. It seems quite different. I browse thru two threads, but didn't quite get a good grasp of what are the differences between them. where can I identify the parameter section in the threads? maybe a great chance for me to learn the script writing.

Could you help?!

THTwt0T.png
 
@cswu1211 The main difference, as I recall, is the ability to set the low, mid, and high levels yourself. I've found it useful when trading different timeframes to be able to set the levels differently. Also you'll notice that the K and D periods and the slowing factors have different default values.
 

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