#### 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 and low < low 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 and high > high 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 and low < low 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 and high > high 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, "UP", 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);

• Hapme
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 • SleepyZ
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 and
BodyMin < BodyMin;
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length);

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

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

assignpriceColor(if Bearish then Color.VIOLET else if Bullish then Color.Yellow else Color.Current);

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 and
BodyMin < BodyMin;
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length);

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

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

assignpriceColor(if Bearish then Color.VIOLET else if Bullish then Color.Yellow else Color.Current);

Ruby:
``Alert(Bullish or Bearish, if Bullish then "BULL" else "BEAR", Alert.BAR, Sound.Ding);``

• Hapme
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

• Hapme
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

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 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);

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

• MohamedAmarragy and Hapme
See if this works for you
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

Last edited:
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. 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 else dataCount, 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 else dataCount1, 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);

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

• Hapme and MerryDay
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

@solaris yes, you can use it in a scan. Make sure showarrows =yes
scan for uparrow is true or downarrow is true

• SleepyZ
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
then high - close
else (high - close) - 0.5 * (low - high);
def LRef = if high >= low
then close - low
else (close - low) - 0.5 * (low - 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) {
case init:
if (!IsNaN(loss)) {
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) {
state = state.long;
trail = Max(trail, close - loss);
} else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail) {
state = state.short;
trail = Min(trail, 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("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")

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
then high - close
else (high - close) - 0.5 * (low - high);
def LRef = if high >= low
then close - low
else (close - low) - 0.5 * (low - 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) {
case init:
if (!IsNaN(loss)) {
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) {
state = state.long;
trail = Max(trail, close - loss);
} else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail) {
state = state.short;
trail = Min(trail, 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("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")

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;

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 then HMA.color("Up") else HMA.color("Down"));

I added this part, but not working as intended and now it is working 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 then HMA.color("Up") else HMA.color("Down"));

I added this part, but not working as intended and now it is working 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.

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.

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

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 else dataCount, 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 else dataCount1, 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);``````

I put the sequence c
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.
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

### Not the exact question you're looking for?

87k+ Posts
195 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?