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!
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.
CODE BELOW - Not Typical since original code delete previous lines.
minor modification on the script and added option to show today blocks only and color the OB bar.
CODE - update
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
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.
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: