Repaints Order Block Finder for ThinkOrSwim

Repaints

samer800

Conversion Expert
VIP
Lifetime
Release Notes (By the TV creator):

But as there seem to be some misunderstandings and confusion about the usage and the logic of the indicator, I want to make some important remarks regarding this:

1) The Order Blocks are NOT DETECTED in REAL TIME!
  • A Bullish Order Block is the last red candle BEFORE a subsequent series of green candle
  • A Bearish Order Block is the last green candle BEFORE a subsequent series of red candles
The required length of the series is defined by the parameter "Relevant Periods to identify OB" (by default it is set to 5).
This means that the earliest an Order Block can be identified with these settings is 5 candles AFTER it has occurred!

As a result of this....

2) The identified Order Blocks (and therefore also the Alerts) are not BUY or SELL signals!
As I have mentioned in the description before, these identified Order Blocks rather show "Areas of Interest" on the chart where there is an increased probability that the price will revisit these levels at one point in the future (but no guarantee of course!).

3) ....and YES, it REPAINTS....by definition!
A "repainting" indicator is changing signals in the past. As according to the defined logic an Order Block can only be identified AFTER future conditions are met, it will of course "repaint" the signal into the chart only after at least the relevant period has elapsed - the same applies to the Alerts. If you intend to complain about this "repainting", then I am sorry to say that you did not understand what this is used for and I advise you not to use this indicator. I would then advise you to first read a bit about Institutional Order Flow.

4) This is not the "Perfect Indicator".....
When you look at the historical performance on the chart, it looks like that the Indicator ALWAYS called a perfect entry! But due to the definition of the logic and due to the delay/repainting, this is misleading if you do not understand how it is supposed to work. So please make sure that you REALLY understand it before you use it - I tried to be very clear in my explanations.

One more thing:
As I am not a financial adviser, this is no shape or form financial advise. This study serves only for experimental & educational purposes. Trading & investing comes with risk - so do your own research.

PJwToDN.png


CODE BELOW - Not Typical since original code delete previous lines.

CSS:
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)

input ShowCloud = yes;
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks  = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel  = yes; # "Show latest Bullish Channel?"
input showBearChannel  = yes; # "Show latest Bearish Channel?"

def na = Double.NaN;
def bar = barNumber();
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}

def ob_period = periods + 1;
def absmove   = ((AbsValue(close[ob_period] - close[1])) / close[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = close[ob_period] < open[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
            p + (if close[i] > open[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def OB_bull_high = if OB_bull  then if usewicks then high[ob_period] else open[ob_period] else na;
def OB_bull_low  = if OB_bull  then low[ob_period] else na;
def OB_bull_avg  = (OB_bull_high + OB_bull_low) / 2;

def ObBull     = if OB_bull then getvalue(close, periods) else na;
def ObBullHigh = if OB_bull_high then getvalue(if usewicks then high else open, periods) else na;
def ObBullLow  = if OB_bull_low then getvalue(low, periods) else na;
def ObBullAvg  = (ObBullHigh + ObBullLow) / 2;


def ph_1 = if !isnan(ObBullHigh) then ObBullHigh else ph_1[1];

def hh = !isnan(ObBullHigh) and ObBullHigh > ph_1[1];

def ObBullHLine = CompoundValue(1,if isNaN(OB_bull_high) then ObBullHLine[1] else OB_bull_high,OB_bull_high);
def ObBullLLine = CompoundValue(1,if isNaN(OB_bull_low) then ObBullLLine[1] else OB_bull_low,OB_bull_low);
def ObBullALine = CompoundValue(1,if isNaN(OB_bull_avg) then ObBullALine[1] else OB_bull_avg,OB_bull_avg);

#// Bearish Order Block Identification
def bearishOB = close[ob_period] > open[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
    s + (if close[j] < open[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def OB_bear_high = if OB_bear then high[ob_period] else na;
def OB_bear_low  = if OB_bear then if usewicks then low[ob_period] else open[ob_period] else na;
def OB_bear_avg  = (OB_bear_low + OB_bear_high)/2;

def ObBear     = if OB_bear then getvalue(close, periods) else na;
def ObBearhigh = if OB_bear_high then getvalue(high, periods) else na;
def ObBearlow  = if OB_bear_low then if usewicks then low[ob_period] else open[ob_period] else na;
def ObBearavg  = (ObBearhigh + ObBearlow) / 2;

def ObBearHLine = CompoundValue(1,if isNaN(OB_bear_high) then ObBearHLine[1] else OB_bear_high,OB_bear_high);
def ObBearLLine = CompoundValue(1,if isNaN(OB_bear_low) then ObBearLLine[1] else OB_bear_low,OB_bear_low);
def ObBearALine = CompoundValue(1,if isNaN(OB_bear_avg) then ObBearALine[1] else OB_bear_avg,OB_bear_avg);
#// Plotting

plot ObBull1 = if ObBull[-ob_period] then low else na;#"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if ObBullHigh[-ob_period] then if usewicks then high else open else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if ObBullLow[-ob_period] then low else na;#"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 =(bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

#AssignPriceColor(if ObBull1 then color.blue else na);
#// Bearish OB Indicator
plot ObBear1 =if ObBear[-ob_period] then high else na; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if ObBearlow[-ob_period] then if usewicks then low else open else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if ObBearLow[-ob_period] then high else na;; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2;; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

######################################

plot BullHLine = ObBullHLine;
BullHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullHLine.SetDefaultColor(Color.GRAY);
BullHLine.SetHiding(!showBullChannel);

plot BullLLine = ObBullLLine;
BullLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullLLine.SetDefaultColor(Color.GRAY);
BullLLine.SetHiding(!showBullChannel);

plot BullALine = ObBullALine;
BullALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullALine.SetDefaultColor(Color.GRAY);
BullALine.SetHiding(!showBullChannel);

AddCloud(if ShowCloud and BullHLine == BullHLine[1] then BullHLine else na, BullLLine, Color.DARK_GRAY);     
#---------------------------------------------------

plot BearHLine = ObBearHLine;
BearHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearHLine.SetDefaultColor(CreateColor(33,150,243));
BearHLine.SetHiding(!showBearChannel);

plot BearLLine = ObBearLLine;
BearLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearLLine.SetDefaultColor(CreateColor(33,150,243));
BearLLine.SetHiding(!showBearChannel);

plot BearALine = ObBearALine;
BearALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearALine.SetDefaultColor(CreateColor(33,150,243));
BearALine.SetHiding(!showBearChannel);

AddCloud(if ShowCloud and BearHLine == BearHLine[1] then BearHLine else na, BearLLine, CreateColor(33,100,122));

##### END of CODE

minor modification on the script and added option to show today blocks only and color the OB bar.

CODE - update

CSS:
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)
# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)
# Updated . Added ShowTodayOnly option and color OB bar - 09/2022

input ShowTodayOnly = yes;
input ColorOBBar = yes;
input ShowCloud = yes;
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks  = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel  = yes; # "Show latest Bullish Channel?"
input showBearChannel  = yes; # "Show latest Bearish Channel?"

def na = Double.NaN;
def today = GetDay()==GetLastDay();
def bar = barNumber();
def o = open;
def c = close;
def h = high;
def l = low;
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
def ob_period = periods + 1;
def absmove   = ((AbsValue(c[ob_period] - c[1])) / c[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = c[ob_period] < o[ob_period];

#def period = periods;
def upcandles;
    upcandles = fold i = 1 to periods with p=1 do
            p + (if c[i] > o[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def OB_bull_high = if OB_bull  then if(usewicks,h[ob_period],o[ob_period]) else na;
def OB_bull_low  = if OB_bull  then l[ob_period] else na;
def OB_bull_avg  = (OB_bull_high + OB_bull_low) / 2;

def ObBull     = if OB_bull then c[ob_period] else na;
def ObBullHigh = if OB_bull_high then if(usewicks,h[ob_period],o[ob_period]) else na;
def ObBullLow  = if OB_bull_low then l[ob_period] else na;
def ObBullAvg  = (ObBullHigh + ObBullLow) / 2;

def ObBullHLine = CompoundValue(1,if isNaN(OB_bull_high) then ObBullHLine[1] else
                 OB_bull_high,OB_bull_high);
def ObBullLLine = CompoundValue(1,if isNaN(OB_bull_low) then ObBullLLine[1] else
                 OB_bull_low,OB_bull_low);
def ObBullALine = CompoundValue(1,if isNaN(OB_bull_avg) then ObBullALine[1] else
                 OB_bull_avg,OB_bull_avg);

#// Bearish Order Block Identification
def bearishOB = c[ob_period] > o[ob_period];

def downcandles;
    downcandles = fold j = 1 to periods with s=1 do
        s + (if c[j] < o[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def OB_bear_high = if OB_bear then h[ob_period] else na;
def OB_bear_low  = if OB_bear then if(usewicks,l[ob_period],o[ob_period]) else na;
def OB_bear_avg  = (OB_bear_low + OB_bear_high)/2;

def ObBear     = if OB_bear then c[ob_period] else na;
def ObBearhigh = if OB_bear_high then h[ob_period] else na;
def ObBearlow  = if OB_bear_low then if(usewicks,l[ob_period],o[ob_period]) else na;
def ObBearavg  = (ObBearhigh + ObBearlow) / 2;

def ObBearHLine = CompoundValue(1,if isNaN(OB_bear_high) then ObBearHLine[1] else
                 OB_bear_high,OB_bear_high);
def ObBearLLine = CompoundValue(1,if isNaN(OB_bear_low) then ObBearLLine[1] else
                 OB_bear_low,OB_bear_low);
def ObBearALine = CompoundValue(1,if isNaN(OB_bear_avg) then ObBearALine[1] else
                 OB_bear_avg,OB_bear_avg);
#// Plotting

plot ObBull1 = if ObBull[-ob_period] then l else na;#"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if ObBullHigh[-ob_period] then if(usewicks,h,o) else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if ObBullLow[-ob_period] then l else na;#"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 =(bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

#AssignPriceColor(if ObBull1 then color.blue else na);
#// Bearish OB Indicator
plot ObBear1 =if ObBear[-ob_period] then h else na; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if ObBearlow[-ob_period] then if(usewicks,l, o) else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if ObBearLow[-ob_period] then h else na; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2;; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

######################################

plot BullHLine = if ShowTodayOnly then if today then ObBullHLine else na else ObBullHLine;
BullHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullHLine.SetDefaultColor(Color.GRAY);
BullHLine.SetHiding(!showBullChannel);

plot BullLLine = if ShowTodayOnly then if today then ObBullLLine else na else ObBullLLine;
BullLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullLLine.SetDefaultColor(Color.GRAY);
BullLLine.SetHiding(!showBullChannel);

plot BullALine = if ShowTodayOnly then if today then ObBullALine else na else ObBullALine;
BullALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullALine.SetDefaultColor(CreateColor(0, 255, 255));
#BullALine.SetHiding(!showBullChannel);
    
#---------------------------------------------------

plot BearHLine = if ShowTodayOnly then if today then ObBearHLine else na else ObBearHLine;
BearHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearHLine.SetDefaultColor(CreateColor(33,150,243));
BearHLine.SetHiding(!showBearChannel);

plot BearLLine = if ShowTodayOnly then if today then ObBearLLine else na else ObBearLLine;
BearLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearLLine.SetDefaultColor(CreateColor(33,150,243));
BearLLine.SetHiding(!showBearChannel);

plot BearALine = if ShowTodayOnly then if today then ObBearALine else na else ObBearALine;
BearALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearALine.SetDefaultColor(CreateColor(255, 0, 255));
#BearALine.SetHiding(!showBearChannel);

#--- Cloud & Bar Color
AddCloud(if ShowCloud and BullHLine == BullHLine[1] then BullHLine else na, BullLLine, CreateColor(4, 103, 117));

AddCloud(if ShowCloud and BearHLine == BearHLine[1] then BearHLine else na, BearLLine, CreateColor(100, 2, 117));

AssignPriceColor(if ColorOBBar and ObBull[-ob_period] then color.Blue else Color.CURRENT);
AssignPriceColor(if ColorOBBar and ObBear[-ob_period] then color.MAGENTA else Color.CURRENT);

##### END of CODE
 
Last edited:
Release Notes (By the TV creator):

But as there seem to be some misunderstandings and confusion about the usage and the logic of the indicator, I want to make some important remarks regarding this:

1) The Order Blocks are NOT DETECTED in REAL TIME!
  • A Bullish Order Block is the last red candle BEFORE a subsequent series of green candle
  • A Bearish Order Block is the last green candle BEFORE a subsequent series of red candles
The required length of the series is defined by the parameter "Relevant Periods to identify OB" (by default it is set to 5).
This means that the earliest an Order Block can be identified with these settings is 5 candles AFTER it has occurred!

As a result of this....

2) The identified Order Blocks (and therefore also the Alerts) are not BUY or SELL signals!
As I have mentioned in the description before, these identified Order Blocks rather show "Areas of Interest" on the chart where there is an increased probability that the price will revisit these levels at one point in the future (but no guarantee of course!).

3) ....and YES, it REPAINTS....by definition!
A "repainting" indicator is changing signals in the past. As according to the defined logic an Order Block can only be identified AFTER future conditions are met, it will of course "repaint" the signal into the chart only after at least the relevant period has elapsed - the same applies to the Alerts. If you intend to complain about this "repainting", then I am sorry to say that you did not understand what this is used for and I advise you not to use this indicator. I would then advise you to first read a bit about Institutional Order Flow.

4) This is not the "Perfect Indicator".....
When you look at the historical performance on the chart, it looks like that the Indicator ALWAYS called a perfect entry! But due to the definition of the logic and due to the delay/repainting, this is misleading if you do not understand how it is supposed to work. So please make sure that you REALLY understand it before you use it - I tried to be very clear in my explanations.

One more thing:
As I am not a financial adviser, this is no shape or form financial advise. This study serves only for experimental & educational purposes. Trading & investing comes with risk - so do your own research.

PJwToDN.png


CODE BELOW - Not Typical since original code delete previous lines.

CSS:
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)

input ShowCloud = yes;
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks  = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel  = yes; # "Show latest Bullish Channel?"
input showBearChannel  = yes; # "Show latest Bearish Channel?"

def na = Double.NaN;
def bar = barNumber();
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}

def ob_period = periods + 1;
def absmove   = ((AbsValue(close[ob_period] - close[1])) / close[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = close[ob_period] < open[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
            p + (if close[i] > open[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def OB_bull_high = if OB_bull  then if usewicks then high[ob_period] else open[ob_period] else na;
def OB_bull_low  = if OB_bull  then low[ob_period] else na;
def OB_bull_avg  = (OB_bull_high + OB_bull_low) / 2;

def ObBull     = if OB_bull then getvalue(close, periods) else na;
def ObBullHigh = if OB_bull_high then getvalue(if usewicks then high else open, periods) else na;
def ObBullLow  = if OB_bull_low then getvalue(low, periods) else na;
def ObBullAvg  = (ObBullHigh + ObBullLow) / 2;


def ph_1 = if !isnan(ObBullHigh) then ObBullHigh else ph_1[1];

def hh = !isnan(ObBullHigh) and ObBullHigh > ph_1[1];

def ObBullHLine = CompoundValue(1,if isNaN(OB_bull_high) then ObBullHLine[1] else OB_bull_high,OB_bull_high);
def ObBullLLine = CompoundValue(1,if isNaN(OB_bull_low) then ObBullLLine[1] else OB_bull_low,OB_bull_low);
def ObBullALine = CompoundValue(1,if isNaN(OB_bull_avg) then ObBullALine[1] else OB_bull_avg,OB_bull_avg);

#// Bearish Order Block Identification
def bearishOB = close[ob_period] > open[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
    s + (if close[j] < open[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def OB_bear_high = if OB_bear then high[ob_period] else na;
def OB_bear_low  = if OB_bear then if usewicks then low[ob_period] else open[ob_period] else na;
def OB_bear_avg  = (OB_bear_low + OB_bear_high)/2;

def ObBear     = if OB_bear then getvalue(close, periods) else na;
def ObBearhigh = if OB_bear_high then getvalue(high, periods) else na;
def ObBearlow  = if OB_bear_low then if usewicks then low[ob_period] else open[ob_period] else na;
def ObBearavg  = (ObBearhigh + ObBearlow) / 2;

def ObBearHLine = CompoundValue(1,if isNaN(OB_bear_high) then ObBearHLine[1] else OB_bear_high,OB_bear_high);
def ObBearLLine = CompoundValue(1,if isNaN(OB_bear_low) then ObBearLLine[1] else OB_bear_low,OB_bear_low);
def ObBearALine = CompoundValue(1,if isNaN(OB_bear_avg) then ObBearALine[1] else OB_bear_avg,OB_bear_avg);
#// Plotting

plot ObBull1 = if ObBull[-ob_period] then low else na;#"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if ObBullHigh[-ob_period] then if usewicks then high else open else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if ObBullLow[-ob_period] then low else na;#"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 =(bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

#AssignPriceColor(if ObBull1 then color.blue else na);
#// Bearish OB Indicator
plot ObBear1 =if ObBear[-ob_period] then high else na; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if ObBearlow[-ob_period] then if usewicks then low else open else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if ObBearLow[-ob_period] then high else na;; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2;; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

######################################

plot BullHLine = ObBullHLine;
BullHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullHLine.SetDefaultColor(Color.GRAY);
BullHLine.SetHiding(!showBullChannel);

plot BullLLine = ObBullLLine;
BullLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullLLine.SetDefaultColor(Color.GRAY);
BullLLine.SetHiding(!showBullChannel);

plot BullALine = ObBullALine;
BullALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullALine.SetDefaultColor(Color.GRAY);
BullALine.SetHiding(!showBullChannel);

AddCloud(if ShowCloud and BullHLine == BullHLine[1] then BullHLine else na, BullLLine, Color.DARK_GRAY);     
#---------------------------------------------------

plot BearHLine = ObBearHLine;
BearHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearHLine.SetDefaultColor(CreateColor(33,150,243));
BearHLine.SetHiding(!showBearChannel);

plot BearLLine = ObBearLLine;
BearLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearLLine.SetDefaultColor(CreateColor(33,150,243));
BearLLine.SetHiding(!showBearChannel);

plot BearALine = ObBearALine;
BearALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearALine.SetDefaultColor(CreateColor(33,150,243));
BearALine.SetHiding(!showBearChannel);

AddCloud(if ShowCloud and BearHLine == BearHLine[1] then BearHLine else na, BearLLine, CreateColor(33,100,122));

##### END of CODE
This is awesome! Thank you for taking the time to make this!
 
Great script....I modified the script with bullish and bearish clouds.
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked) / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)

input ShowCloud = yes;
input periods = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel = yes; # "Show latest Bullish Channel?"
input showBearChannel = yes; # "Show latest Bearish Channel?"

def na = Double.NaN;
def bar = barNumber();
script nz {
input data = 1;
input repl = 0;
def ret_val = if IsNaN(data) then repl else data;
plot return = ret_val;
}

def ob_period = periods + 1;
def absmove = ((AbsValue(close[ob_period] - close[1])) / close[ob_period]) * 100;
def relmove = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = close[ob_period] < open[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
p + (if close > open then 1 else 0);

def OB_bull = bullishOB and (upcandles == periods) and relmove;
def OB_bull_high = if OB_bull then if usewicks then high[ob_period] else open[ob_period] else na;
def OB_bull_low = if OB_bull then low[ob_period] else na;
def OB_bull_avg = (OB_bull_high + OB_bull_low) / 2;

def ObBull = if OB_bull then getvalue(close, periods) else na;
def ObBullHigh = if OB_bull_high then getvalue(if usewicks then high else open, periods) else na;
def ObBullLow = if OB_bull_low then getvalue(low, periods) else na;
def ObBullAvg = (ObBullHigh + ObBullLow) / 2;


def ph_1 = if !isnan(ObBullHigh) then ObBullHigh else ph_1[1];

def hh = !isnan(ObBullHigh) and ObBullHigh > ph_1[1];

def ObBullHLine = CompoundValue(1,if isNaN(OB_bull_high) then ObBullHLine[1] else OB_bull_high,OB_bull_high);
def ObBullLLine = CompoundValue(1,if isNaN(OB_bull_low) then ObBullLLine[1] else OB_bull_low,OB_bull_low);
def ObBullALine = CompoundValue(1,if isNaN(OB_bull_avg) then ObBullALine[1] else OB_bull_avg,OB_bull_avg);

#// Bearish Order Block Identification
def bearishOB = close[ob_period] > open[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
s + (if close[j] < open[j] then 1 else 0);

def OB_bear = bearishOB and (downcandles == periods) and relmove;
def OB_bear_high = if OB_bear then high[ob_period] else na;
def OB_bear_low = if OB_bear then if usewicks then low[ob_period] else open[ob_period] else na;
def OB_bear_avg = (OB_bear_low + OB_bear_high)/2;

def ObBear = if OB_bear then getvalue(close, periods) else na;
def ObBearhigh = if OB_bear_high then getvalue(high, periods) else na;
def ObBearlow = if OB_bear_low then if usewicks then low[ob_period] else open[ob_period] else na;
def ObBearavg = (ObBearhigh + ObBearlow) / 2;

def ObBearHLine = CompoundValue(1,if isNaN(OB_bear_high) then ObBearHLine[1] else OB_bear_high,OB_bear_high);
def ObBearLLine = CompoundValue(1,if isNaN(OB_bear_low) then ObBearLLine[1] else OB_bear_low,OB_bear_low);
def ObBearALine = CompoundValue(1,if isNaN(OB_bear_avg) then ObBearALine[1] else OB_bear_avg,OB_bear_avg);
#// Plotting

plot ObBull1 = if ObBull[-ob_period] then low else na;#"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if ObBullHigh[-ob_period] then if usewicks then high else open else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if ObBullLow[-ob_period] then low else na;#"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 =(bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

#AssignPriceColor(if ObBull1 then color.blue else na);
#// Bearish OB Indicator
plot ObBear1 =if ObBear[-ob_period] then high else na; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if ObBearlow[-ob_period] then if usewicks then low else open else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if ObBearLow[-ob_period] then high else na;; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2;; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

######################################

plot BullHLine = ObBullHLine;
BullHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullHLine.SetDefaultColor(Color.GRAY);
BullHLine.SetHiding(!showBullChannel);

plot BullLLine = ObBullLLine;
BullLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullLLine.SetDefaultColor(Color.GRAY);
BullLLine.SetHiding(!showBullChannel);

plot BullALine = ObBullALine;
BullALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullALine.SetDefaultColor(Color.GRAY);
BullALine.SetHiding(!showBullChannel);

AddCloud(if ShowCloud and BullHLine == BullHLine[1] then BullHLine else na, BullALine, Color.Light_green);
AddCloud(if ShowCloud and BullLLine == BullLLine[1] then BullLLine else na, BullALine, Color.pink);
#---------------------------------------------------

plot BearHLine = ObBearHLine;
BearHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearHLine.SetDefaultColor(CreateColor(33,150,243));
BearHLine.SetHiding(!showBearChannel);

plot BearLLine = ObBearLLine;
BearLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearLLine.SetDefaultColor(CreateColor(33,150,243));
BearLLine.SetHiding(!showBearChannel);

plot BearALine = ObBearALine;
BearALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearALine.SetDefaultColor(CreateColor(33,150,243));
BearALine.SetHiding(!showBearChannel);

AddCloud(if ShowCloud and BearLLine == BearLLine[1] then BearLLine else na, BearALine, Color.pink);
AddCloud(if ShowCloud and BearHLine == BearHLine[1] then BearHLine else na, BearALine, Color.Light_green);
##### END of CODE
 
Great work on this script. Is it possible to add MTF options on this script? For example, have 15 min order book levels on 3 min chart?
 
Sorry I meant to request that on the orderblock indicator! @samer800

  • A metric to consider blocks mitigated or not (tested x amount of times) ( I see this adjusts to end a block when a new like-one is created)
  • A way to extend blocks longer past the generation of new blocks
  • A MTF function
 
Release Notes (By the TV creator):

But as there seem to be some misunderstandings and confusion about the usage and the logic of the indicator, I want to make some important remarks regarding this:

1) The Order Blocks are NOT DETECTED in REAL TIME!
  • A Bullish Order Block is the last red candle BEFORE a subsequent series of green candle
  • A Bearish Order Block is the last green candle BEFORE a subsequent series of red candles
The required length of the series is defined by the parameter "Relevant Periods to identify OB" (by default it is set to 5).
This means that the earliest an Order Block can be identified with these settings is 5 candles AFTER it has occurred!

As a result of this....

2) The identified Order Blocks (and therefore also the Alerts) are not BUY or SELL signals!
As I have mentioned in the description before, these identified Order Blocks rather show "Areas of Interest" on the chart where there is an increased probability that the price will revisit these levels at one point in the future (but no guarantee of course!).

3) ....and YES, it REPAINTS....by definition!
A "repainting" indicator is changing signals in the past. As according to the defined logic an Order Block can only be identified AFTER future conditions are met, it will of course "repaint" the signal into the chart only after at least the relevant period has elapsed - the same applies to the Alerts. If you intend to complain about this "repainting", then I am sorry to say that you did not understand what this is used for and I advise you not to use this indicator. I would then advise you to first read a bit about Institutional Order Flow.

4) This is not the "Perfect Indicator".....
When you look at the historical performance on the chart, it looks like that the Indicator ALWAYS called a perfect entry! But due to the definition of the logic and due to the delay/repainting, this is misleading if you do not understand how it is supposed to work. So please make sure that you REALLY understand it before you use it - I tried to be very clear in my explanations.

One more thing:
As I am not a financial adviser, this is no shape or form financial advise. This study serves only for experimental & educational purposes. Trading & investing comes with risk - so do your own research.

PJwToDN.png


CODE BELOW - Not Typical since original code delete previous lines.

CSS:
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)

input ShowCloud = yes;
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"
input useWicks  = no; # "Use whole range [High/Low] for OB marking?" )
input showBullChannel  = yes; # "Show latest Bullish Channel?"
input showBearChannel  = yes; # "Show latest Bearish Channel?"

def na = Double.NaN;
def bar = barNumber();
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}

def ob_period = periods + 1;
def absmove   = ((AbsValue(close[ob_period] - close[1])) / close[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = close[ob_period] < open[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
            p + (if close[i] > open[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def OB_bull_high = if OB_bull  then if usewicks then high[ob_period] else open[ob_period] else na;
def OB_bull_low  = if OB_bull  then low[ob_period] else na;
def OB_bull_avg  = (OB_bull_high + OB_bull_low) / 2;

def ObBull     = if OB_bull then getvalue(close, periods) else na;
def ObBullHigh = if OB_bull_high then getvalue(if usewicks then high else open, periods) else na;
def ObBullLow  = if OB_bull_low then getvalue(low, periods) else na;
def ObBullAvg  = (ObBullHigh + ObBullLow) / 2;


def ph_1 = if !isnan(ObBullHigh) then ObBullHigh else ph_1[1];

def hh = !isnan(ObBullHigh) and ObBullHigh > ph_1[1];

def ObBullHLine = CompoundValue(1,if isNaN(OB_bull_high) then ObBullHLine[1] else OB_bull_high,OB_bull_high);
def ObBullLLine = CompoundValue(1,if isNaN(OB_bull_low) then ObBullLLine[1] else OB_bull_low,OB_bull_low);
def ObBullALine = CompoundValue(1,if isNaN(OB_bull_avg) then ObBullALine[1] else OB_bull_avg,OB_bull_avg);

#// Bearish Order Block Identification
def bearishOB = close[ob_period] > open[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
    s + (if close[j] < open[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def OB_bear_high = if OB_bear then high[ob_period] else na;
def OB_bear_low  = if OB_bear then if usewicks then low[ob_period] else open[ob_period] else na;
def OB_bear_avg  = (OB_bear_low + OB_bear_high)/2;

def ObBear     = if OB_bear then getvalue(close, periods) else na;
def ObBearhigh = if OB_bear_high then getvalue(high, periods) else na;
def ObBearlow  = if OB_bear_low then if usewicks then low[ob_period] else open[ob_period] else na;
def ObBearavg  = (ObBearhigh + ObBearlow) / 2;

def ObBearHLine = CompoundValue(1,if isNaN(OB_bear_high) then ObBearHLine[1] else OB_bear_high,OB_bear_high);
def ObBearLLine = CompoundValue(1,if isNaN(OB_bear_low) then ObBearLLine[1] else OB_bear_low,OB_bear_low);
def ObBearALine = CompoundValue(1,if isNaN(OB_bear_avg) then ObBearALine[1] else OB_bear_avg,OB_bear_avg);
#// Plotting

plot ObBull1 = if ObBull[-ob_period] then low else na;#"Bullish OB"
ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
ObBull1.SetDefaultColor(Color.WHITE);
ObBull1.SetLineWeight(2);

plot bull1 = if ObBullHigh[-ob_period] then if usewicks then high else open else na;
bull1.SetPaintingStrategy(PaintingStrategy.DASHES);
bull1.SetDefaultColor(Color.WHITE);
bull1.SetLineWeight(2);

plot bull2 = if ObBullLow[-ob_period] then low else na;#"Bullish OB Low"
bull2.SetPaintingStrategy(PaintingStrategy.DASHES);
bull2.SetDefaultColor(Color.WHITE);
bull2.SetLineWeight(2);

plot ObBullAvg1 =(bull1 + bull2) / 2; #"Bullish OB Average"
ObBullAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBullAvg1.SetDefaultColor(Color.WHITE);
ObBullAvg1.SetLineWeight(2);

#AssignPriceColor(if ObBull1 then color.blue else na);
#// Bearish OB Indicator
plot ObBear1 =if ObBear[-ob_period] then high else na; # "Bearish OB"
ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ObBear1.SetDefaultColor(CreateColor(33,150,243));
ObBear1.SetLineWeight(2);

plot bear1 = if ObBearlow[-ob_period] then if usewicks then low else open else na;
bear1.SetPaintingStrategy(PaintingStrategy.DASHES);
bear1.SetDefaultColor(CreateColor(33,150,243));
bear1.SetLineWeight(2);

plot bear2 = if ObBearLow[-ob_period] then high else na;; # "Bearish OB High"
bear2.SetPaintingStrategy(PaintingStrategy.DASHES);
bear2.SetDefaultColor(CreateColor(33,150,243));
bear2.SetLineWeight(2);

plot ObBearAvg1 = (bear1 + bear2) / 2;; #"Bearish OB Average"
ObBearAvg1.SetPaintingStrategy(PaintingStrategy.DASHES);
ObBearAvg1.SetDefaultColor(CreateColor(33,150,243));
ObBearAvg1.SetLineWeight(2);

######################################

plot BullHLine = ObBullHLine;
BullHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullHLine.SetDefaultColor(Color.GRAY);
BullHLine.SetHiding(!showBullChannel);

plot BullLLine = ObBullLLine;
BullLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BullLLine.SetDefaultColor(Color.GRAY);
BullLLine.SetHiding(!showBullChannel);

plot BullALine = ObBullALine;
BullALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullALine.SetDefaultColor(Color.GRAY);
BullALine.SetHiding(!showBullChannel);

AddCloud(if ShowCloud and BullHLine == BullHLine[1] then BullHLine else na, BullLLine, Color.DARK_GRAY);     
#---------------------------------------------------

plot BearHLine = ObBearHLine;
BearHLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearHLine.SetDefaultColor(CreateColor(33,150,243));
BearHLine.SetHiding(!showBearChannel);

plot BearLLine = ObBearLLine;
BearLLine.SetPaintingStrategy(PaintingStrategy.DASHES);
BearLLine.SetDefaultColor(CreateColor(33,150,243));
BearLLine.SetHiding(!showBearChannel);

plot BearALine = ObBearALine;
BearALine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearALine.SetDefaultColor(CreateColor(33,150,243));
BearALine.SetHiding(!showBearChannel);

AddCloud(if ShowCloud and BearHLine == BearHLine[1] then BearHLine else na, BearLLine, CreateColor(33,100,122));

##### END of CODE
Samer800, Would it be possible for you to share a link to your screen shown at the beginning of your post, please. I am having a hard time setting the indicator like you show it. Thank you
 
Samer800, Would it be possible for you to share a link to your screen shown at the beginning of your post, please. I am having a hard time setting the indicator like you show it. Thank you
I use the default settings. not sure about your issue. However, I amended the code to show today OB only and color the OB bar. try it
 
I use the default settings. not sure about your issue. However, I amended the code to show today OB only and color the OB bar. try it
Okay, got it. I think that is the look I am after. Thanks for your time. Thanks for great indicator
 
I stumbled across this one today and it is quite interesting. I found all of the zones that were printing on the chart was a bit too busy for my liking so I've attempted to simplify but only placing a cloud around the candles that form the block. I'm not 100% sure that the blocks are always in the right place but here is a look at today's action:
JwnEymx.png


The chart above is a 1m chart showing the 5m order blocks on ES. I have left all of the original comments, even though some are no longer applicable to this version of the study.

Ruby:
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)
# multi-timeframe support and simplified lines added by tony_futures - 10/2022
input higherTimeFrame = AggregationPeriod.FIVE_MIN;
def htf = higherTimeFrame;
def xO = open(period = htf);
def xH = high(period = htf);
def xL = low(period = htf);
def xC = close(period = htf);
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"

def na = Double.NaN;

def ob_period = periods + 1;
def absmove   = ((AbsValue(xC[ob_period] - xC[1])) / xC[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = xC[ob_period] < xO[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
            p + (if xC[i] > xO[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def ObBull     = if OB_bull then getvalue(xC, periods) else na;


#// Bearish Order Block Identification
def bearishOB = xC[ob_period] > xO[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
    s + (if xC[j] < xO[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def ObBear     = if OB_bear then getvalue(xC, periods) else na;

DefineGlobalColor("BullCloud", Color.GRAY);
DefineGlobalColor("BearCloud", Color.GRAY);

def plotBull = ObBull[-ob_period];
AddCloud(if plotBull then xH else Na, xL, GlobalColor("BullCloud"), GlobalColor("BullCloud"));
#plot ObBull1 = if plotBull then xH else na;#"Bullish OB"
#ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
#ObBull1.SetDefaultColor(Color.WHITE);
#ObBull1.SetLineWeight(2);

#// Bearish OB Indicator
def plotBear = ObBear[-ob_period];
AddCloud(if plotBear then xH else Na, xL, GlobalColor("BearCloud"), GlobalColor("BearCloud"));
#plot ObBear1 =if plotBear then xL else na; # "Bearish OB"
#ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#ObBear1.SetDefaultColor(CreateColor(33,150,243));
#ObBear1.SetLineWeight(2);
 
I stumbled across this one today and it is quite interesting. I found all of the zones that were printing on the chart was a bit too busy for my liking so I've attempted to simplify but only placing a cloud around the candles that form the block. I'm not 100% sure that the blocks are always in the right place but here is a look at today's action:
JwnEymx.png


The chart above is a 1m chart showing the 5m order blocks on ES. I have left all of the original comments, even though some are no longer applicable to this version of the study.

Ruby:
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)
# multi-timeframe support and simplified lines added by tony_futures - 10/2022
input higherTimeFrame = AggregationPeriod.FIVE_MIN;
def htf = higherTimeFrame;
def xO = open(period = htf);
def xH = high(period = htf);
def xL = low(period = htf);
def xC = close(period = htf);
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"

def na = Double.NaN;

def ob_period = periods + 1;
def absmove   = ((AbsValue(xC[ob_period] - xC[1])) / xC[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = xC[ob_period] < xO[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
            p + (if xC[i] > xO[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def ObBull     = if OB_bull then getvalue(xC, periods) else na;


#// Bearish Order Block Identification
def bearishOB = xC[ob_period] > xO[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
    s + (if xC[j] < xO[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def ObBear     = if OB_bear then getvalue(xC, periods) else na;

DefineGlobalColor("BullCloud", Color.GRAY);
DefineGlobalColor("BearCloud", Color.GRAY);

def plotBull = ObBull[-ob_period];
AddCloud(if plotBull then xH else Na, xL, GlobalColor("BullCloud"), GlobalColor("BullCloud"));
#plot ObBull1 = if plotBull then xH else na;#"Bullish OB"
#ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
#ObBull1.SetDefaultColor(Color.WHITE);
#ObBull1.SetLineWeight(2);

#// Bearish OB Indicator
def plotBear = ObBear[-ob_period];
AddCloud(if plotBear then xH else Na, xL, GlobalColor("BearCloud"), GlobalColor("BearCloud"));
#plot ObBear1 =if plotBear then xL else na; # "Bearish OB"
#ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#ObBear1.SetDefaultColor(CreateColor(33,150,243));
#ObBear1.SetLineWeight(2);
Have you tried this in live trading and if so, can you approximate if or when the OB's appear? OP stated this does not detect OB's in real time. Just wondering if there's a way to do so. Thank you for your efforts!
 
Have you tried this in live trading and if so, can you approximate if or when the OB's appear? OP stated this does not detect OB's in real time. Just wondering if there's a way to do so. Thank you for your efforts!
It seems like they show up a few candles after the fact. It's just the nature of the beast. The pattern requires several candles to confirm. I'm mainly looking at them as points of interest if they were not revisited before they showed up - if that makes sense.
 
It seems like they show up a few candles after the fact. It's just the nature of the beast. The pattern requires several candles to confirm. I'm mainly looking at them as points of interest if they were not revisited before they showed up - if that makes sense.
Certainly understand that. I loaded it and noticed the paint/repainting of the boxes. Love the concept and find it to be a very useful tool. Wish there was a way to help identify the OB boxed area a bit sooner, even with the lag. Thanks again for your contributions!!!
 
Certainly understand that. I loaded it and noticed the paint/repainting of the boxes. Love the concept and find it to be a very useful tool. Wish there was a way to help identify the OB boxed area a bit sooner, even with the lag. Thanks again for your contributions!!!
I'm not sure they can be identified much sooner. The opposite move needs to happen before they are 'valid'. There was another interesting example from this morning:
S2AAFQH.png
 
I'm not sure they can be identified much sooner. The opposite move needs to happen before they are 'valid'. There was another interesting example from this morning:
S2AAFQH.png
Yes. Saw this as well which was why I asked. I loaded it on a 1m and 3m ES chart. This looks like my 3m, but the 1m actually had 2 OB sell boxes. Not sure how long either appeared or reappeared, but was interesting to see as well. Thanks
 
1min tf on /ES, when the boxes show up, they're good for a quick 1-2pt scalp, fyi. In & Out. Love the strategy and I follow the TWTR account too.
 
I stumbled across this one today and it is quite interesting. I found all of the zones that were printing on the chart was a bit too busy for my liking so I've attempted to simplify but only placing a cloud around the candles that form the block. I'm not 100% sure that the blocks are always in the right place but here is a look at today's action:
JwnEymx.png


The chart above is a 1m chart showing the 5m order blocks on ES. I have left all of the original comments, even though some are no longer applicable to this version of the study.

Ruby:
#// This experimental Indicator helps identifying instituational Order Blocks.
#// Often these blocks signal the beginning of a strong move, but there is a significant probability that these price levels will be revisited at a later point in time again.
#// Therefore these are interesting levels to place limit orders (Buy Orders for Bullish OB / Sell Orders for Bearish OB).
#// A Bullish Order block is defined as the last down candle before a sequence of up candles. (Relevant price range "Open" to "Low" is marked)  / Optionally full range "High" to "Low"
#// A Bearish Order Block is defined as the last up candle before a sequence of down candles. (Relevant price range "Open" to "High" is marked) / Optionally full range "High" to "Low"
#// In the settings the number of required sequential candles can be adjusted.
#// Furthermore a %-threshold can be entered. It defines which %-change the sequential move needs to achieve in order to identify a relevant Order Block.
#// Channels for the last Bullish/Bearish Block can be shown/hidden.
#// In addition to the upper/lower limits of each Order Block, also the equlibrium (average value) is marked as this is an interesting area for price interaction.
#// Alerts added: Alerts fire when an Order Block is detected. The delay is based on the "Relevant Periods" input. Means with the default setting "5" the alert will trigger after the
#// number of consecutive candles is reached.
#https://www.tradingview.com/script/R8g2YHdg-Order-Block-Finder-Experimental/
#study("Order Block Finder", overlay = true)

# Converted & mod by Sam4COK @ Samer800 - 08/2022 (Not typical conversion)
# multi-timeframe support and simplified lines added by tony_futures - 10/2022
input higherTimeFrame = AggregationPeriod.FIVE_MIN;
def htf = higherTimeFrame;
def xO = open(period = htf);
def xH = high(period = htf);
def xL = low(period = htf);
def xC = close(period = htf);
input periods   = 5; # "Relevant Periods to identify OB")
input threshold = 0.0; # "Min. Percent move to identify OB"

def na = Double.NaN;

def ob_period = periods + 1;
def absmove   = ((AbsValue(xC[ob_period] - xC[1])) / xC[ob_period]) * 100;
def relmove   = absmove >= threshold;

#// Bullish Order Block Identification
def bullishOB = xC[ob_period] < xO[ob_period];

#def period = periods;
def upcandles = fold i = 1 to periods + 1 with p do
            p + (if xC[i] > xO[i] then 1 else 0);

def OB_bull      = bullishOB and (upcandles == periods) and relmove;
def ObBull     = if OB_bull then getvalue(xC, periods) else na;


#// Bearish Order Block Identification
def bearishOB = xC[ob_period] > xO[ob_period];

def downcandles;
downcandles = fold j = 1 to periods + 1 with s do
    s + (if xC[j] < xO[j] then 1 else 0);

def OB_bear      = bearishOB and (downcandles == periods) and relmove;
def ObBear     = if OB_bear then getvalue(xC, periods) else na;

DefineGlobalColor("BullCloud", Color.GRAY);
DefineGlobalColor("BearCloud", Color.GRAY);

def plotBull = ObBull[-ob_period];
AddCloud(if plotBull then xH else Na, xL, GlobalColor("BullCloud"), GlobalColor("BullCloud"));
#plot ObBull1 = if plotBull then xH else na;#"Bullish OB"
#ObBull1.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
#ObBull1.SetDefaultColor(Color.WHITE);
#ObBull1.SetLineWeight(2);

#// Bearish OB Indicator
def plotBear = ObBear[-ob_period];
AddCloud(if plotBear then xH else Na, xL, GlobalColor("BearCloud"), GlobalColor("BearCloud"));
#plot ObBear1 =if plotBear then xL else na; # "Bearish OB"
#ObBear1.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#ObBear1.SetDefaultColor(CreateColor(33,150,243));
#ObBear1.SetLineWeight(2);

This version is how order blocks should be located and charted - with the line showing where the block is so you can clearly see when it retraces (and possibly a high wick line so you can see when they run stops on people). Nice work, now if I can just get it to show up when market is closed...
 
This version is how order blocks should be located and charted - with the line showing where the block is so you can clearly see when it retraces (and possibly a high wick line so you can see when they run stops on people). Nice work, now if I can just get it to show up when market is closed...
I cannot make it work on ES chart 1min. could I have link to your chart please?
 

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

Thread starter Similar threads Forum Replies Date
FutureTony Naked POC finder For ThinkOrSwim Indicators 5
C Phoenix Finder Trend Strength Indicator for ThinkorSwim Indicators 30

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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