Please – Translation of Order Blocks from TV

Forums ProRealTime English forum ProBuilder support Please – Translation of Order Blocks from TV

Viewing 15 posts - 1 through 15 (of 22 total)
  • #199375

    Hello,

    Can anyone please help translating the code below from TradingView? I don’t need the alerts. I just need the order blocks boxes to be drawn.

    Thanks in advance.

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © ClayeWeight

    // Sonarlabs – Order Block Finder
    //
    //
    // ENJOY THE FREE SCRIPT

    //@version=5
    indicator(title=’Sonarlab – Order Blocks’, shorttitle=’Sonarlab – OB’, overlay=true, max_boxes_count=20)
    _v = input.string(“1.0.2″, title=”Version”, options=[“1.0.2″], group=”Sonarlab.io”, tooltip=”This is a free script based on our premium Smart Money Concepts (SMC) indicator. Get a free trial of our SMC indicator by visiting our website.\nhttps://www.sonarlab.io”)
    sens = input.int(28, minval=1, title=’Sensitivity’, group=’Order Block’, tooltip=’Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocks.’)
    sens /= 100

    // OB
    OBMitigationType = input.string(“Close”, title=”OB Mitigation Type”, options=[“Close”, “Wick”], group=”Order Block”, tooltip=”Choose how Order Blocks are mitigated”)
    OBBullMitigation = OBMitigationType==”Close” ? close[1] : low
    OBBearMitigation = OBMitigationType==”Close” ? close[1] : high

    //OB Colors
    col_bullish = input.color(#5db49e, title=”Bullish OB Border”, inline=”a”, group=”Order Block”)
    col_bullish_ob = input.color(color.new(#64C4AC, 85), title=”Background”, inline=”a”, group=”Order Block”)

    col_bearish = input.color(#4760bb, title=”Bearish OB Border”, inline=”b”, group=”Order Block”)
    col_bearish_ob = input.color(color.new(#506CD3, 85), title=”Background”, inline=”b”, group=”Order Block”)

    // Alerts
    buy_alert = input.bool(title=’Buy Signal’, defval=true, group=’Alerts’, tooltip=’An alert will be sent when price goes below the top of a bullish order block.’)
    sell_alert = input.bool(title=’Sell Signal’, defval=true, group=’Alerts’, tooltip=’An alert will be sent when price goes above the bottom of a bearish order block.’)

    // Delacring Variables
    bool ob_created = false
    bool ob_created_bull = false
    var int cross_index = na

    // Declaring Box Arrays
    var box drawlongBox = na
    var longBoxes = array.new_box()
    var box drawShortBox = na
    var shortBoxes = array.new_box()

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

    // If the ROC crossover our Sensitivty input – Then create an Order Block
    // Sensitivty is negative as this is a Bearish OB
    if ta.crossunder(pc, -sens)
    ob_created := true
    cross_index := bar_index
    cross_index

    // If the ROC crossover our Sensitivty input – Then create an Order Block
    if ta.crossover(pc, sens)
    ob_created_bull := true
    cross_index := bar_index
    cross_index

    // ——————————-
    // 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 ob_created and cross_index – cross_index[1] > 5
    float last_green = 0
    float highest = 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 by 1
    if close[i] > open[i]
    last_green := i
    break
    // Draw our OB on that candle – then push the box into our box arrays.
    drawShortBox := box.new(left=bar_index[last_green], top=high[last_green], bottom=low[last_green], right=bar_index[last_green], bgcolor=col_bearish_ob, border_color=col_bearish, extend=extend.right)
    array.push(shortBoxes, drawShortBox)

    // ——————————-
    // 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 ob_created_bull and cross_index – cross_index[1] > 5
    float last_red = 0
    float highest = 0
    // Loop through the most recent candles and find the first RED (Bearish) candle. We will place our OB here.
    for i = 4 to 15 by 1
    if close[i] < open[i]
    last_red := i
    break
    // Draw our OB on that candle – then push the box into our box arrays.
    drawlongBox := box.new(left=bar_index[last_red], top=high[last_red], bottom=low[last_red], right=bar_index[last_red], bgcolor=col_bullish_ob, border_color=col_bullish, extend=extend.right)
    array.push(longBoxes, drawlongBox)

    // —————– Bearish Order Block ——————-
    // Clean up OB boxes and place alerts
    if array.size(shortBoxes) > 0
    for i = array.size(shortBoxes) – 1 to 0 by 1
    sbox = array.get(shortBoxes, i)
    top = box.get_top(sbox)
    bot = box.get_bottom(sbox)
    // If the two last closes are above the high of the bearish OB – Remove the OB
    if OBBearMitigation > top
    array.remove(shortBoxes, i)
    box.delete(sbox)
    // Alerts
    if high > bot and sell_alert
    alert(‘Price inside Bearish OB’, alert.freq_once_per_bar)

    // —————– Bullish Clean Up ——————-
    // Clean up OB boxes and place alerts
    if array.size(longBoxes) > 0
    for i = array.size(longBoxes) – 1 to 0 by 1
    sbox = array.get(longBoxes, i)
    bot = box.get_bottom(sbox)
    top = box.get_top(sbox)
    // If the two last closes are below the low of the bullish OB – Remove the OB
    if OBBullMitigation < bot
    array.remove(longBoxes, i)
    box.delete(sbox)
    // Alerts
    if low < top and buy_alert
    alert(‘Price inside Bullish OB’, alert.freq_once_per_bar)

    #199376

    Better with the screenshot

    #199437

    Anyone can help PLEASE ! It will benefit all the PRT community.

    Thank you 🙂

    #199440
    JS

    I can’t translate the code but maybe this is a beginning:

     

    It looks like a SAR with a custom ROC calculation:

    pc = (open – open[4]) / open[4] * 100

    The trigger lines are set with “Sensitivty” (sens = 28/100)

    At a positive crossing (Crosses Over) “Bullish OB” are drawn:

    If pc crosses over sens then

    As a starting point, the last red candle is sought

    For i = 4 to 15

    If Close[i] < Open[i] then

    LastRed = i

    Break

    At a negative crossing (Crosses Under) “Bearish OB” are drawn:

    If pc crosses under -sens then

    with the last green candle as the starting point.

    For i = 4 to 15

    If Close[i] > Open[i] then

    LastGreen = i

    Break

    #199442

    Thank you JS!

    #199443

    I tried my best, but I’m still far away… Nicolas, Roberto, pleeeease!

     

    #199453

    Sorry, I don’t have a good knowledge of then Pinescript programming language.

     

    1 user thanked author for this post.
    #199506

    Dear All,

    Below my updated attempt to convert the code above, but it doesn’t seem to work properly. Any help would be much appreciated.

     

    #199508

    Dear @Nicolas,

    please HELP !

    Thanks a million!

    #199811

    Since most of us were on holidays, I suspect this why I didn’t get too many replies.

    @Nicolas, can you please help with this Order Blocks code?

    Thanks

    Khaled

    #199874

    Please don’t multiple post for the same query. We are all very busy, trying to solve queries everywhere, please be patient.

    1 user thanked author for this post.
    #200306

    Nicolas,

    I understand PRT doesn’t handle yet two dimension Arrays.

    Can’t substiute  “array.push(longBoxes, drawlongBox)” with

    $array1 = longBoxes

    $array2 = drawlongBox

    and then create a conditional drawing of the box:

    if array1 = condition1 and $array2 = condition2 then

    drawrectangle(…)

    endif

     

    like you have done on the first example on Arrays about Support and Resistance.

     

    Merci beaucoup

     

    #200329

    I tried my best, spent hours reading TradingView coding manual, but couldn’t reach a satisfactory result.

    Can someone who knows Arrays in PRT (not necessary need to know TradingView) please help me to figure out if all Arrays are OK and why it doesn’t remove old order blocks? The original TradingView code is above.

    A BIG THANK YOU!

     

    #200334

    You can’t remove previous objects on the chart if they are painted along the read of history. The best thing to do is to paint them all from the last candlestick within a loop through your arrays.

    1 user thanked author for this post.
    #200336

    Ok digging into the code and I understand where is the trouble, all that zones must be erased if the price has breached them.

    Just made the version for the bearish zones, you can learn from it to create the other side 🙂

     

    2 users thanked author for this post.
Viewing 15 posts - 1 through 15 (of 22 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login