Khaled

Supply & Demand - Order Blocks

Category: Indicators By: Khaled Created: September 14, 2022, 9:31 AM
September 14, 2022, 9:31 AM
Indicators
54 Comments
Supply & Demand - Order Blocks

Hello PRC/PRT Community,

Below is a joint work between Nicolas (90%) and myself (10%) to convert Order Blocks code from TradingView. All credits go to Sonarlabs who made it available to the public.

For those who trade with Supply and Demand zones, this indicator could help you identify the zones where most likely there are unfilled orders left, which can be a magnet or Support and Resistance. It does not give signals, but it’s definitely a good complement with your Price Action tools. You need to pay attention how the price reacts to these zones, then take action and apply your own system.

You can change the “Sens” parameter to adjust to your Asset and Timeframe.

Above picture shows ES Futures on H4.

// Sonarlabs - Order Block Finder
// converted from TradingView
// Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocks

defparam drawonlastbaronly=true

Transparency = 80

sens = 28

once obcreatedbear = 0
once obcreatedbull = 0
once crossindexbear = 0
once crossindexbull = 0


// Custom Rate of Change (ROC) calculation. This is to calculate high momentum moves in the market.
pc = ((open - open[4]) / open[4]) * 100


// -----------------
sens = sens/100 //ExponentialAverage[8](pc) //sens/100
OBBullMitigation = close[1]
OBBearMitigation = close[1]


// If the ROC crossover our Sensitivty input - Then create a Bearish Order Block
// Sensitivty is negative as this is a Bearish OB
if pc crosses under -sens then
obcreatedbear = 1
crossindexbear = barindex
endif


// If the ROC crossover our Sensitivty input - Then create a Bullish Order Block
if pc crosses over sens then
obcreatedbull = 1
crossindexbull = barindex
endif


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//      Calculation
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------
// Bearish OB Creation
// -------------------------------
// Check if we should create a OB. Also check if we haven't created an OB in the last 5 candles.
if obcreatedbear and (crossindexbear - crossindexbear[1]) > 5 then
lastgreen = 0
hhighest = 0
// Loop through the most recent candles and find the first GREEN (Bullish) candle. We will place our OB here.
for i = 4 to 15
if close[i] > open[i] then
lastgreen = i
//populate the arrays of order block to draw them later
$left[plot]= barindex[lastgreen]
$top[plot]=high[lastgreen]
$bottom[plot]=low[lastgreen]
$right[plot]=barindex[lastgreen]
plot=plot+1 //increase the array column for next data
break
endif
next
endif


// -------------------------------
// Bullish OB Creation
// -------------------------------
// Check if we should create a OB, Also check if we haven't created an OB in the last 5 candles.
if obcreatedbull and (crossindexbull - crossindexbull[1]) > 5 then
lastred = 0
hhighest = 0
// Loop through the most recent candles and find the first RED (Beaarish) candle. We will place our OB here.
for ibull = 4 to 15
if close[ibull] < open[ibull] then
lastred = ibull
//populate the arrays of order block to draw them later
$leftbull[plotbull]= barindex[lastred]
$topbull[plotbull]=high[lastred]
$bottombull[plotbull]=low[lastred]
$rightbull[plotbull]=barindex[lastred]
plotbull=plotbull+1 //increase the array column for next data
break
endif
next
endif


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//      Cleanup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Clean up Bearish OB boxes
if plot>0 then
for j = plot-1 downto 0 //0 to plot-1
// If the two last closes are above the high of the bearish OB - Remove the OB
if $left[j]>0 then //check if the zone still exist
itop = $top[j]
breakout = summation[max(1,barindex-$left[j])](OBBearMitigation>itop)>=1 //2
if breakout then
$left[j]=0
endif
endif
next
endif

// Clean up Bullish OB boxes
if plotbull>0 then
for jbull = plotbull-1 downto 0 //0 to plotbull-1
// If the two last closes are below the low of the bullish OB - Remove the OB
if $leftbull[jbull]>0 then //check if the zone still exist
ibot = $bottombull[jbull]
breakoutbull = summation[max(1,barindex-$leftbull[jbull])](OBBullMitigation<ibot)>=1
if breakoutbull then
$leftbull[jbull]=0
endif
endif
next
endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//     Drawing
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if islastbarupdate then
//plot the Bearish boxes
if  plot>0 then //islastbarupdate and
for j = plot-1 downto 0 //0 to plot-1
if $left[j]>0 then
drawrectangle($left[j],$top[j],barindex,$bottom[j]) coloured("red",Transparency)bordercolor("red",Transparency)
endif
next
endif
//plot the Bullish boxes
if  plotbull>0 then //islastbarupdate and
for jbull = plotbull-1 downto 0 //0 to plotbull-1
if $leftbull[jbull]>0 then
drawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) coloured("green",Transparency)bordercolor("green",Transparency)
endif
next
endif
endif

return

Download
Filename: Supply-Demand-–-Order-Blocks.itf
Downloads: 1540
Khaled
Khaled Veteran
Operating in the shadows, I hack problems one by one. My bio is currently encrypted by a complex algorithm. Decryption underway...
Author’s Profile

Comments

Fpal
2 years ago
#

Hello, thanks very much for your work. I am trying to flag when the close price is in a green (1) or red zone (-1). I have tried the following code but it doesn't work. Not very good at coding... I'd be very grateful if someone could kindly point me in the right direction. Many thanks. // Identificación de la zona roja (bajista) o verde (alcista) isInRedZone = 0 isInGreenZone = 0 if plot > 0 then for j = plot-1 downto 0 // Iterar zonas rojas if $left[j] > 0 then if (close >= $bottom[j] and close 0 then for jbull = plotbull-1 downto 0 // Iterar zonas verdes if $leftbull[jbull] > 0 then if (close >= $bottombull[jbull] and close <= $topbull[jbull]) then isInGreenZone = 1 break endif ENDIF NEXT ENDIF return isInGreenZone, isInRedZone

gaby IDE
2 years ago
#

merci beaucoup, je l'ai mais il se place en bas avec le rsi, comment le placer au dessus sur le graphique svp?

Bodaris
3 years ago
#

Bonjour, Merci pour ce super code que je n'aurais su faire moi-même, TOP. Je me demandais, s'il serait pertinent d'avoir une variable "sens" dynamic" pour que cela colle au plus près à la spécificité de chaque actif ? Je sais pas si je me suis bien exprimé ?

Crillezz
4 years ago
#

Hello Khaled!! Is it possible to build a screener of the indicator when the price returns to a supply/demand zone?

pintris
3 years ago
#

Hi, same request. Could someone help in creating a screener for this great indicator that screens the stocks when the price enters this red/green "blocks" that this indicator created ? Many thanks

alb3rt1
3 years ago
#

I join the request to create if is it possible to build a screener based on the indicator when the price entering the supply/demand zone? Thanks

Ha
Ha
4 years ago
#

Hello Thank you for sharing the code. Your indicator doesn't work properly. No zones are printed on chart, instead I get an indicator window on the bottom that has a single straight line. Can you please tell me how to fix it? Regards,

FabienEmmanuel
4 years ago
#

Mon Email: fabien.emmanuel35@gmail.com

FabienEmmanuel
4 years ago
#

Bonjour Khaled, Merci pour ce super code (et les autres) et aux commentaires qui m'on permis de modifier la sensibilité directement dans la boite de dialogue (Au départ j'avait modifier les paramètres dans le code..) C'est top avant Je passais mon temps à tracer les zone de supply et demand.. Et comme je trace encore certains BOS et ChoCh et que j'ai vu que vous pouviez éventuellement partager un code plus complet et qui montre BOS et CHoCH, etc. J'en serais ravi moi de le recevoir !! n'ayant pas vraiment trouvé mon bonheur dans PRC Cordialement

fluvii
4 years ago
#

Hi, Khaled! I'm trying to use it in PRT12 beta but it doesn't work. In PRT11 works fine, but here I don't understand why not. Could you please help me? Thank you in advance!

Khaled
4 years ago
#

Sorry Fluvii, but I don't have v12 yet.

Matchsolo
4 years ago
#

Kalhed, ca ne serait pas possible de créer un robot de trading sur la base de ton travail ? C'est du super boulot

Khaled
4 years ago
#

Je n'ai pas essayé, mais les zones ne sont pas des signaux de trading.

Meelist
4 years ago
#

Hi Khaled! Thanks for the great work. But question, do I understand correctly, that if I want to use it for example on 3 different timeframes simultaneously, then I should just create 3 different indicator files with different sensitivity? And by your experience so far, let's say in futures (since that was your screenshot in the beginning), what would be the best sensitivities for example on weekly, daily, hourly (and perhaps even smaller) timeframes? Thanks!

Khaled
4 years ago
#

Hi Meelist, good questions. What I personally do on weekly basis : 1) add the indicator on a chart (without other indicators) to see clearly, 2) navigate from weekly, down to 30 min, 3) draw rectangles of the high TF, then keep these drawings on the lower TF, but at certain time you will have too many zones. So it all depends on your style of trading, if you're a scalper, the weekly zones would not be of much interest. You can adjust the sensitivity with your TF, but it doesn't change a lot (at least for ES).

wtangsiri
4 years ago
#

@Khaled, c'est plus la peine, j'ai trouvé la solution, Merci Khaled !

Khaled
4 years ago
#

C'est très bien. Tu pourrais partager ta solution avec nous stp? Merci

wtangsiri
4 years ago
#

yes, please send to my email address : williamtangsiri@gmail.com I will do for you, one question, are the lines that you draw (Supply and demand zones) coming from Bos and CHoCH ? Thanks.

wtangsiri
4 years ago
#

Could you show which "BOS" and which "CHoCH" making these Supply and Demand zone ? Thanks

Khaled
4 years ago
#

Hi, I'm not expert in Arrays. If you master programming Arrays, I can share with you a code that is more complete and which shows BOS and CHoCH, etc.

Erreerra
4 years ago
#

Gracias por el indicador es magnífico. El problema es que me tarda muchísimo en cargar ¿hay alguna forma de que vaya más rápido?

SkySurferBlue
4 years ago
#

Is there anything more I need to do for the indicator to show on the chart? I downloaded the file in this thread and imported it into ProRealtime v11. It has been added to a 4hr Gold chart but no colour bands are showing up.

Nicolas
4 years ago
#

Add it on the price and it should be displayed. https://www.prorealcode.com/blog/video-tutorials/how-to-add-an-indicator-on-price-prorealtime/

Borja Sanz
4 years ago
#

Thank you Khaled and Nicolas for this great indicator. Very helpfull. Great Job. I use it just as a guide for "hot" or relevants zones, so your predefined parameters are fine for me. CONGRATS!.

Dron
2 years ago
#

Gracias

Dron
4 years ago
#

En que time frame es recomendable usarlo?

Khaled
4 years ago
#

Sorry, I don't speak Spanish :)

ProRealCode ProRealCode
Loading...