I need some help with Alert Bar coding

Mart

New member
VIP
What I am trying to do is have an alarm after the last maximum point is plotted.

The def Signal line is not correct can some one explain, Thanks.


def sma1 = SimpleMovingAvg(close, 10);
def Signal = Alert.BAR, Sound.Ring;

Alert(Signal == 1, "NewHighIsDone", Alert.BAR, Sound.Ring);

plot sma1higher = if sma1 > sma1[1] then sma1 else Signal and Double.NaN;
sma1higher.SetLineWeight (1);

================================================

I also tried to use some code from halcyonguy
that is not working for me either.

#up
alert(a, "up", alert.bar, sound.ding);

#down
alert(b, "down", alert.bar, sound.bell);

input barsback = 8;
# check if current high is higher than prev x bars
# these will be 1 or 0 , true or false
def ishigher = ( high > highest( high[1], barsback) );
def islower = ( low < lowest[1], barsback) );

then use ishigher as the trigger variable in 1 alert function, and use islower in the other alert.
 
Last edited:
Solution
What I am trying to do is have an alarm after the last maximum point is plotted.

The def Signal line is not correct can some one explain, Thanks.


def sma1 = SimpleMovingAvg(close, 10);
def Signal = Alert.BAR, Sound.Ring;

Alert(Signal == 1, "NewHighIsDone", Alert.BAR, Sound.Ring);

plot sma1higher = if sma1 > sma1[1] then sma1 else Signal and Double.NaN;
sma1higher.SetLineWeight (1);

================================================

I also tried to use some code from halcyonguy
that is not working for me either.

#up
alert(a, "up", alert.bar, sound.ding);

#down
alert(b, "down", alert.bar, sound.bell);

input barsback = 8;
# check if current high is higher than prev x bars
# these will be 1 or 0 , true or...
What I am trying to do is have an alarm after the last maximum point is plotted.

The def Signal line is not correct can some one explain, Thanks.


def sma1 = SimpleMovingAvg(close, 10);
def Signal = Alert.BAR, Sound.Ring;

Alert(Signal == 1, "NewHighIsDone", Alert.BAR, Sound.Ring);

plot sma1higher = if sma1 > sma1[1] then sma1 else Signal and Double.NaN;
sma1higher.SetLineWeight (1);

================================================

I also tried to use some code from halcyonguy
that is not working for me either.

#up
alert(a, "up", alert.bar, sound.ding);

#down
alert(b, "down", alert.bar, sound.bell);

input barsback = 8;
# check if current high is higher than prev x bars
# these will be 1 or 0 , true or false
def ishigher = ( high > highest( high[1], barsback) );
def islower = ( low < lowest[1], barsback) );

then use ishigher as the trigger variable in 1 alert function, and use islower in the other alert.

The def Signal is not a boolean (yes/no, 1/0, true/false) signal needed to trigger an alert. Your code was just attributes of the Alert function and not useable to trigger an alert.

The following code triggers the alert when the current bar is a double.nan (IsNaN(sma1higher)) and the prior bar is a number and not a double.nan (!IsNaN(sma1higher[1]).

The alert may make false triggers, as does most alerts using the current bar as part of the trigger, if the current developing bar changes from a true/false condition on that bar. In your case, the current bar may be a continuation of the SMA and change to not being a continuation, creating multiple alerts on the same bar, some being false ultimately.

To visually alert you, the code below has a chart bubble option to display at the low of the bar that triggers your alert, the message "NewHighIsDone".

Capture.jpg
Ruby:
def sma1 = SimpleMovingAvg(close, 10);
#def Signal = Alert.BAR, Sound.Ring;
#Alert(Signal == 1, "NewHighIsDone", Alert.BAR, Sound.Ring);

plot sma1higher = if sma1 > sma1[1] then sma1 else Double.NaN;
sma1higher.SetLineWeight (5);

input usealert = yes;
Alert(usealert and IsNaN(sma1higher) and !IsNaN(sma1higher[1]), "NewHighIsDone", Alert.BAR, Sound.Ring);
input showbubbles = yes;
AddChartBubble(showbubbles and IsNaN(sma1higher) and !IsNaN(sma1higher[1]), low, "New\nHigh\nIs\nDone", Color.RED, no);
 
Solution
Many Thanks, your help is greatly appreciated.
It looks like you added 2 Alerts, sound and a bubble.
I will try them out after I get some sleep.
HAPPY HOLIDAYS
 
The audio alert works great. I hope someday to as good as you, Many thanks.
I am using declare lower and
when I activate the showbubbles line of code the text plots at 4695 on the subgraph
and the subgraph of the data is a horizontal line.
can the position of the showbubbles text be lowered?
 
The audio alert works great. I hope someday to as good as you, Many thanks.
I am using declare lower and
when I activate the showbubbles line of code the text plots at 4695 on the subgraph
and the subgraph of the data is a horizontal line.
can the position of the showbubbles text be lowered?

Yes, the bubbles can be moved up or down in the following code at the input bubbles_updn = 0; By increasing this number it will move the bubbles down and decreasing moving them up. It is then multiplied by the ticksize() of the chart you are viewing. The default is zero. In the image below it is set to 20 to move the bubbles down.

Also, included is an option to shorten the text in the bubble.

Added is a Verticalline option to use as a visual

Capture.jpg
Ruby:
input length = 10;
def sma1 = SimpleMovingAvg(close, length);

plot sma1higher = if sma1 > sma1[1] then sma1 else Double.NaN;
sma1higher.SetLineWeight (5);

input usealert = yes;
Alert(usealert and IsNaN(sma1higher) and !IsNaN(sma1higher[1]), "NewHighIsDone", Alert.BAR, Sound.Ring);

input showbubbles  = yes;
input bubbles_updn = 0;
AddChartBubble(showbubbles and IsNaN(sma1higher) and !IsNaN(sma1higher[1]),
               low - ticksize() * bubbles_updn,
               "High\nDone", #"New\nHigh\nIs\nDone",
               Color.RED, no);

input showvertical = yes;
addverticalLine(showvertical and IsNaN(sma1higher) and !IsNaN(sma1higher[1]),
                "High\nDone", #"New\nHigh\nIs\nDone",
                Color.RED, curve.firm);
 
Yes, I could use some help on this too. It’s been 50 years since I had a basic coding course (Fortran) most of which has been long forgotten.

Here’s my situation: I have an Alert on each stock in my portfolio. I would like to create a custom column script that would plot the percentage that the Alert is below the current price.

What is the code that I could use to call out the value of the Alert? I think I could do the rest. Thanks.
 
Yes, I could use some help on this too. It’s been 50 years since I had a basic coding course (Fortran) most of which has been long forgotten.

Here’s my situation: I have an Alert on each stock in my portfolio. I would like to create a custom column script that would plot the percentage that the Alert is below the current price.

What is the code that I could use to call out the value of the Alert? I think I could do the rest. Thanks.

to post 6
just came across this post,


an alert doesn't have a value.
do you mean to,
compare the close of the bar when the alert triggered,
to the current close?

maybe this will be close to what you are looking for.

this uses the crossing of 2 averages as a trigger.
replace the trigger formula with yours.

watchlist column study

Ruby:
# zalert_per_0

# https://usethinkscript.com/threads/i-need-some-help-with-alert-bar-coding.9418/#post-86406
# i need some help with Alert Bar coding
# wchillman  Jan 2, 2022
# I have an Alert on each stock in my portfolio. 
# I would like to create a custom column script that would plot the percentage that the Alert is below the current price.

#-------------------------------------


def bn = barnumber();
def na = double.nan;

#-------------------------------------
# replace this with your trigger code

# test trigger
input avg1_len = 10;
input avg1_type =  AverageType.simple;
def ma1 = MovingAverage(avg1_type, close, avg1_len);

input avg2_len = 80;
input avg2_type =  AverageType.simple;
def ma2 = MovingAverage(avg2_type, close, avg2_len);

def xup = if ma1 crosses above ma2 then 1 else 0;

#-------------------------------------


#def trigger = your code for alert trigger
def trigger = xup;

def trigger_close =
  if barnumber() == 1 then 0
  else if trigger then close
  else trigger_close[1];

# percent of change of close , from alert close
def per = round(100 * (( trigger_close - close ) / close ), 1);

plot z = per;
z.setdefaultcolor(color.black);

assignbackgroundcolor(if per > 0 then color.green else if per < 0 then color.red else color.gray);

# if you want to display text, disable the plot and use this addlabel 
# addlabel(1, per, color.black);
#
 

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