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

@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.
tks, greatly appreciated. could you show me WHICH section of the script has these info for further modifications
 
tks, greatly appreciated. could you show me WHICH section of the script has these info for further modifications
Sorry cswu1211 - took a while to get back to you.

This section creates inputs that are populated with my preferred default values for the 1, 2, 5 minute times frames. They are easily changed in TOS by selecting 'Edit Properties'.

Code:
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;

Lower in the code is where you can set the colors for the levels:

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) );

h5 is the highest level.
 
Hey Guys

First post here and I want to say Thank You to all who have contributed to this amazing source of ThinkScript knowledge!

I have written an indicator that draws an arrow and writes to the message center when a slow stochastic is below 20 and a fast stochastic is above 80 (amongst other conditions). I got an odd result today whereby I got the message in the message center but not the arrows. After watching it for a while I realized that the arrow was repainting. I don't understand this as the StochasticSlow is using close as a parameter so how is the condition triggering before the bar has closed? Is there a way (other than multi-timeframe) to have the condition fire only at the close of the bar?

Many thanks!

Matt.


Code:
# Slow Stoch Indicator inspired by BreakpointTrades.com
# Written by Matt Ward
#######################################################
# Version 1.0 3/17/21
# It triggers on two conditions.  The first is when the slow stoch is above "bull upper" (default 80)
# and the fast stock crosses below "bull lower" (default 20).   The second is when the slow stoch is
# below "bear lower" (default 20) and the fast stoch crosses above "bear upper" (default 80). You can
# change the stoch speeds using the inputs "fast stoch" (default 10) and "slow stoch" (default 60). 
#######################################################
# Version 1.1 3/21/21
# Added Alerts.  If the alerts are turned on then and the script triggers then it will write to the
# Message Center and play a sound.   You can chose which sound on the settings screen
# The way I use this is to have a 2x2 chart window open with 5 min charts for the SPY, QQQ, IWM and DIA.
# This way I get a real time alert when the trigger conditions are met.
#######################################################

Input FastStoch = 10;
Input SlowStoch = 60;
Input BullUpper = 80;
Input BullLower = 20;
Input BearUpper = 80;
Input BearLower = 20;
Input AlertsOn = yes;
Input AlertSound = Sound.DING;

def StochSlowSlow = StochasticSlow(80,20,SlowStoch,3,high,low,close,AverageType.SIMPLE).SlowK;
def StochSlowFast = StochasticSlow(80,20,FastStoch,3,high,low,close,AverageType.SIMPLE).SlowK;

def BullCondition = StochSlowSlow >= BullUpper && (StochasticSlow(80,20,FastStoch,3,high,low,close,AverageType.SIMPLE).SlowK) crosses below BullLower;

def BearCondition = StochSlowSlow <= BearLower && (StochasticSlow(80,20,FastStoch,3,high,low,close,AverageType.SIMPLE).SlowK) crosses above BearUpper;

plot Bear = BearCondition;
Bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bear.SetDefaultColor(COLOR.RED);
plot Bull = BullCondition;
Bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bull.SetDefaultColor(COLOR.GREEN);

Alert( if AlertsOn and BearCondition then yes else no, "MBW BPT Slow stoch Bear Condition", Alert.BAR, AlertSound);
Alert(if AlertsOn and BullCondition then yes else no, "MBW BPT Slow Stoch Bull Condition", Alert.BAR, AlertSound);
 
I'm very far from being an expert, but tos labeling 'last price' as close is a bit misleading. tos seems to choose a price out of the avalanche of price data that's available and says, 'here, use this'. Its why different charts, even in tos, show different prices at roughly the same time. tos also limits your ability to pull price at the micro-time level, due to the sheer data tos would have to download to users.

imo, if you need that level of detail for 'last price', tos is the wrong platform for you, probably, any retail platform is the wrong platform
 
Hi Guys, I need help on my first post here. I've been looking for Stochastic upper label for awhile but nowhere to find one so I figured it out how to add upper label.

If anyone could help adjust the code, I'm trying to separate color of %K >or< 50%. I'm looking for %K > 50 then shows color green or blue (doesn't matter), and then if %K <50 then shows color red or orange. the only code I added from original StochasticFAST is at the bottom

Thanks guy, really appreciate it! Also, all lines still show on upper study if you can hide or remove them please do, if not I can unselect to not show on study later.


Code:
#
# Stochastic %K label
#

declare upper;

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

plot FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK;
plot FastD = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;

def upK = FastK crosses above OverSold;
def upD = FastD crosses above OverSold;
def downK = FastK crosses below OverBought;
def downD = FastD crosses below OverBought;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;
case "On FastK":
    UpSignal = if upK then OverSold else Double.NaN;
    DownSignal = if downK then OverBought else Double.NaN;
case "On FastD":
    UpSignal = if upD then OverSold else Double.NaN;
    DownSignal = if downD then OverBought else Double.NaN;
case "On FastK & FastD":
    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");

FastK.SetDefaultColor(GetColor(5));
FastD.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);

AddLabel(yes, "%K= " + FastK, Color.BLUE);
 
Last edited:
@elreytrder Here you go

Code:
#
# Stochastic %K label
#

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

def FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK;
def FastD = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def upK = FastK crosses above OverSold;
def upD = FastD crosses above OverSold;
def downK = FastK crosses below OverBought;
def downD = FastD crosses below OverBought;

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

AddLabel(yes, Concat("FastK = ", FastK), if FastK > 50 then color.green else if FastK < 50 then color.red else color.gray);
 
@elreytrder Here is a more appreviated version of @BenTen's script
SQMnso6.png

Ruby:
#
# Stochastic %K label
#

declare upper;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;


def FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK;
AddLabel(yes, "%K= " + round(FastK,2), if FastK > 50 then color.green else color.red);
 
Last edited:
@elreytrder Here you go

Code:
#
# Stochastic %K label
#

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

def FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK;
def FastD = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def upK = FastK crosses above OverSold;
def upD = FastD crosses above OverSold;
def downK = FastK crosses below OverBought;
def downD = FastD crosses below OverBought;

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

AddLabel(yes, Concat("FastK = ", FastK), if FastK > 50 then color.green else if FastK < 50 then color.red else color.gray);
Thank you Ben !
@elreytrder Here is a more appreviated version of @BenTen's script
SQMnso6.png

Ruby:
#
# Stochastic %K label
#

declare upper;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;


def FastK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 1, averageType).FullK;
AddLabel(yes, "%K= " + round(FastK,2), if FastK > 50 then color.green else color.red);
FYI for future reference To share code in your post, click on this icon at the top of your post and then past the code.
QNUw9Yh.png

More Guidelines for When Asking For Help with A Study
HTH
Thank you Guys! @BenTen @MerryDay
 
Hello all,
I use the Stochastic Slow as one of my indicators on the Daily time frame.
The settings are
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 1;

I want to be able to turn this into a scanner so that if a stock falls below the oversold range (under 20) it will show up on my scan.

I tried this for the code but this is not working for me. I also watched couple videos but i can't seem to get it to work. Any help would be appreciated.
Code:
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 1;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On SlowK", "On SlowD", "On SlowK & SlowD"};

def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullK;
def SlowD = reference
StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageType).FullD;
def OverBought = over_bought;
def OverSold = over_sold;

def Data = (SlowK[1] < SlowD[1]) and (SlowK > SlowD) ;
 
@crashed323 Welcome to the usethinkscript forums...

It appears that you're making this out to be harder than it needs to be... Wouldn't it be easier to simply reference StochasticSlow.OverSold rather than trying to rewrite history...??? Doesn't the Scanner Conditional Wizard panel below display what you are looking for...??? You could just as easily use is less than or equal to...

HlQXHYM.png
 
Oh yes I didnt think of that. Not sure why i didnt find that as an option when i was messing with it last night.
Thank you will be testing it now.
 
Hello script geniuses,

I've stumbled on a script which was posted by tc815. Seems he is not an active member within this community so it's hard to ask any questions or making requests. With that said, I would love for anyone that has the awesome knowledge to convert this script into a SCANNER. I personally see a potential in it, but lack the knowledge of writing scripts.....

Here it is the Code:


def agg=aggregationPeriod.FIVE_MIN;
def na = Double.NaN;
input ORBegin = 930;
input OREnd = 1600;
def ORActive = if SecondsTillTime(OREnd) > 0 and SecondsTillTime(ORBegin) <= 0 then 1 else 0;
def today = GetDay() == GetLastDay();
def numDevDn = -2.0;
def numDevUp = 2.0;
def timeFrame = 3 ;

def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == 3 and cap >= AggregationPeriod.WEEK or
timeFrame == 3 and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
#switch (timeFrame) {
#case DAY:
periodIndx = yyyyMmDd;
#}
#def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

#if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);

def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

input filterfrom_1_20= 10;
def Sover_bought = 80;
def Sover_sold = 20;
def SKPeriod = 14;
def SDPeriod = 3;
def SpriceH = high;
def SpriceL = low;
def SpriceC = close;
def SaverageType = AverageType.SIMPLE;

def SlowK = reference StochasticFull(Sover_bought, Sover_sold, SKPeriod, SDPeriod, SpriceH, SpriceL, SpriceC, 3, if (SaverageType == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def SlowD = reference StochasticFull(Sover_bought, Sover_sold, SKPeriod, SDPeriod, SpriceH, SpriceL, SpriceC, 3, if (SaverageType == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullD;
def SOverBought = Sover_bought;
def SOverSold = Sover_sold;

#-----------------------------------------------------MACD--------------------------------
def MfastLength = 12;
def MslowLength = 26;
def MACDLength = 9;
def MaverageType = AverageType.EXPONENTIAL;
def MshowBreakoutSignals = no;

def Value = MovingAverage(MaverageType, close, MfastLength) - MovingAverage(MaverageType, close, MslowLength);
def Avg = MovingAverage(MaverageType, Value, MACDLength);

def Diff = Value - Avg;
def ZeroLine = 0;
def hod = if today and hod[1] == 0 then Value else if ORActive and today and Value > hod[1] then Value else hod[1];
def lod = if today and lod[1] == 0 then Value else if ORActive and today and Value < lod[1] then Value else lod[1];

def prctcalc = (filterfrom_1_20/ 100);
def separation = (hod - lod) * prctcalc;
#addlabel(yes,separation,color.green);
#addlabel(yes,prctcalc);
def conditionlong1 = SlowK crosses above SlowD and SlowK < Sover_sold and SlowD < Sover_sold;
def conditionlong2 = Value < 0 and Avg < 0 and Value - Avg > separation or Value < 0 and Avg < 0 and Value - Avg < -separation;

def conditionshort1 = SlowK crosses below SlowD and SlowK > Sover_bought and SlowD > Sover_bought;
def conditionshort2 = Value > 0 and Avg > 0 and Value - Avg > separation or Value > 0 and Avg > 0 and Value - Avg < -separation;
def confirmation = Value crosses below Avg;
plot long = if SecondsFromTime(ORBegin) > 0 and SecondsFromTime(OREnd) < 0 and conditionlong1 and conditionlong2 then low else Double.NaN;
long.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
long.SetDefaultColor(Color.GREEN);
plot short = if SecondsFromTime(ORBegin) > 0 and SecondsFromTime(OREnd) < 0 and conditionshort1 and conditionshort2 then high else Double.NaN;
short.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
short.SetDefaultColor(Color.RED);
 
Last edited by a moderator:
You might also consider copying that script and adding it to a custom watchlist column so it lights up on stocks you're interested in.
BxVAX3.png
 
This thing works beautifully for the time I had left before market closed.....it's set for 5 min.....have you tried to maybe change it to 1m 2m 15m 1 hour??? Wonder if it would work?
 
This thing works beautifully for the time I had left before market closed.....it's set for 5 min.....have you tried to maybe change it to 1m 2m 15m 1 hour??? Wonder if it would work?
@Stock Tradin kindly explain the details or why were you interested in the scanner specifically this script, please? What does it provide you if wouldn't mind sharing? Thanks. @cabe1332
 

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