Alert When FullK Crosses Below FullD and Overbought


0
0
  1. I’d like this stochastic to cross down from 80 (overbought) and display a signal, but it’s not plotting at all. What am I doing wrong?
    1. See attached file
  2. Are there more sound that just bell? What other sounds may I change to? How do I have it display an alert message too?
    1. See attached file 
  3. Is there a way to combine the above two codes into one – crosses below 80 and give alert?

Please advise. Thank you.

Kim

Attachments:
Marked as spam
Posted by (Questions: 23, Answers: 57)
Asked on May 19, 2017 7:29 pm
358 views
0

Editors’s note. I have changed both the title of the question as well as the URL to more accurately reflect the context of this entire post. This will assist others how are seeking a similar solution to find this post.

( at May 20, 2017 1:06 pm)
0
Private answer

Let’s make it easier on future visitors to this site by showing the code you attached in a separate text file:

Plot Data = (FullK[1] > FullD[1]) and (FullK < FullD) and (highest (FullK[1],3) crosses below 80);

So the first line states. Plot when FullK crosses from Above the FullD on the first bar and ends up with FullK below the FullD on the second bar. Then to this you have added a strange bit of code. The code is saying, (excluding the current value of FullK) the highest value of FullK from the last three bars crosses below 80. I cannot imagine that last section of code doing anything at all.

Alert(highest (FullK[1],3) crosses below 80, "", Alert.BAR, Sound.Bell);

And it is certainly not going to do anything when used as a condition for an alert.

Now let’s see how we patch this up and get it working. In your description you stated only that you wanted the signal and alert when the FullK crossed from above 80 to below 80. However your code includes an extra rule. And that is that the FullK should be crossing below the FullD. What we don’t know from both sources is whether you want to test when both rules occur at the same time of if you want to allow for some number of bars to pass before FullK dives back below 80. In the code I provide, I am going to break things down into pieces to make it easier to read the code and understand what each part is doing.
def fullKCrossesFromOverbought = FullK[1] > 80 and FullK < 80;
def fullKCrossesBelowFullD = FullK[1] > FullD[1] and FullK < FullD;
def signal = fullKCrossesFromOverbought and fullKCrossesBelowFullD;
Alert(signal, "FullK and FullD Crossing: Overbought", Alert.BAR, Sound.RING);

You can read more about the Alert() function here: http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Alert.html

My example shows you how to define the text that displays with your alert. You can find a list of the available sounds here: http://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Sound.html

And don’t forget that once you have added an Alert() statement to a study, the settings for that alert can be adjusted from the “Edit Studies” window.

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on May 20, 2017 1:25 pm
0
Private answer

Hi Pete,

Thank you! That’s very helpful. Follow up questions:

If I want to add the logic for Overbought, all I need to change in the code is just to change from “Oversold” to “Overbought” and change “80” to “20” and “Below” to “Above”?

Please advise. Thanks!

Marked as spam
Posted by (Questions: 23, Answers: 57)
Answered on May 21, 2017 7:40 pm
0

I just realized I used the term Oversold where I should have used the term Overbought. So I updated the post title, URL and code solution to reflect that Stochastic above 80 is actually Overbought. The code I list here shows how to reverse the entire signal, for the Oversold condition.

You would also have to flip the signs (greater than to less and less than to greater than). Here is what the code looks like for that:

def fullKCrossesFromOverbought = FullK[1] < 20 and FullK > 20;
def fullKCrossesAboveFullD = FullK[1] < FullD[1] and FullK > FullD;
def signal = fullKCrossesFromOverbought and fullKCrossesAboveFullD;
Alert(signal, ”FullK and FullD Crossing: Oversold”, Alert.BAR, Sound.RING);

( at May 22, 2017 7:45 am)
0
Private answer

Hi Pete,

It’s working nicely. Thanks! Follow up questions:

  1. On an uptrend (>200 SMA), I want the signal to be that it pulls backs to 21 EMA or 50 EMA when it hooks up from 20. Is this the code for that: SimpleMovingAve(“length” =200) is less than or equal to close and MovAvgExponential(“length”=21) is greater than or equal to close and MovAvgExponential(“length”=50) is greater than or equal to close?
  2. On a downtrend (<200 SMA), I want the signal to be that it pulls up to 21 EMA or 50 EMA when it hooks down from 80. Is this the code for that: SimpleMovingAve(“length” =200) is greater than or equal to close and MovAvgExponential(“length”=21) is less than or equal to close and MovAvgExponential(“length”=50) is less than or equal to close?
Marked as spam
Posted by (Questions: 23, Answers: 57)
Answered on May 22, 2017 1:55 pm
0

If you want to dig into this new specification a bit deeper be sure to post it as a new question so we can prevent confusing futures videos to this post.

The specification ”pulls back to the 21 EMA or 50 EMA”

is not going to be correctly addressed by

”MovAvgExponential(“length”=21) is greater than or equal to close and MovAvgExponential(“length”=50) is greater than or equal to close”

This is because your specification is for a pull back to 21 EMA or 50 EMA and your code is using the word AND instead of the word OR. You can use parentheses to separate the different elements but I find it easier to just put them on a separate line and name them accordingly.

( at May 22, 2017 2:45 pm)
0
Private answer

Hi Pete,

Do I need this line of code in the scanner:

Plot signal = fullKCrossesFromOverbought and fullKCrossesBelowFullD;

Or I just have your line of code:

def signal = fullKCrossesFromOverbought and fullKCrossesAboveFullD;

?

And the scanner will scan correctly with that?

Please advise. Thanks!

Marked as spam
Posted by (Questions: 23, Answers: 57)
Answered on May 22, 2017 8:01 pm
0

Yes, this line of code will work in the scanner:
Plot signal = fullKCrossesFromOverbought and fullKCrossesBelowFullD;

( at May 23, 2017 7:57 am)