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);
 
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);
This study is hard coded to be 2 bar fractal even though there is an input n is still shown.

However, if you want alerts for what you posted above, then add the following code. Please note that the alert fires after the future bar (2) condition is met. It will disappear as does the arrow does if the bar triggering the alert/arrow changes at close.

Ruby:
Alert(upfractal[2], "UP", Alert.BAR, Sound.Chimes);
Alert(downfractal[2], "DN", Alert.BAR, Sound.Chimes);

TOS's Williams fractal script is shown below with alerts. It allows the fractal to be set by the user at the input sequencecount.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2015-2021
#

#wizard plots
#wizard text: Inputs: sequence count:
#wizard input: sequenceCount

input sequenceCount = 2;

def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do
    if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1
    else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do
    if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1
    else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

def downRightSide = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do
    if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1
    else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do
    if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1
    else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

plot UpFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;
plot DownFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;

UpFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpFractal.SetDefaultColor(GetColor(3));
UpFractal.SetLineWeight(2);
DownFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownFractal.SetDefaultColor(GetColor(4));
DownFractal.SetLineWeight(2);

Alert(upfractal[sequenceCount], "DN", Alert.BAR, Sound.Chimes);
Alert(downfractal[sequenceCount], "UP", Alert.BAR, Sound.Chimes);
 

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

This study is hard coded to be 2 bar fractal even though there is an input n is still shown.

However, if you want alerts for what you posted above, then add the following code. Please note that the alert fires after the future bar (2) condition is met. It will disappear as does the arrow does if the bar triggering the alert/arrow changes at close.



TOS's Williams fractal script is shown below with alerts. It allows the fractal to be set by the user at the input sequencecount

Thank you Sleepy thank you so much exacly what i needed :)
 
Would it be possible to add Alerts on Engulfing candle script , thank you .



Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2018
# Modified by BenTen @ usethinkscript.com
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

assignpriceColor(if Bearish then Color.VIOLET else if Bullish then Color.Yellow else Color.Current);
AddLabel(yes,"Bu_Engulf",color.Yellow);
AddLabel(yes,"Be_Engulf",color.VIOLET);
 
Would it be possible to add Alerts on Engulfing candle script , thank you .



Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2018
# Modified by BenTen @ usethinkscript.com
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

assignpriceColor(if Bearish then Color.VIOLET else if Bullish then Color.Yellow else Color.Current);
AddLabel(yes,"Bu_Engulf",color.Yellow);
AddLabel(yes,"Be_Engulf",color.VIOLET);

Ruby:
Alert(Bullish or Bearish, if Bullish then "BULL" else "BEAR", Alert.BAR, Sound.Ding);
 
I didn’t change the size of the arrows, but gave you another script than what you were using as an option. You could have used your script and added the 2 line alert code. Nonetheless, you can resize the arrows on any script at the script settings, lineweight
 
Would it be possible to add the higher close price of the last 2 red fractals like in the picture , the price to be small above on the last 2 red fractal close higher price , i add a picture if you can have a look there


See if this works for you

Screenshot-2021-08-25-073005.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2015-2021
#

#wizard plots
#wizard text: Inputs: sequence count:
#wizard input: sequenceCount

input sequenceCount = 2;

def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do
    if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1
    else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do
    if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1
    else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

def downRightSide = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do
    if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1
    else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do
    if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1
    else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

plot UpFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;
plot DownFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;

UpFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpFractal.SetDefaultColor(GetColor(3));
UpFractal.SetLineWeight(2);
DownFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownFractal.SetDefaultColor(GetColor(4));
DownFractal.SetLineWeight(2);

Alert(upfractal[sequenceCount], "DN", Alert.BAR, Sound.Chimes);
Alert(downfractal[sequenceCount], "UP", Alert.BAR, Sound.Chimes);

input showbubbles = yes;
input Count       = 2;
def cond          = upfractal;
def dataCount     = CompoundValue(1, if !IsNaN(cond) then dataCount[1] + 1 else dataCount[1], 0);
def data         = if HighestAll(dataCount) - dataCount <= Count - 1 then upfractal else Double.NaN;
addchartBubble(showbubbles and data,data, data);
 
Works perfectly is just sometimes gives multiple numbers like in the picture , can you do something about it ,and can i get only the code for the last 2 fractals price showing , to add in the small williams fractals with small arroaws


Here is the arrows and bubbles limited to the input count you decide.
The bubbles have an input movebubbleupsupdown to displace them so the arrows will show.

Screenshot-2021-08-25-091506.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2015-2021
#

#wizard plots
#wizard text: Inputs: sequence count:
#wizard input: sequenceCount

input sequenceCount = 2;

def maxSideLength   = sequenceCount + 10;
def upRightSide     = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do
    if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1
    else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;
def upLeftSide      = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do
    if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1
    else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

def downRightSide    = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do
    if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1
    else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;
def downLeftSide     = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do
    if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1
    else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

#---------------------------------------
#Conditions

def UpFractal_   = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;
def DownFractal_ = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;

#------------------------------
#Plot limiting Code for chart bubbles and arrows

input Count       = 2;
def cond          = UpFractal_;
def dataCount     = CompoundValue(1, if !IsNaN(cond) then dataCount[1] + 1 else dataCount[1], 0);
def data         = if HighestAll(dataCount) - dataCount <= Count - 1 then UpFractal_ else Double.NaN;

def cond1         = DownFractal_;
def dataCount1    = CompoundValue(1, if !IsNaN(cond1) then dataCount1[1] + 1 else dataCount1[1], 0);
def data1         = if HighestAll(dataCount1) - dataCount1 <= Count - 1 then DownFractal_ else Double.NaN;

#--------------------------------
#Bubbles
input showbubbles = yes;
input movebubblesupdown = 8;

AddChartBubble(showbubbles and data, data + movebubblesupdown * TickSize(), astext(data));
AddChartBubble(showbubbles and data1, data1 - movebubblesupdown * TickSize(), astext(data1), Color.LIGHT_GREEN, No);

#-------------------------------------
#Arrows
input showarrows = yes;
plot upfractal   = if showarrows then data else double.nan;
upfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
upfractal.SetDefaultColor(GetColor(3));
upfractal.SetLineWeight(2);
plot downfractal = if showarrows then data1 else double.nan;
downfractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
downfractal.SetDefaultColor(GetColor(4));
downfractal.SetLineWeight(2);

#-----------------------------
#Alerts

Alert(upfractal[sequenceCount], "DN", Alert.BAR, Sound.Chimes);
Alert(downfractal[sequenceCount], "UP", Alert.BAR, Sound.Chimes);
 
Here is the arrows and bubbles limited to the input count you decide.
The bubbles have an input movebubbleupsupdown to displace them so the arrows will show.
I'm really enjoying this fractal script, was wondering if a scan could be created to catch the fractal when it appears on the chart. I'm monitoring several stocks on a 1 min chart and it would be nice to scan for the fractal, instead of tabing through several charts. Any help would be appreciated.
Thanks
 
Hey guys. Had a question in regards to this thread here. I'm trying to add alerts for when TOS's ATR Trailing Stop indicator has price above and below the indicators. Can anyone help in adding those alerts?

input trailType = {default modified, unmodified};
input ATRPeriod = 9;
input ATRFactor = 2.9;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange;
switch (trailType) {
case modified:
trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
} else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
} else {
state = state.long;
trail = close - loss;
}
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

plot TrailingStop = trail;

TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));


this is the script. I just want the alerts to come up when price is above/below the ATR Trailing Stop.
 
Hey guys. Had a question in regards to this thread here. I'm trying to add alerts for when TOS's ATR Trailing Stop indicator has price above and below the indicators. Can anyone help in adding those alerts?

input trailType = {default modified, unmodified};
input ATRPeriod = 9;
input ATRFactor = 2.9;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange;
switch (trailType) {
case modified:
trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
} else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
} else {
state = state.long;
trail = close - loss;
}
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

plot TrailingStop = trail;

TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));


this is the script. I just want the alerts to come up when price is above/below the ATR Trailing Stop.

Add the following to the bottom of the code. Change the input price to whatever you want.

Ruby:
input price = close;
Alert(price crosses above trail, "ABOVE", Alert.ONCE, Sound.Ding);
Alert(price crosses below trail, "BELOW", Alert.ONCE, Sound.Chimes);
 
Hey team... hope you are surviving the recent market volatility OK :)

I wanted to find out if there is a quick way to add UP and DOWN signal alerts for the Hull Moving Average indicator. I tried adding alert commands to the bottom of the ToS source code, but it is triggering both alerts at the same time, regardless of the indicator moving up or down. So it is hard to differentiate.

I got it to work!


ToS source code for Hull MA

#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));


I added this part, but not working as intended and now it is working :)
Alert(HMA > HMA[1], "Up", Alert.Bar, Sound.Chimes);
Alert(HMA < HMA[1], "Down", Alert.Bar, Sound.Ding);
 
Last edited:
Hey team... hope you are surviving the recent market volatility OK :)

I wanted to find out if there is a quick way to add UP and DOWN signal alerts for the Hull Moving Average indicator. I tried adding alert commands to the bottom of the ToS source code, but it is triggering both alerts at the same time, regardless of the indicator moving up or down. So it is hard to differentiate.

I got it to work!


ToS source code for Hull MA

#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));


I added this part, but not working as intended and now it is working :)
Alert(HMA > HMA[1], "Up", Alert.Bar, Sound.Chimes);
Alert(HMA < HMA[1], "Down", Alert.Bar, Sound.Ding);
I think this is always a good idea to add alerts. However, I'm wondering if this is truly accurate because I've used alert notifications on my ToS platform and noticed that they go off at random times. It's a bit frustrating. I'm trying to eliminate the additional noise and hopefully get rid of these unwanted false positives.
 
God Bless you Sleepyz , would it be possible to remove the fractals and to let only the price of the last candle close with green like in the picture


This will plot your choice of how many bubbles and whether for upfractals and/or downfractals. It is preset now to show 1 green bubble.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2015-2021
#

#wizard plots
#wizard text: Inputs: sequence count:
#wizard input: sequenceCount

input sequenceCount = 2;

def maxSideLength   = sequenceCount + 10;
def upRightSide     = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do
    if GetValue(high, -i1, -maxSideLength) > high or (GetValue(high, -i1, -maxSideLength) == high and count1 == 0) then -1
    else if GetValue(high, -i1, -maxSideLength) < high then count1 + 1 else count1;
def upLeftSide      = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do
    if GetValue(high, i2, maxSideLength) > high or (GetValue(high, i2, maxSideLength) == high and count2 >= 1) then -1
    else if GetValue(high, i2, maxSideLength) < high then count2 + 1 else count2;

def downRightSide    = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do
    if GetValue(low, -i3, -maxSideLength) < low or (GetValue(low, -i3, -maxSideLength) == low and count3 == 0) then -1
    else if GetValue(high, -i3, -maxSideLength) > low then count3 + 1 else count3;
def downLeftSide     = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do
    if GetValue(low, i4, maxSideLength) < low or (GetValue(low, i4, maxSideLength) == low and count4 >= 1) then -1
    else if GetValue(low, i4, maxSideLength) > low then count4 + 1 else count4;

#---------------------------------------
#Conditions

def UpFractal_   = if upRightSide == sequenceCount and upLeftSide == sequenceCount then high else Double.NaN;
def DownFractal_ = if downRightSide == sequenceCount and downLeftSide == sequenceCount then low else Double.NaN;

#------------------------------
#Plot limiting Code for chart bubbles and arrows

input Count       = 1;
input showbubble_upfractal   = no;
input showbubble_downfractal = yes;

def cond          = UpFractal_;
def dataCount     = CompoundValue(1, if !IsNaN(cond) then dataCount[1] + 1 else dataCount[1], 0);
def data         = if HighestAll(dataCount) - dataCount <= Count - 1 then UpFractal_ else Double.NaN;

def cond1         = DownFractal_;
def dataCount1    = CompoundValue(1, if !IsNaN(cond1) then dataCount1[1] + 1 else dataCount1[1], 0);
def data1         = if HighestAll(dataCount1) - dataCount1 <= Count - 1 then DownFractal_ else Double.NaN;

#--------------------------------
#Bubbles
input showbubbles = yes;
input movebubblesupdown = 8;

AddChartBubble(showbubbles and showbubble_upfractal and data, data + movebubblesupdown * TickSize(), astext(data));
AddChartBubble(showbubbles and showbubble_downfractal and data1, data1 - movebubblesupdown * TickSize(), astext(data1), Color.LIGHT_GREEN, No);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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