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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
// 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 |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Thank you Khaled and Nicolas for this great indicator I’ve been looking for something like this for a long time.
The Graph has been screenshot over last weekend. Difficult to see the scale on the graph above, but there is a zone around 3940 detected by the indicator which served as support following yesterday’s flash crash on the ES (following release of CPI).
Hey, I can’t get any values from the indicator when I am backtesting, the indicator is supposed to show all order blocks in the past aaswell, right?
bonjour Khaled pouvez vous me dire comment regler l’indicateur pour qu’il affiche les block avec la derniere bougie avant le mouvement et non pas avec l’avant derniere ou avant avant derniere bougie merci d’avance
It is not possible to modify the sensitivity as per the current code. In order to modify it, the “sens” parameter must be changed to another one in lines 22 (1st parameter, not 2nd), 29 and 36.
Sorry Barrabs, I didn’t get your point. Do you mean that we need to change manually “Sens” in lines 22, 29 and 36? For me, it works fine as it is.
With the current code I cannot change the sensitivity (try it anyway).
I attach part of the code in which I have changed the parameter “sens” to “sensib” in lines 22, 29 and 36.
This way I can change the sensitivity.
sensib = 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 -sensib then
obcreatedbear = 1
crossindexbear = barindex
endif
// If the ROC crossover our Sensitivty input – Then create a Bullish Order Block
if pc crosses over sensib then
obcreatedbull = 1
crossindexbull = barindex
endif
@Barrabas15 I see your point, but I have the same result with “Sensi “or “Sensib”.
With the original code the variable “sens” is useless. Even if you modify it, nothing changes.
With the proposal that I indicate when changing the parameters of the variable, the supply/demand zones DO change.
I’ve tested with a large spectrum of values of “Sens” and you’re right, for certain values of “Sens”, it doesn’t show order blocks. However, when I replace “Sens” with “Sensb”, it shows new blocks. Well spotted. Thank you.
I am trying to make an algo around this indicator but it is hard because the indicator doesn’t provide any values? Could any of you help me with an example code to make the algo buy when price is inside the order block?
Thanks
The concept of the Order Blocks is that Institutional come there to search for liquidity. Depending on your timeframe, the price may spend sometime there on a lower TF. The general idea is that you don’t trade Long or Short inside the Box. You wait for a breakout in either direction.
I didn’t try to put a System together using Order Blocks, but you can try with the variables :
a1) $top[j]
a2 )$bottom[j]
b1) $bottombull[jbull]
b2) $topbull[jbull]
I tried your idea Khaled but got the error that says that j and jbull is undefined. do you think this is because the variable is defined in the indicator code and not the system code? Here is the code however:
c4 = (close) < a1
c5 = (close) > a2
a1 = $top[j]
a2 = $bottom[j]
b1 = $bottombull[jbull]
b2 = $topbull[jbull]
c6 = (close) > b1
c7 = (close) < b2
This is a great indicator. Unfortunately, I have too much red and green colour in the chart already. How could I change the colour from lets say from green to light blue and from red to pink? Thank you so much for letting me know. Very much appreciated and sorry for such a question. Thank you for this great indicator again!
Hello Jonpt, to change the colors you need to go to lines 133 & 141 and change (“red”, transparency) and (“green”,transparency) with (r,g,b, transparency) codes you see better fit. You have the codes of the colors r, g and b available on this forum or just google RGB PINK and you will get (255,192,203). I hope this is clear enough.
Attached is a link with the colors you can use with their names. You only have to change in the code the words “green” and “red” by some name of any of the colors of the palette. https://www.prorealcode.com/documentation/coloured/
thanks you so much! 🙂
hello traders,
how to load it on my mt4 please?
I downloaded but can’t find it in mt4 indicator
Hello, we do not provide MT4 code on our website. You should use ProRealTime trading platform in order to benefit from our codes.
BRAVO
très bon code pour ceux qui traident le volumes.
pour ma part j’ai remplacer le 100 de la ligne 22 par un code créer dans les variables(celui que vous voulez ,NBR)
ce qui évite de rentrer à chaque fois dans le code.
@larouedegann, this is what I’ve done on my PRT platform, but I put it here directly in the code to make it easier for those who will copy/paste the code instead of downloading the .itf 🙂
à quoi correspond le chiffre 100 ? et quelle valeur peut-on la remplacer ? Merci.
Hi PRC community, what is the code to add to limit the lenght of each rectangle drawn to 5 period (for example) ? Bonjour à toute la communauté, quel est le code à ajouter pour limiter la largeur des rectangles qui sont dessinés à 5 periodes (par exemple) ? Merci !
The idea is to be able to see the rectangle on the last candle. Therefore drawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) starts from where the Order Block has been detected to the last candles (Barindex). If you want to limit the the number of bars the either you do “barindex-x “(chose x) or “$leftbull[jbull]+y” (which in your case is 5).
Thanks so much Khaled for your help
Hi , Thanks for sharing. Does it works in intra’day ? Also, is there any documentation about the concepts the indicator is based ?
Thanks
It is supposed to work on all timeframes. However, the higher the TF, the more reliable the result. You need to adjust the “sens” factor and adapt it for each TF. I would suggest that you focus on a max of 3 TFs. For example, you can visit the weekly TF once per week and draw the zones so that they appear on lower TF, then move to visit Daily, H4 and H1 and draw the zones, then trade as per your system (e.g. M5) with these zones in mind. The idea of these order blocks is that it CAN play a role of Support/Resistance or magnet. I say CAN, because some of the zones may or may not attract new orders. Some of the zones become obsolete after a while, once all the big hands have finished their shopping or distribution at certain zones. I don’t have a specific documentation, but there are a lot of videos on Sypply/demand zones on youtube.
En que time frame es recomendable usarlo?
Sorry, I don’t speak Spanish 🙂
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!.
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.
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/
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?
Could you show which “BOS” and which “CHoCH” making these Supply and Demand zone ? Thanks
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.
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.
@Khaled, c’est plus la peine, j’ai trouvé la solution, Merci Khaled !
C’est très bien. Tu pourrais partager ta solution avec nous stp? Merci
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!
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).
Kalhed, ca ne serait pas possible de créer un robot de trading sur la base de ton travail ?
C’est du super boulot
Je n’ai pas essayé, mais les zones ne sont pas des signaux de trading.
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!
Sorry Fluvii, but I don’t have v12 yet.
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
Mon Email: fabien.emmanuel35@gmail.com
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,
Hello Khaled!!
Is it possible to build a screener of the indicator when the price returns to a supply/demand zone?
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
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
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é ?
merci beaucoup, je l’ai mais il se place en bas avec le rsi, comment le placer au dessus sur le graphique svp?