Chart Study alert for Stochastic FullK overbought / oversold


Category:
0
0

Hi Pete,

I was wondering how to create an alert on the actual chart itself regardless of the symbol. I have a script I created for study alerts, but I would like it on the actual chart just like for example when you gave out the Heikin Ashi bar color change alert. Here is my script, basically I just want it to alert me when the stochastics are Overbought/Oversold or 70+ & 30-

StochasticFull(“k period” = 9, “d period” = 3).”FullK” is less than 30 or StochasticFull(“k period” = 9, “d period” = 3).”FullK” is greater than 70

Marked as spam
Posted by (Questions: 1, Answers: 7)
Asked on July 19, 2023 8:07 am
79 views
0
Private answer

I updated the title of your question to better describe the context of your request. This will help the rest of our viewers to locate this solution using the search function. There are many examples of chart study alerts scattered throughout this forum. But I don't think anyone has requested a solution for Stochastic FullK overbought/oversold.

Let's begin by providing the language reference for the Alert() function used in Thinkorswim:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Alert

From that resource we see that the Alert() function takes 4 parameters. The first of which is the true/false conditions used to trigger the alert. You sample script combines the overbought and oversold conditions into one statement. We can separate that into separate true/false conditions as follows:

def oversold = StochasticFull(“k period” = 9, “d period” = 3).”FullK” is less than 30;

def overbought = StochasticFull(“k period” = 9, “d period” = 3).”FullK” is greater than 70;

Notice that those conditions are merely checking if the FullK is in the oversold condition or the overbought condition. If we use them exactly as they are, the chart study alert will get triggered for each and every bar in which the FullK is either overbought or oversold. Some may find this annoying, and prefer a solution which only captures the first bar which crosses into oversold or overbought range. However that would not exactly match the behavior of the sample script you provided. So this solution will attempt to hold true to the exact conditions you have specified.

In order to add the chart study alerts we only need to add two more lines of code:

Alert(oversold, "FullK Oversold", Alert.BAR, Sound.RING);

Alert(overbought, "FullK Overbought", Alert.BAR, Sound.RING);

The only thing lacking now are some plots. We can take those same conditions which trigger the alerts and use them to plot arrows on the price graph. The following solution puts all those pieces together:

plot oversold = StochasticFull(“k period” = 9, “d period” = 3).”FullK” is less than 30;
oversold.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
oversold.SetLineWeight(3);
oversold.SetDefaultColor(Color.CYAN);
plot overbought = StochasticFull(“k period” = 9, “d period” = 3).”FullK” is greater than 70;
overbought.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
overbought.SetLineWeight(3);
overbought.SetDefaultColor(Color.MAGENTA);
Alert(oversold, "FullK Oversold", Alert.BAR, Sound.RING);
Alert(overbought, "FullK Overbought", Alert.BAR, Sound.RING);

And I know many folks are going to find that pretty annoying, having the alert fire off for every bar that is overbought or oversold instead of just the first bar that crosses. So you can modify the plot statements as follows:

plot oversold = StochasticFull(“k period” = 9, “d period” = 3).”FullK” crosses below 30;
plot overbought = StochasticFull(“k period” = 9, “d period” = 3).”FullK” crosses above 70;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on July 19, 2023 8:37 am
0
Thanks very much Pete you rock! Employees from the TOS platform had no solutions for this and you just did it in less than an hour.
( at July 19, 2023 8:48 am)
0
Wow, that's surprising. Glad I could help. Be sure to spread the word and share this post with all your trading buddies!
( at July 19, 2023 9:40 am)