Can anyone help me to add Alerts

Hapme

New member
Code:
# Bill Williams Fractal Template
# Coded By: Rigel May 2018

#Define "n" as the number of periods and keep a minimum value of 2 for error handling.
input n=2;

# Williams Fractals are a 5 point lagging indicator that will draw 2 candles behind.
# The purpose of the indicator is to plot points of trend reversals.
# Often these are paired with trailing stop indicators such as Parabolic SAR, Volatility Stop, and SuperTrend.

# Down pointing fractals occur over candles when:
#   High(n-2) < High(n)
#   High(n-1) < High(n)
#   High(n + 1) < High(n)
#   High(n + 2) < High(n)
#dnFractal = (high[n-2] < high[n]) and (high[n-1] < high[n]) and (high[n+1] < high[n]) and (high[n+2] < high[n])

def isupfractal = if low < low[1] and low < low[2] and low < low[-1] and low < low[-2] then low else double.nan;
# Up pointing fractals occur under candles when:
#   Low(n-2) > Low(n)
#   Low(n-1) > Low(n)
#   Low(n + 1) > Low(n)
#   Low(n + 2) > Low(n)
#upFractal = (low[n-2] > low[n]) and (low[n-1] > low[n]) and (low[n+1] > low[n]) and (low[n+2] > low[n])
def isdownfractal = if high > high[1] and high > high[2] and high > high[-1] and high > high[-2] then high else double.nan;
# Plot the fractals as shapes on the chart.


plot upfractal = if( isupfractal, isupfractal+ (1 * tickSize()) , double.nan);
upfractal.SetPaintingStrategy(paintingStrategy.ARROW_UP);
plot downfractal = if( isdownfractal, isdownfractal - (1 * tickSize()), double.nan);
downfractal.SetPaintingStrategy(paintingStrategy.ARROW_DOWN);
 
I put the sequence c

i put the sequence to count to 1 and still goes wiith the previus candle close , not with the last , i will add a picture to see



I think I now understand that you just want a bubble for the close of the last candle. That is not dependent on the sequence counter, but a separate code as follows. This can be added to the sequence code or be a separate indicator.

Ruby:
def last = HighestAll(if !IsNaN(close) and IsNaN(close[-1]) then BarNumber() else Double.NaN);
AddChartBubble(BarNumber() == last, close, astext(close), if close > open then Color.GREEN else Color.RED, no);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I think I now understand that you just want a bubble for the close of the last candle. That is not dependent on the sequence counter, but a separate code as follows. This can be added to the sequence code or be a separate indicator.
Hey SleepyZ


Im trying to add Alerts to this script , when a new High is made , and when a new HL is made , could please have a look here
........................................................................................................................................................................................................................................

#PAS_sample by JayC @ https://futures.io/thinkorswim/56934-price-action-swing-conversion.html
input lookBack = 10;
input lookAhead = 5;

def isHigh = high >= Highest(high[1], lookBack) and high >= Highest(high[-lookAhead], lookBack);
def highValue = if BarNumber() < lookBack then Double.NaN else if isHigh then high else highValue[1];
AddChartBubble(isHigh and highValue != highValue[1], high, if highValue > highValue[1] then "HH" else "LH", Color.CYAN, yes);

#Added By DW
def LH = highValue < highValue[1];
plot LowerHigh = LH;



def isLow = low <= Lowest(low[1], lookBack) and low <= Lowest(low[-lookAhead], lookBack);
def lowValue = if BarNumber() < lookBack then Double.NaN else if isLow then low else lowValue[1];
AddChartBubble(isLow and lowValue != lowValue[1], low, if lowValue > lowValue[1] then "HL" else "LL", Color.LIGHT_RED, no);

#Added By DW
def HL = lowValue > lowValue[1];
plot HigherLow = HL;
#end code


#ZigZag Percent
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#

input price = close;
input reversalAmount = 8.0;
input showBubbles = no;
input showLabel = no;

assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else getValue(zzSave, 1);
def chg = (price / getValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(getValue("ZZ%", 1)) and getValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".color("Undefined") else if isUp then "ZZ%".color("Up Trend") else "ZZ%".color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = barNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"));
 
Hey SleepyZ


Im trying to add Alerts to this script , when a new High is made , and when a new HL is made , could please have a look here
........................................................................................................................................................................................................................................

#PAS_sample by JayC @ https://futures.io/thinkorswim/56934-price-action-swing-conversion.html
input lookBack = 10;
input lookAhead = 5;

def isHigh = high >= Highest(high[1], lookBack) and high >= Highest(high[-lookAhead], lookBack);
def highValue = if BarNumber() < lookBack then Double.NaN else if isHigh then high else highValue[1];
AddChartBubble(isHigh and highValue != highValue[1], high, if highValue > highValue[1] then "HH" else "LH", Color.CYAN, yes);

#Added By DW
def LH = highValue < highValue[1];
plot LowerHigh = LH;



def isLow = low <= Lowest(low[1], lookBack) and low <= Lowest(low[-lookAhead], lookBack);
def lowValue = if BarNumber() < lookBack then Double.NaN else if isLow then low else lowValue[1];
AddChartBubble(isLow and lowValue != lowValue[1], low, if lowValue > lowValue[1] then "HL" else "LL", Color.LIGHT_RED, no);

#Added By DW
def HL = lowValue > lowValue[1];
plot HigherLow = HL;
#end code


#ZigZag Percent
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#

input price = close;
input reversalAmount = 8.0;
input showBubbles = no;
input showLabel = no;

assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else getValue(zzSave, 1);
def chg = (price / getValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(getValue("ZZ%", 1)) and getValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".color("Undefined") else if isUp then "ZZ%".color("Up Trend") else "ZZ%".color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = barNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"));

The bubbles and thus the alert require the input lookahead, currently set to 5 bars past them to the right. to be met before the bubbles will appear and the alert to occur. As this is a repainting indicator, bubbles will appear and sometimes disappear and alerts will sound and the bubble associated with it may disappear at times.

So this is the alert code that is added to the full code with it below
Code:
input alerts = yes;
alert(alerts and isHigh[5] and highValue[5] != highValue[5+1], "High", alert.bar, sound.chimes);
alert(alerts and isLow[5] and lowValue[5] != lowValue[5+1], "Low", alert.bar, Sound.Ding);

Ruby:
#PAS_sample by JayC @ https://futures.io/thinkorswim/56934-price-action-swing-conversion.html
input lookBack = 10;
input lookAhead = 5;

def isHigh = high >= Highest(high[1], lookBack) and high >= Highest(high[-lookAhead], lookBack);
def highValue = if BarNumber() < lookBack then Double.NaN else if isHigh then high else highValue[1];
AddChartBubble(isHigh and highValue != highValue[1], high, if highValue > highValue[1] then "HH" else "LH", Color.CYAN, yes);

#Added By DW
def LH = highValue < highValue[1];
plot LowerHigh = LH;



def isLow = low <= Lowest(low[1], lookBack) and low <= Lowest(low[-lookAhead], lookBack);
def lowValue = if BarNumber() < lookBack then Double.NaN else if isLow then low else lowValue[1];
AddChartBubble(isLow and lowValue != lowValue[1], low, if lowValue > lowValue[1] then "HL" else "LL", Color.LIGHT_RED, no);

#Added By DW
def HL = lowValue > lowValue[1];
plot HigherLow = HL;
#end code

input alerts = yes;
alert(alerts and isHigh[5] and highValue[5] != highValue[5+1], "High", alert.bar, sound.chimes);
alert(alerts and isLow[5] and lowValue[5] != lowValue[5+1], "Low", alert.bar, Sound.Ding);


#ZigZag Percent
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#

input price = close;
input reversalAmount = 8.0;
input showBubbles = no;
input showLabel = no;

assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else getValue(zzSave, 1);
def chg = (price / getValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(getValue("ZZ%", 1)) and getValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".color("Undefined") else if isUp then "ZZ%".color("Up Trend") else "ZZ%".color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = barNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"));
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
203 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