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

Need some help.
im trying to create an alert for two conditions in the Slow Stoch.
I. when slow K is above 80, and then crosses below slow D - want a down arrow and an audible alert
II. when slow K is less than 20 and then crosses above slow D - want an up arrow and audible alert
(no alerts if there are crosses when K is between 80-20)

See my attempt below.
I've created "signal" which accomplishes "I." and "signal two" which accomplishes II. -- but i cant seem to get the arrows to work.
All of my attempts end up putting arrows corresponding with every single candle as opposed to just when the crossover occurs

can anyone help?
I didn't check your logic. I just added the arrow statements.
qovtJUT.png

Ruby:
declare lower;

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

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

def slowKOverbought = slowK[1] > 80;
def slowKCrossesBelowSlowD = slowK[1] > slowD[1] and slowK < slowD;
plot signal = if slowKOverbought and slowKCrossesBelowSlowD then SlowK else double.NaN;
     signal.SetPaintingStrategy(PaintingStrategy.ARROW_down);
     signal.SetDefaultColor(color.magenta) ;
     signal.SetLineWeight(1);

Alert(signal, "SlowK and SlowD Crossing: OverBought", Alert.BAR, Sound.RING);

def slowKOverSold = slowK[1] < 20;
def slowKCrossesAboveFullD = slowK[1] < slowD[1] and slowK > slowD;
plot signaltwo = if slowKOverSold and slowKCrossesAboveFullD then SlowK else double.NaN;;
     signaltwo.SetPaintingStrategy(PaintingStrategy.ARROW_up);
     signaltwo.SetDefaultColor(color.blue) ;
     signaltwo.SetLineWeight(1);

Alert(signaltwo, "SlowK and SlowD Crossing: OverSold", Alert.BAR, Sound.RING);
 
Is it possible to create this label with multiple lengths/periods/mtf?
Yes, you can create the code with different lengths/periods/mtf. It is a boring, redundant process which will result in repainting issues.
So it is unlikely a member will provide this for you.
But if you want to take it on yourself, it is easy enough even for those with no coding experience.
This easy MTF tutorial was posted as an option for non-programmers interested in creating their own MTF indicators.
 
Last edited:
Yes, you can create the code with different lengths/periods/mtf. It is a boring, redundant process which will result in repainting issues.
So someone else will probably not take this on.
But if you want to take it on yourself, it is easy enough even for those with no coding experience.
This easy MTF tutorial was posted as an option for non-programmers interested in creating their own MTF indicators.
Thank you for replying. I'm learning to code as I go. I see that I'm not the only 1 trying to implement this logic. I was able to revise the label you provided to fit my needs for now, Thanks
 
Last edited:
Hello everyone, I use a variety of indicators for bullish/bearish signals. I need some help with the script for when a signal is either bullish or bearish, but it is in between the bull/bear signal zones.
For example, the code below uses the stochastic oscillator. The histogram is painted green when it is overbought, red when it is oversold, and yellow when it is in between those levels.
A bull signal is generated when FullD crosses above 60 and I assign 1 point.
A bear signal occurs when FullD crosses below 40 and I assign -1 point.
Once the signal occurs, I want to have the point value remain at either +1 or -1 until a new signal reverses the existing one. Zero points is not wanted.
I'm assuming that I need to use the Case or Switch statements, but I've never written that script.

#Declarations
declare lower;

#Inputs
input over_bought = 60;
input over_sold = 40;
input KPeriod = 126;
input DPeriod = 5;
input priceH = close;
input priceL = close;
input priceC = close;
input slowing_period = 1;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

#Definitions
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 AboveOB = FullD > over_bought;
def BetweenOBOS = FullD <= over_bought and FullD >= over_sold;
def StochClose = StochasticFull(UTLevel, DTLevel, StochLength, StochSMA, Price, Price, Price, SlowP)."FullD";
def SCSignal = if StochClose > UTLevel then 1 else if SCSignal[1] == 1 and StochClose >= DTLevel then 1 else if StochClose < DTLevel then -1 else if SCSignal[1] ==-1 and StochClose <= UTLevel then -1 else 0;

#Plots
plot StochClose = FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;

#Painting Strategies
StochClose.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochClose.AssignValueColor(If BetweenOBOS then Color.YELLOW else if AboveOB then Color.GREEN else Color.RED);

Any assistance would be appreciated.
 
Hello, can someone be able to make me a stochastic slow D and Slow K cross overs for the upper chart. So I would see an arrow on the candle to the upside or downside when they cross each other.
 
Last edited by a moderator:
What I would like help with is the following: FullD is above 60 and the indicator is set to 1. The indicator will remain at 1 until FullD crosses below 40, which will change the indicator to -1. Conversely, the indicator remains at -1 until FullD crosses back above 60.
Any help would be appreciated.
 
What I would like help with is the following: FullD is above 60 and the indicator is set to 1. The indicator will remain at 1 until FullD crosses below 40, which will change the indicator to -1. Conversely, the indicator remains at -1 until FullD crosses back above 60.
Any help would be appreciated.

something like this

def x = if barnumber() == 1 then 0
else if fulld crosses below 40 then -1
else if fulld crosses above 60 then 1
else x[1];
 
Hello, can someone be able to make me a stochastic slow D and Slow K cross overs for the upper chart. So I would see an arrow on the candle to the upside or downside when they cross each other.
# SlowK Crossing SlowD Stochastic Arrows Upper Chart
Ruby:
# SlowK Crossing SlowD Stochastic Arrows Upper Chart
# @MerryDay 7/2022
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.SIMPLE;

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;

plot upside = slowk crosses above slowd ;
     upside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);
     upside.SetDefaultColor(color.blue) ;
     upside.SetLineWeight(1);

plot downside = slowk crosses below slowd  ;
     downside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
     downside.SetDefaultColor(color.red) ;
     downside.SetLineWeight(1);
N7lk0i0.png
 
I was looking for some sort of signal when the FullK and FullD signals crossed and where in the over sold/bought area.

Did not find anything so I modded the included study.

Hope it helps someone.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#
# StochasticFull Modded to show arrow when FullK and FullD cross and are above/below over bought over sold
#

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"};
input showCrossoverSignals = {default "No", "Yes"};

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


plot crossUpSignal;
plot crossDownSignal;
switch (showCrossoverSignals) {
case "No":
    crossUpSignal = Double.NaN;
    crossDownSignal = Double.NaN;
case "Yes":
    crossUpSignal = if FullK crosses FullD and FullK >= OverBought and FullD >= OverBought then FullK else Double.NaN;
    crossDownSignal = if FullK crosses FullD and Fullk <= OverSold and FullD <= OverSold then FullD else Double.NaN;

}

crossUpSignal.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
crossUpSignal.SetDefaultColor(Color.Red);

crossDownSignal.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
crossDownSignal.SetDefaultColor(Color.Green);
 
Last edited:
I was looking for some sort of signal when the FullK and FullD signals crossed and where in the over sold/bought area.

Did not find anything so I modded the included study.

Hope it helps someone.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#
# StochasticFull Modded to show arrow when FullK and FullD cross and are above/below over bought over sold
#

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"};
input showCrossoverSignals = {default "No", "Yes"};

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


plot crossUpSignal;
plot crossDownSignal;
switch (showCrossoverSignals) {
case "No":
    crossUpSignal = Double.NaN;
    crossDownSignal = Double.NaN;
case "Yes":
    crossUpSignal = if FullK crosses FullD and FullK >= OverBought and FullD >= OverBought then FullK else Double.NaN;
    crossDownSignal = if FullK crosses FullD and Fullk <= OverSold and FullD <= OverSold then FullD else Double.NaN;

}

crossUpSignal.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
crossUpSignal.SetDefaultColor(Color.Red);

crossDownSignal.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
crossDownSignal.SetDefaultColor(Color.Green);
@fabriciom Thank you so much for sharing this code. Can you please code it so that the arrows show in the upper chart? I would really appreciate it.
 
@fabriciom Thank you so much for sharing this code. Can you please code it so that the arrows show in the upper chart? I would really appreciate it.

Hello,

I don't understand what you mean with the "upper chart".

Do you mean above the over bought and over sold line?

If you want the chart to show in the upper part of your screen like the candle sticks just comment the first line with "#declare lower;".
 
Last edited:
Can anyone make a StochasticMacd buy and sell indicator that uses StochasticMacd and StochasticSlow. Much appreciated in advance.
 
Last edited by a moderator:
I was able to find the below script. I see SleepyZ posted it on someone else's question, either SleepyZ created it or obtained it somewhere else. Either way, I much appreciated it. Not exactly what I was looking for but close enough.

def rsi = reference rsi();
def macdsignal = reference MACD().Diff;
def stoK= reference stochasticfull().fullK;

assignPriceColor(if rsi>50 and stok>50 and macdsignal>0
then color.green
else if rsi<50 and stok<50 and macdsignal<0
then color.red
else color.black);
 
Last edited:
Looking for someone to add crossover arrows to the StochasticMomemtumIndex please. Thank you.
 
Last edited:
Looking for someone to add crossover arrows to the StochasticMomemtumIndex please. Thank you.

This allows an input option to show crossover arrows.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#

declare lower;

input crossover_arrows = yes;
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
SMI.SetDefaultColor(GetColor(1));

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));

plot overbought = over_bought;
overbought.SetDefaultColor(GetColor(5));

plot oversold = over_sold;
oversold.SetDefaultColor(GetColor(5));

#Arrows
plot uparrow = if !crossover_arrows then Double.NaN       
               else if SMI crosses above AvgSMI
               then SMI
               else Double.NaN;
uparrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
uparrow.SetLineWeight(3);
uparrow.SetDefaultColor(GetColor(1));

plot dnarrow = if !crossover_arrows then Double.NaN       
               else if SMI crosses below AvgSMI
               then SMI
               else Double.NaN;
dnarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DoWN);
dnarrow.SetLineWeight(3);
dnarrow.SetDefaultColor(GetColor(5));
 
I am looking for Arrows for buy and sell signals when there is a cross in the up or down move on the Stochastic Slow. Very much appreciate. Thank you.
 
Last edited:
I am looking for Arrows for buy and sell signals when there is a cross in the up or down move on the Stochastic Slow. Very much appreciate. Thank you.
Not sure what you are asking, the ToS Stochastic slow already has buy / sell signals. Perhaps you didn't turn on signals in settings:
hi0UmSY.png
 
Last edited:
I was provided the below script graciously from SleepyZ. I am trying to have it to only provide StochasticMomenutemIndex crossover arrow as an entry and MACD crossover arrow as an exit for both directions in my trades. To be displayed in the Candle chart area as entries and exits. I hope this makes sense. Can someone help created the script for me, I still am not good enough to even figure this out. I appreciate your time and efforts. Thank you. Not sure if the below script will help since this displays below the chart. Thank you.

#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#

declare lower;

input crossover_arrows = yes;
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
SMI.SetDefaultColor(GetColor(1));

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));

plot overbought = over_bought;
overbought.SetDefaultColor(GetColor(5));

plot oversold = over_sold;
oversold.SetDefaultColor(GetColor(5));

#Arrows
plot uparrow = if !crossover_arrows then Double.NaN
else if SMI crosses above AvgSMI
then SMI
else Double.NaN;
uparrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
uparrow.SetLineWeight(3);
uparrow.SetDefaultColor(GetColor(1));

plot dnarrow = if !crossover_arrows then Double.NaN
else if SMI crosses below AvgSMI
then SMI
else Double.NaN;
dnarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DoWN);
dnarrow.SetLineWeight(3);
dnarrow.SetDefaultColor(GetColor(5));
 
Not sure on the MACD what you were intending to crossover: This will get you started.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2022
#


input SMI_crossover_arrows = yes;
input MACD_crossover_arrows = yes;
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;


def AvgSMI = ExpAverage(SMI, percentDLength);



input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
input price = close;

def signal = reference MACD(fastLength, slowLength, macdLength, averageType).Avg;
def macd = reference MACD(fastLength, slowLength, macdLength, averageType).Value;
plot buymacd =  MACD_crossover_arrows and macd crosses above signal;
buymacd.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buymacd.SetLineWeight(3);
buymacd.setDefaultColor(Color.Blue);
plot sellmacd = MACD_crossover_arrows and macd crosses below signal;
sellmacd.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
sellmacd.SetLineWeight(3);
sellmacd.setDefaultColor(Color.Magenta);

# SMI Arrows
plot uparrow = if !SMI_crossover_arrows then Double.NaN
else if SMI crosses above AvgSMI
then SMI
else Double.NaN;
uparrow.SetPaintingStrategy(PaintingStrategy.BoOLEAN_ARROW_UP);
uparrow.SetLineWeight(3);
uparrow.SetDefaultColor(GetColor(1));

plot dnarrow = if !SMI_crossover_arrows then Double.NaN
else if SMI crosses below AvgSMI
then SMI
else Double.NaN;
dnarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DoWN);
dnarrow.SetLineWeight(3);
dnarrow.SetDefaultColor(GetColor(5));
 

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