H/L 2$ Candles indicator

kharbi

New member
Hello everyone... Can anyone, if possible, create an indicator that creates a signal or a line on the high and low on the chart, if the following conditions are met:

- If the length of one, two, or three candles is >= $2.. (Note: the number of candles should not exceed 3).

Since I am currently doing a study based on that, after fulfilling the condition, I set Fibonacci and wait for prices to bounce back at 38%, 50%, or 61%, and then I enter according to the trend and my target is 100%. The results were fantastic (5 min spy).

Thank you all

Shared Chart Link: http://tos.mx/XmoyEyN
https%3A//i.imgur.com/8qf6Kd4.png[/img]']
8qf6Kd4.png



7oG8ME5.png
 
Last edited by a moderator:
Solution
After the first experience, the indicator works very well. But I found some problems and it is possible that it is my fault because I did not explain accurately ..

-I found overlap between trading sessions. Can each session be separated from the other? ? (as in picture No. 1)
-Is it possible to show the Fibonacci ratios in the case of ups and downs?
-One of the most important conditions of the study is that the two or three candles are of the same type, i.e. 3 green candles, i.e. its closing is higher than its opening, and vice versa with bearish candles. Which should be sequential .. (as in picture No. 2)

BYXze0z.png




YI85LKT.png

I think this does what you want.

Has separate Bull and Bear groupings
Offers option to limit...
Hello everyone... Can anyone, if possible, create an indicator that creates a signal or a line on the high and low on the chart, if the following conditions are met:

- If the length of one, two, or three candles is >= $2.. (Note: the number of candles should not exceed 3).

Since I am currently doing a study based on that, after fulfilling the condition, I set Fibonacci and wait for prices to bounce back at 38%, 50%, or 61%, and then I enter according to the trend and my target is 100%. The results were fantastic (5 min spy).

Thank you all

Shared Chart Link: http://tos.mx/XmoyEyN
16504[/ATTACH]']
8qf6Kd4.png



7oG8ME5.png

This plot the high/low, price_bubbles and fibs. You can control at input count how many of these groups plot.

The image is of from your chart with the code below plotting the last 2 groupings (input count = 2)

[Edit: changed $2 criteria from a hard code to an input diff
Also noticed that you have items checked on the left side under chart settings, price axis. It is best to uncheck these.
Screenshot-2022-11-24-153750.png

Ruby:
input count = 2;
input diff  = 2;
def r = (Highest(high, 3) - Lowest(low, 3));
def h = if r >= diff then Highest(high, 3) else h[1];
def l = if r >= diff then Lowest(low, 3) else l[1];
def hbar = if r >= diff then 1 else 0;
def lbar = if r >= diff then 1 else 0;

def dataCounth = CompoundValue(1, if hbar[1] == 0 and hbar then dataCounth[1] + 1 else dataCounth[1], 0);
plot hh = if HighestAll(dataCounth) - dataCounth <= count - 1 then h else Double.NaN;
hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh.SetDefaultColor(Color.CYAN);

def dataCountl = CompoundValue(1, if lbar[1] == 0 and lbar then dataCountl[1] + 1 else dataCountl[1], 0);
plot ll = if HighestAll(dataCountl) - dataCountl <= count - 1 then l else Double.NaN;
ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll.SetDefaultColor(Color.CYAN);

input show_bubbles = yes;
input bubblemover_updown = 3;

AddChartBubble(show_bubbles and hbar[1] == 0 and hbar, hh + TickSize() * bubblemover_updown, hh, Color.WHITE);
AddChartBubble(show_bubbles and lbar[1] == 0 and lbar, ll - TickSize() * bubblemover_updown, ll, Color.WHITE, no);

plot fib1 = ll + (hh - ll) * .618;
plot fib2 = ll + (hh - ll) * .500;
plot fib3 = ll + (hh - ll) * .382;
fib1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1.SetDefaultColor(Color.WHITE);
fib2.SetDefaultColor(Color.YELLOW);
fib3.SetDefaultColor(Color.RED);
 

Attachments

  • 8qf6Kd4.png
    8qf6Kd4.png
    77.8 KB · Views: 62
Last edited:
This plot the high/low, price_bubbles and fibs. You can control at input count how many of these groups plot.

The image is of from your chart with the code below plotting the last 2 groupings (input count = 2)

[Edit: changed $2 criteria from a hard code to an input diff
Also noticed that you have items checked on the left side under chart settings, price axis. It is best to uncheck these.
You are amazing.. I will give it a try... Thank you very much 😁(y)
 
This plot the high/low, price_bubbles and fibs. You can control at input count how many of these groups plot.

The image is of from your chart with the code below plotting the last 2 groupings (input count = 2)

[Edit: changed $2 criteria from a hard code to an input diff
Also noticed that you have items checked on the left side under chart settings, price axis. It is best to uncheck these.
After the first experience, the indicator works very well. But I found some problems and it is possible that it is my fault because I did not explain accurately ..

-I found overlap between trading sessions. Can each session be separated from the other? ? (as in picture No. 1)
-Is it possible to show the Fibonacci ratios in the case of ups and downs?
-One of the most important conditions of the study is that the two or three candles are of the same type, i.e. 3 green candles, i.e. its closing is higher than its opening, and vice versa with bearish candles. Which should be sequential .. (as in picture No. 2)

BYXze0z.png




YI85LKT.png
 
After the first experience, the indicator works very well. But I found some problems and it is possible that it is my fault because I did not explain accurately ..

-I found overlap between trading sessions. Can each session be separated from the other? ? (as in picture No. 1)
-Is it possible to show the Fibonacci ratios in the case of ups and downs?
-One of the most important conditions of the study is that the two or three candles are of the same type, i.e. 3 green candles, i.e. its closing is higher than its opening, and vice versa with bearish candles. Which should be sequential .. (as in picture No. 2)

BYXze0z.png




YI85LKT.png

I think this does what you want.

Has separate Bull and Bear groupings
Offers option to limit the plot of the number of bull/bear groups (Highest highs/Lowest lows) by count.
Limits the plot of a group when a cross outside the group.
Keeps grouping components within same day

Screenshot-2022-11-26-070206.png
Ruby:
#H/L_2$_Candles_indicator
input use_count_plot_limit = yes;
input count        = 2;

input diff         = 2.0;
input lookback     = 3;
input show_bubbles = yes;
input bubblemover_updown = 3;

def day = if GetDay() != GetDay()[1] then 1 else day[1] + 1;
def up  = if GetDay() != GetDay()[1]
          then if close > open then 1
          else 0
          else if GetDay() == GetDay()[1]
          then if close > open
          then 1
          else 0
          else up[1];
def r  = (Highest(high, lookback) - Lowest(low, lookback));

#  Bull Groups ##################################

def bull     = if day >= lookback and (up[2] == 1 and up[1] == 1 and up == 1)
               then 1 else 0;
def hbull_   = if r >= diff and bull
               then Highest(high, lookback) else hbull_[1];
def lbull_   = if r >= diff and bull
               then Lowest(low, lookback) else lbull_[1];
def hbull    = if r >= diff and bull
               then Highest(high, lookback)
               else if high < hbull_[1] and low > lbull_[1]
               then hbull[1] else Double.NaN;
def lbull    = if r >= diff and bull
               then Lowest(low, lookback)
               else if high < hbull_[1] and low > lbull_[1]
               then lbull[1] else Double.NaN;
def hbullbar = if r >= diff and bull
               then 1 else 0;
def lbullbar = if r >= diff and bull
               then 1 else 0;

def dataCounthbull = CompoundValue(1, if hbullbar[1] == 0 and hbullbar then dataCounthbull[1] + 1 else dataCounthbull[1], 0);
def dataCountlbull = CompoundValue(1, if lbullbar[1] == 0 and lbullbar then dataCountlbull[1] + 1 else dataCountlbull[1], 0);

plot hhbull = if use_count_plot_limit and HighestAll(dataCounthbull) - dataCounthbull <= count - 1 or !use_count_plot_limit then hbull else Double.NaN;
hhbull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhbull.SetDefaultColor(Color.CYAN);

plot llbull = if use_count_plot_limit and HighestAll(dataCountlbull) - dataCountlbull <= count - 1 or !use_count_plot_limit then lbull else Double.NaN;
llbull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llbull.SetDefaultColor(Color.CYAN);


AddChartBubble(show_bubbles and hbullbar[1] == 0 and hbullbar, hhbull + TickSize() * bubblemover_updown, hhbull, Color.GREEN);
AddChartBubble(show_bubbles and lbullbar[1] == 0 and lbullbar, llbull - TickSize() * bubblemover_updown, llbull, Color.GREEN, no);

plot fib1bull = llbull + (hhbull - llbull) * .618;
plot fib2bull = llbull + (hhbull - llbull) * .500;
plot fib3bull = llbull + (hhbull - llbull) * .382;
fib1bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1bull.SetDefaultColor(Color.WHITE);
fib2bull.SetDefaultColor(Color.YELLOW);
fib3bull.SetDefaultColor(Color.RED);

# Bear Groups  ##################################

def bear     = if day >= lookback and (up[2] == 0 and up[1] == 0 and up == 0)
               then 1 else 0;
def hbear_   = if r >= diff and bear
               then Highest(high, lookback) else hbear_[1];
def lbear_   = if r >= diff and bear
               then Lowest(low, lookback) else lbear_[1];
def hbear    = if r >= diff and bear
               then Highest(high, lookback)
               else if high < hbear_[1] and low > lbear_[1]
               then hbear[1] else Double.NaN;
def lbear    = if r >= diff and bear then Lowest(low, lookback)
               else if high < hbear_[1] and low > lbear_[1]
               then lbear[1] else Double.NaN;
def hbearbar = if r >= diff and bear
               then 1 else 0;
def lbearbar = if r >= diff and bear
               then 1 else 0;

def dataCounthbear = CompoundValue(1, if hbearbar[1] == 0 and hbearbar then dataCounthbear[1] + 1 else dataCounthbear[1], 0);
def dataCountlbear = CompoundValue(1, if lbearbar[1] == 0 and lbearbar then dataCountlbear[1] + 1 else dataCountlbear[1], 0);

plot hhbear = if use_count_plot_limit and HighestAll(dataCounthbear) - dataCounthbear <= count - 1 or !use_count_plot_limit then hbear else Double.NaN;
hhbear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhbear.SetDefaultColor(Color.CYAN);

plot llbear = if use_count_plot_limit and HighestAll(dataCountlbear) - dataCountlbear <= count - 1 or !use_count_plot_limit then lbear else Double.NaN;
llbear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llbear.SetDefaultColor(Color.CYAN);

AddChartBubble(show_bubbles and hbearbar[1] == 0 and hbearbar, hhbear + TickSize() * bubblemover_updown, hhbear, Color.RED);
AddChartBubble(show_bubbles and lbearbar[1] == 0 and lbearbar, llbear - TickSize() * bubblemover_updown, llbear, Color.RED, no);

plot fib1bear = llbear + (hhbear - llbear) * .382;
plot fib2bear = llbear + (hhbear - llbear) * .500;
plot fib3bear = llbear + (hhbear - llbear) * .618;
fib1bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1bear.SetDefaultColor(Color.WHITE);
fib2bear.SetDefaultColor(Color.YELLOW);
fib3bear.SetDefaultColor(Color.RED);
 
Solution
At the outset, I would like to thank you for taking the time to help me. The improvements you've made to the indicator have been pretty excellent, and I thank you for that. After using the indicator (after updating), here are some notes if you want to modify it or if your time allows..


(In picture number 1).. The indicator did not calculate the single candle automatically.. (I know that I can add the indicator more than once in the same chart with the required modification. But as soon as I change (lookback) to 1 specifically, it does not give any results unless in the case The bearish candle is also not in all cases, for example: if a red candle of length => 2$ appeared and gave a signal, an opposite (green) candle was formed, and after a while a new (red) candle was formed, whose length => 2$ 2 dollars, the indicator does not draw lines on it as (in picture no. 2)

xojJuuT.png



lAha3Ty.png




Last Note : In this example, the indicator has drawn all cases (3 red candles in the same direction), so is it possible to ignore the other signal until a new green candle is formed after it.... If a new case is formed during the same session even if the same trend is negative, the indicator will draw again. (as in picture number 3)


fLJtVRD.png


I know that you are not obligated to respond or make the indicator, whether you or one of the members and I appreciate that ..

But I promise you that the results will amaze you all so that interest prevails on this forum .. I have very good knowledge in statistics, so the study needs accurate data from me, and I promise to share it with everyone. Even if you draw by hand, but the data is scarce until the success rate of this strategy is extracted... In principle, the success rate of this strategy is 84%+
 
At the outset, I would like to thank you for taking the time to help me. The improvements you've made to the indicator have been pretty excellent, and I thank you for that. After using the indicator (after updating), here are some notes if you want to modify it or if your time allows..


(In picture number 1).. The indicator did not calculate the single candle automatically.. (I know that I can add the indicator more than once in the same chart with the required modification. But as soon as I change (lookback) to 1 specifically, it does not give any results unless in the case The bearish candle is also not in all cases, for example: if a red candle of length => 2$ appeared and gave a signal, an opposite (green) candle was formed, and after a while a new (red) candle was formed, whose length => 2$ 2 dollars, the indicator does not draw lines on it as (in picture no. 2)

xojJuuT.png



lAha3Ty.png




Last Note : In this example, the indicator has drawn all cases (3 red candles in the same direction), so is it possible to ignore the other signal until a new green candle is formed after it.... If a new case is formed during the same session even if the same trend is negative, the indicator will draw again. (as in picture number 3)


fLJtVRD.png


I know that you are not obligated to respond or make the indicator, whether you or one of the members and I appreciate that ..

But I promise you that the results will amaze you all so that interest prevails on this forum .. I have very good knowledge in statistics, so the study needs accurate data from me, and I promise to share it with everyone. Even if you draw by hand, but the data is scarce until the success rate of this strategy is extracted... In principle, the success rate of this strategy is 84%+

I have made an adjustment to include only the first bar of a bull or bear candle that exceeds $2 by itself.

All of your examples 1-3 show the high-low until broken. So in example 1 now appears, on 11/23 it was broken at 1425 and example 2 now appears on 11/4 and broken at 1135. As far as example 3, it appeared originally on 11/15 and was broken at 1320. No extension of lines here as this was the next candle to start extension and it crossed below the low.

Screenshot-2022-11-27-160129.png
Ruby:
#H/L_2$_Candles_indicator
input use_count_plot_limit = yes;
input count        = 2;

input diff         = 2.0;
input lookback     = 3;
input show_bubbles = yes;
input bubblemover_updown = 3;

def day = if GetDay() != GetDay()[1] then 1 else day[1] + 1;
def up  = if GetDay() != GetDay()[1]
          then if close > open then 1
          else 0
          else if GetDay() == GetDay()[1]
          then if close > open
          then 1
          else 0
          else up[1];
def r  = (Highest(high, lookback) - Lowest(low, lookback));

#  Bull Groups ##################################

def bull     = if day >= lookback and (up[2] == 1 and up[1] == 1 and up == 1) or day >= 1 and up == 1 and (high - low) > diff
               then 1 else 0;
def hbull_   = if r >= diff and bull
               then Highest(high, lookback) else hbull_[1];
def lbull_   = if r >= diff and bull
               then Lowest(low, lookback) else lbull_[1];
def hbull    = if r >= diff and bull
               then Highest(high, lookback)
               else if high < hbull_[1] and low > lbull_[1]
               then hbull[1] else Double.NaN;
def lbull    = if r >= diff and bull
               then Lowest(low, lookback)
               else if high < hbull_[1] and low > lbull_[1]
               then lbull[1] else Double.NaN;
def hbullbar = if r >= diff and bull
               then 1 else 0;
def lbullbar = if r >= diff and bull
               then 1 else 0;

def dataCounthbull = CompoundValue(1, if hbullbar[1] == 0 and hbullbar then dataCounthbull[1] + 1 else dataCounthbull[1], 0);
def dataCountlbull = CompoundValue(1, if lbullbar[1] == 0 and lbullbar then dataCountlbull[1] + 1 else dataCountlbull[1], 0);

plot hhbull = if use_count_plot_limit and HighestAll(dataCounthbull) - dataCounthbull <= count - 1 or !use_count_plot_limit then hbull else Double.NaN;
hhbull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhbull.SetDefaultColor(Color.CYAN);

plot llbull = if use_count_plot_limit and HighestAll(dataCountlbull) - dataCountlbull <= count - 1 or !use_count_plot_limit then lbull else Double.NaN;
llbull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llbull.SetDefaultColor(Color.CYAN);


AddChartBubble(show_bubbles and hbullbar[1] == 0 and hbullbar, hhbull + TickSize() * bubblemover_updown, hhbull, Color.GREEN);
AddChartBubble(show_bubbles and lbullbar[1] == 0 and lbullbar, llbull - TickSize() * bubblemover_updown, llbull, Color.GREEN, no);

plot fib1bull = llbull + (hhbull - llbull) * .618;
plot fib2bull = llbull + (hhbull - llbull) * .500;
plot fib3bull = llbull + (hhbull - llbull) * .382;
fib1bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1bull.SetDefaultColor(Color.WHITE);
fib2bull.SetDefaultColor(Color.YELLOW);
fib3bull.SetDefaultColor(Color.RED);

# Bear Groups  ##################################

def bear     = if day >= lookback and (up[2] == 0 and up[1] == 0 and up == 0) or day >= 1 and up == 0 and (high - low) > diff
               then 1 else 0;
def hbear_   = if r >= diff and bear
               then Highest(high, lookback) else hbear_[1];
def lbear_   = if r >= diff and bear
               then Lowest(low, lookback) else lbear_[1];
def hbear    = if r >= diff and bear
               then Highest(high, lookback)
               else if high < hbear_[1] and low > lbear_[1]
               then hbear[1] else Double.NaN;
def lbear    = if r >= diff and bear then Lowest(low, lookback)
               else if high < hbear_[1] and low > lbear_[1]
               then lbear[1] else Double.NaN;
def hbearbar = if r >= diff and bear
               then 1 else 0;
def lbearbar = if r >= diff and bear
               then 1 else 0;

def dataCounthbear = CompoundValue(1, if hbearbar[1] == 0 and hbearbar then dataCounthbear[1] + 1 else dataCounthbear[1], 0);
def dataCountlbear = CompoundValue(1, if lbearbar[1] == 0 and lbearbar then dataCountlbear[1] + 1 else dataCountlbear[1], 0);

plot hhbear = if use_count_plot_limit and HighestAll(dataCounthbear) - dataCounthbear <= count - 1 or !use_count_plot_limit then hbear else Double.NaN;
hhbear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhbear.SetDefaultColor(Color.CYAN);

plot llbear = if use_count_plot_limit and HighestAll(dataCountlbear) - dataCountlbear <= count - 1 or !use_count_plot_limit then lbear else Double.NaN;
llbear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llbear.SetDefaultColor(Color.CYAN);

AddChartBubble(show_bubbles and hbearbar[1] == 0 and hbearbar, hhbear + TickSize() * bubblemover_updown, hhbear, Color.RED);
AddChartBubble(show_bubbles and lbearbar[1] == 0 and lbearbar, llbear - TickSize() * bubblemover_updown, llbear, Color.RED, no);

plot fib1bear = llbear + (hhbear - llbear) * .382;
plot fib2bear = llbear + (hhbear - llbear) * .500;
plot fib3bear = llbear + (hhbear - llbear) * .618;
fib1bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1bear.SetDefaultColor(Color.WHITE);
fib2bear.SetDefaultColor(Color.YELLOW);
fib3bear.SetDefaultColor(Color.RED);
 
I would like to thank you very much for giving me the indicator that it does a great job .. The only observation that I would like to put forward (if it is possible to amend it please)

( in picture 1 )
A = (1, 2, [3]) = 3 candles
B = ([3], 4) = 2 candles

The common candle between (A and B) = [ 3 ]

What I want is not to continue drawing the new lines until it reaches a green candle, not to break the bottom. That is, the indicator shows one condition, which is the first case, and after that it stops drawing if connected red candles appear, except for one condition, which is the appearance of a green candle, and then if the condition is met, it draws. Because the green reputation in our example is a fresh start for me. ( in picture 2 )... and I will tell you why, because each new drawing represents a different entry case for me... the results that appear from repeating the single candlestick pattern are different from the risks that result from 3 candles.. and I thank you for your kind response to me..


M06Ucxe.png



Nca9sDk.png
 
I would like to thank you very much for giving me the indicator that it does a great job .. The only observation that I would like to put forward (if it is possible to amend it please)

( in picture 1 )
A = (1, 2, [3]) = 3 candles
B = ([3], 4) = 2 candles

The common candle between (A and B) = [ 3 ]

What I want is not to continue drawing the new lines until it reaches a green candle, not to break the bottom. That is, the indicator shows one condition, which is the first case, and after that it stops drawing if connected red candles appear, except for one condition, which is the appearance of a green candle, and then if the condition is met, it draws. Because the green reputation in our example is a fresh start for me. ( in picture 2 )... and I will tell you why, because each new drawing represents a different entry case for me... the results that appear from repeating the single candlestick pattern are different from the risks that result from 3 candles.. and I thank you for your kind response to me..


M06Ucxe.png



Nca9sDk.png

In example 1 B is 3 candles with your numbers 2, 3 4 making it similar to example 2. If I have time, I will take a look at it.
 
In example 1 B is 3 candles with your numbers 2, 3 4 making it similar to example 2. If I have time, I will take a look at it.

I revised the bull/bear definitions with some annotations to:

Identify a 1 bar, 2 bars and 3 bar sequences (red/green), with the Highest/Lowest defined within the 3 conditions.
If the bar after the bull or bear is not within the Highest/Lowest area, nothing will plot.
No overlap of bars between days when forming a bull/bear
Can Limit plots of bull/bear at input.

Ruby:
#H/L_2$_Candles_indicator_v1
input use_count_plot_limit = yes;
input count        = 2;

input diff         = 2.0;

input show_bubbles = yes;
input bubblemover_updown = 3;

def day = if GetDay() != GetDay()[1] then 1 else day[1] + 1;
def up  = if GetDay() != GetDay()[1]
          then if close > open then 1
          else 0
          else if GetDay() == GetDay()[1]
          then if close > open
          then 1
          else 0
          else up[1];
def bull;
def bear;
#  Bull Groups ##################################

bull     = if day[1] != 78 and  day >= 1 and #No bars from prior day allowed
              #1 bar only: red, green, red
              up[1] == 0 and up == 1 and up[-1] == 0 and
              (high - low) > diff and
              #Next bar must be within highest/lowest
              high[-1] < highest(high, 1) and low[-1] > lowest(low, 1)
           then 1
           else if day[1] != 78 and  day >= 1 and #No bars from prior day allowed
                   #2 bars only: red, green, green, red
                   up[2] == 0 and up[1] == 1 and up == 1 and up[-1] == 0 and
                   (Highest(high, 2) - Lowest(low, 2)) > diff and
                   #Next bar must be within highest/lowest  
                   high[-1] < Highest(high, 2) and low[-1] > Lowest(low, 2)
           then 1
           else if day[3] != 78 and day >= 3 and
                   #3 bars: green, green, green
                   up[2] == 1 and up[1] == 1 and up == 1 and
                   (Highest(high, 3) - Lowest(low, 3)) > diff and
                   #Next bar must be within highest/lowest
                   high[-1] < Highest(high, 3) and low[-1] > Lowest(low, 3)
           then 1
           else 0;

def bull_hl   = if day[1] != 78 and  day >= 1 and #No bars from prior day allowed
                   #1 bar only: red, green, red
                   up[1] == 0 and up == 1 and up[-1] == 0 and
                   (high - low) > diff and
                   #Next bar must be within highest/lowest
                    high[-1] < highest(high, 1) and low[-1] > lowest(low, 1)
                then 1
                else if day[1] != 78 and  day >= 1 and
                        #2 bars only: red, green, green, red
                        up[2] == 0 and up[1] == 1 and up == 1 and up[-1] == 0 and
                        (Highest(high, 2) - Lowest(low, 2)) > diff and
                        #Next bar must be within highest/lowest
                        high[-1] < Highest(high, 2) and low[-1] > Lowest(low, 2)
                then 2
                else if day[3] != 78 and day >= 3 and
                        #3 bars: green, green, green
                        up[2] == 1 and up[1] == 1 and up == 1 and
                        (Highest(high, 3) - Lowest(low, 3)) > diff and
                        #Next bar must be within highest/lowest
                        high[-1] < Highest(high, 3) and low[-1] > Lowest(low, 3)
                then 3
                else 0;

def hbull_   = if bull
               then if bull_hl == 1 then Highest(high, 1) else
                    if bull_hl == 2 then Highest(high, 2)
                    else Highest(high, 3)  
               else hbull_[1];
def lbull_   = if bull
               then if bull_hl == 1 then Lowest(low, 1) else
                    if bull_hl == 2 then Lowest(low, 2)
                    else Lowest(low, 3)
               else lbull_[1];
def hbull    = if bull
               then if bull_hl == 1 then Highest(high, 1) else
                    if bull_hl == 2 then Highest(high, 2)
                    else Highest(high, 3)
               else if high < hbull_[1] and low > lbull_[1]
               then hbull[1] else Double.NaN;
def lbull    = if bull
               then if bull_hl == 1 then Lowest(low, 1) else
                    if bull_hl == 2 then Lowest(low, 2)
                    else Lowest(low, 3)
               else if high < hbull_[1] and low > lbull_[1]
               then lbull[1] else Double.NaN;

def hbullbar = if bull
               then 1 else 0;
def lbullbar = if bull
               then 1 else 0;

def dataCounthbull = CompoundValue(1, if hbullbar[1] == 0 and hbullbar then dataCounthbull[1] + 1 else dataCounthbull[1], 0);
def dataCountlbull = CompoundValue(1, if lbullbar[1] == 0 and lbullbar then dataCountlbull[1] + 1 else dataCountlbull[1], 0);

plot hhbull = if use_count_plot_limit and HighestAll(dataCounthbull) - dataCounthbull <= count - 1 or !use_count_plot_limit then hbull else Double.NaN;
hhbull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhbull.SetDefaultColor(Color.CYAN);

plot llbull = if use_count_plot_limit and HighestAll(dataCountlbull) - dataCountlbull <= count - 1 or !use_count_plot_limit then lbull else Double.NaN;
llbull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llbull.SetDefaultColor(Color.CYAN);


AddChartBubble(show_bubbles and hbullbar[1] == 0 and hbullbar, hhbull + TickSize() * bubblemover_updown, hhbull, Color.GREEN);
AddChartBubble(show_bubbles and lbullbar[1] == 0 and lbullbar, llbull - TickSize() * bubblemover_updown, llbull, Color.GREEN, no);

plot fib1bull = llbull + (hhbull - llbull) * .618;
plot fib2bull = llbull + (hhbull - llbull) * .500;
plot fib3bull = llbull + (hhbull - llbull) * .382;
fib1bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1bull.SetDefaultColor(Color.WHITE);
fib2bull.SetDefaultColor(Color.YELLOW);
fib3bull.SetDefaultColor(Color.RED);

# Bear Groups  ##################################

bear         = if day[1] != 78 and  day >= 1 and #No bars from prior day allowed
                  #1 bar only: green, red, green
                  up[1] == 1 and up == 0 and up[-1] == 1 and
                  (high - low) > diff and
                  #Next bar must be within highest/lowest
                  high[-1] < highest(high, 1) and low[-1] > lowest(low, 1)  
               then 1
               else if day[1] != 78 and day >= 1 and
                       #2 bars: green, red, red, green
                       up[2] == 1 and up[1] == 0 and up == 0 and up[-1] == 1 and
                       (Highest(high, 2) - Lowest(low, 2)) > diff and
                       high[-1] < Highest(high, 2) and low[-1] > Lowest(low, 2)
               then 1
               else if day[3] != 78 and day >= 3 and
                       #3 bars: red, red, red
                       up[2] == 0 and up[1] == 0 and up == 0 and
                       (Highest(high, 3) - Lowest(low, 3)) > diff and
                       high[-1] < Highest(high, 3) and low[-1] > Lowest(low, 3)
               then 1
               else 0;
def bear_hl =  if day[1] != 78 and  day >= 1 and #No bars from prior day allowed
                  #1 bar only: green, red, green
                  up[1] == 1 and up == 0 and up[-1] == 1 and
                  (high - low) > diff and
                  #Next bar must be within highest/lowest
                  high[-1] < Highest(high, 2) and low[-1] > Lowest(low, 2)
               then 1
               else if day[1] != 78 and day >= 1 and
                       #2 bars: green, red, red, green
                       up[2] == 1 and up[1] == 0 and up == 0 and up[-1] == 1 and
                       (Highest(high, 2) - Lowest(low, 2)) > diff and
                       high[-1] < Highest(high, 2) and low[-1] > Lowest(low, 2)
               then 2
               else if day[3] != 78 and day >= 3 and
                       #3 bars: red, red, red
                       up[2] == 0 and up[1] == 0 and up == 0 and
                       (Highest(high, 3) - Lowest(low, 3)) > diff and
                       high[-1] < Highest(high, 3) and low[-1] > Lowest(low, 3)
               then 3
               else 0;

def hbear_   = if bear
               then if bear_hl == 1 then Highest(high, 1) else
                    if bear_hl == 2 then Highest(high, 2)
                    else Highest(high, 3)
               else hbear_[1];
def lbear_   = if bear
               then if bear_hl == 1 then Lowest(low, 1) else
                    if bear_hl == 2 then Lowest(low, 2)
                    else Lowest(low, 3)
               else lbear_[1];
def hbear    = if bear
               then if bear_hl == 1 then Highest(high, 1) else
                    if bear_hl == 2 then Highest(high, 2)
                    else Highest(high, 3)
               else if high < hbear_[1] and low > lbear_[1]
               then hbear[1] else Double.NaN;
def lbear    = if bear
               then if bear_hl == 1 then Lowest(low, 1) else
                    if bear_hl == 2 then Lowest(low, 2)
                    else Lowest(low, 3)
               else if high < hbear_[1] and low > lbear_[1]
               then lbear[1] else Double.NaN;
def hbearbar = if bear
               then 1 else 0;
def lbearbar = if bear
               then 1 else 0;

def dataCounthbear = CompoundValue(1, if hbearbar[1] == 0 and hbearbar then dataCounthbear[1] + 1 else dataCounthbear[1], 0);
def dataCountlbear = CompoundValue(1, if lbearbar[1] == 0 and lbearbar then dataCountlbear[1] + 1 else dataCountlbear[1], 0);

plot hhbear = if use_count_plot_limit and HighestAll(dataCounthbear) - dataCounthbear <= count - 1 or !use_count_plot_limit then hbear else Double.NaN;
hhbear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hhbear.SetDefaultColor(Color.CYAN);

plot llbear = if use_count_plot_limit and HighestAll(dataCountlbear) - dataCountlbear <= count - 1 or !use_count_plot_limit then lbear else Double.NaN;
llbear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llbear.SetDefaultColor(Color.CYAN);

AddChartBubble(show_bubbles and hbearbar[1] == 0 and hbearbar, hhbear + TickSize() * bubblemover_updown, hhbear, Color.RED);
AddChartBubble(show_bubbles and lbearbar[1] == 0 and lbearbar, llbear - TickSize() * bubblemover_updown, llbear, Color.RED, no);

plot fib1bear = llbear + (hhbear - llbear) * .382;
plot fib2bear = llbear + (hhbear - llbear) * .500;
plot fib3bear = llbear + (hhbear - llbear) * .618;
fib1bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1bear.SetDefaultColor(Color.WHITE);
fib2bear.SetDefaultColor(Color.YELLOW);
fib3bear.SetDefaultColor(Color.RED);
 
Last edited:
I revised the bull/bear definitions with some annotations to:

Identify a 1 bar, 2 bars and 3 bar sequences (red/green), with the Highest/Lowest defined within the 3 conditions.
If the bar after the bull or bear is not within the Highest/Lowest area, nothing will plot.
No overlap of bars between days when forming a bull/bear
Can Limit plots of bull/bear at input.


The indicator has improved significantly. But after the experiment, I found some notes (if you can modify them) ... see the picture

PkU9yUP.png


thank you very much for this indicator that it does a great job . I made several deals and not a single one failed, so thank you very much... And as I promised you earlier, I will provide you with the success and failure rates and the method of trading in them .. If there is a friends who can support us with help, I appreciate this collective effort and it is welcome
 
The indicator has improved significantly. But after the experiment, I found some notes (if you can modify them) ... see the picture

PkU9yUP.png


thank you very much for this indicator that it does a great job . I made several deals and not a single one failed, so thank you very much... And as I promised you earlier, I will provide you with the success and failure rates and the method of trading in them .. If there is a friends who can support us with help, I appreciate this collective effort and it is welcome

You're welcome. Looking at your images, which have been very useful, here is what I see:

1. No drawing as next candle exceeded high of single candle. The code is set to terminate the plots when the high or low is crossed. In this case the lines would have started to plot on the next candle. The logic required to differentiate this with no potential profit from other extended plot terminations with good potentials was not worth it. This was mentioned in the code and post with it.
2. The 2nd green next to it is the same situation, the following red candle is higher than the high of the green candle. No potential profit.
3&4 plotted okay to me.
5. Same as 1&2.

Based upon the above comments, I do not see a need to overly complicate things from a coding standpoint with things that are not going to be profitable.

Glad you had some success with it.
 

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