Momentum indicator with sound alert


0
0

Mr. Hahn, I have been trying to create a sound alert for a momentum indicator.  It does not work.

Any help would be appreciated. See attached code:

#
# TD Ameritrade IP Company, Inc. (c) 2009-2020
#

#wizard input: crossingType
#wizard text: Inputs: length:
#wizard input: length

input length = 12;
input crossingType = {default “Positive to Negative”, “Negative to Positive”};

assert(length > 0, “‘length’ must be positive: ” + length);

def price = close;
def momentum = price – price[length];

plot signal = crosses(momentum, 0, crossingType == CrossingType.”Negative to Positive”);

signal.DefineColor(“Negative to Positive”, GetColor(3));
signal.DefineColor(“Positive to Negative”, GetColor(4));
signal.AssignValueColor(if crossingType == CrossingType.”Negative to Positive” then signal.color(“Negative to Positive”) else signal.color(“Positive to Negative”));
signal.SetPaintingStrategy(if crossingType == CrossingType.”Negative to Positive”
then PaintingStrategy.BOOLEAN_ARROW_UP
else PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(UpSignal == ZeroLine, “Up Arrow Alert”, Alert.BAR, Sound.RING);
Alert(DownSignal == ZeroLine, “Down Arrow Alert”, Alert.BAR, Sound.RING);

Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on April 21, 2020 7:06 pm
253 views
0
How do you define the signal that should generate an alert? Since your code does not work I cannot read the code and guess what you are trying to accomplish.
( at April 21, 2020 7:49 pm)
0
I copied the TOS Momentum Cross indicator. I added a sound alert code from another indicator. A sound alert when the momentum line crosses over the zero line in either direction is what I am looking for. Sorry for the confusion
( at April 22, 2020 4:38 pm)
0
Private answer

Ok, now that we have some clarification on what signal should trigger an alert we have the following solution:

Alert(signal, “Momentum Alert”, Alert.BAR, Sound.RING);

Notice that my solution does not differentiate between up signal or down signal. The reason for this is because the direction of the signal is determined further upstream, in the user inputs. Specifically, the user input named "crossingType".

In the interest of providing some educations how does this compare to what you attempted?

In the last two lines you added to the code we find that you have added three variable names that were not previous defined. Let's take a look at what you had:

Alert(UpSignal == ZeroLine, “Up Arrow Alert”, Alert.BAR, Sound.RING);
Alert(DownSignal == ZeroLine, “Down Arrow Alert”, Alert.BAR, Sound.RING);

So we find the following variables that were never defined in the code:

UpSignal
DownSignal
ZeroLine

So when you try to say "UpSignal == ZeroLine", the English interpretation of this is:

undefined variable equals undefined variable

This creates a compiler error and the study cannot be saved an applied to the chart until the error is corrected.

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on April 22, 2020 5:22 pm
0
Thank you Mr. Hahn, this is exactly want I wanted. This coupled with your EMA alert and MACD divergence makes a trade entry point much easier.
( at April 26, 2020 1:48 pm)