Supply & Demand – Order Blocks

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.

Share this

Risk disclosure:

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 : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. Razz • 11 days ago #

    Thank you Khaled and Nicolas for this great indicator I’ve been looking for something like this for a long time.

  2. Khaled • 11 days ago #

    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).

  3. ThaNoizy • 9 days ago #

    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?

  4. Barrabas15 • 8 days ago #

    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.

    • Khaled • 7 days ago #

      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.

  5. Barrabas15 • 7 days ago #

    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

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

    • Khaled • 7 days ago #

      @Barrabas15 I see your point, but I have the same result with “Sensi “or “Sensib”.

  6. Barrabas15 • 6 days ago #

    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.

    • Khaled • 6 days ago #

      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.

  7. ThaNoizy • 5 days ago #

    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?

    • Khaled • 5 days ago #

      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]

  8. ThaNoizy • 5 days ago #

    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

  9. jonpt88 • 4 days ago #

    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!

    • Khaled • 4 days ago #

      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.

  10. Barrabas15 • 3 days ago #

    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.

  11. larouedegann • 2 days ago #

    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.

    • Khaled • 13 mins ago #

      @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 🙂

Register or


avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
Carlos Garcia If price tags the lower BBand, look for IIIX has positive values to enter a trade. Converse...