Master Pattern Indicator conversion

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #252962 quote
    yas
    Participant
    Junior

    Hi ivan

    is it possible if you can convert this code into PRT for me please i think this will be a good and complete edition of Master Pattern i think everyone will benefit if you can help Please

    here is the code

    //@version=5

    indicator(“Master Pattern Indicator”,overlay = true,max_boxes_count = 500, max_lines_count = 500, max_bars_back = 5000)

    Major_Box_Color = input.color(color.rgb(81, 55, 226),”Major Box Color”)
    show_minor_boxes = input.bool(false,”Show Minor Boxes”)
    Minor_Box_Color = input.color(color.rgb(163, 160, 160),”Minor Box Color”)
    Major_Expansion_Line_Color = input.color(color.rgb(238, 238, 238),”Major Expansion Line Color”)
    Major_Expansion_Line_Style = input.string(“Solid”,”Major Expansion Line Style”,[“Solid”,”Dotted”,”Dashed”])
    Major_Expansion_Line_Thickness = input.int(2,”Major Expansion Line Thickness”)
    show_minor_expansion = input.bool(true,”Show Minor Expansion Lines”)
    Minor_Expansion_Line_Color = input.color(color.rgb(241, 238, 239),”Minor Expansion Line Color”)
    Minor_Expansion_Line_Style = input.string(“Dashed”,”Minor Expansion Line Style”,[“Solid”,”Dotted”,”Dashed”])
    Minor_Expansion_Line_Thickness = input.int(1,”Minor Expansion Line Thickness”)
    Sell_Line_Color = input.color(color.red,”Sell Side Liquidity Line Color”)
    Sell_Line_Style = input.string(“Dotted”,”Sell Side Liquidity Line Style”,[“Solid”,”Dotted”,”Dashed”])
    Sell_Line_Thickness = input.int(1,”Sell Side Liquidity Line Thickness”)
    Buy_Line_Color = input.color(color.green,”Buy Side Liquidity Line Color”)
    Buy_Line_Style = input.string(“Dotted”,”Buy Side Liquidity Line Style”,[“Solid”,”Dotted”,”Dashed”])
    Buy_Line_Thickness = input.int(1,”Buy Side Liquidity Line Thickness”)
    max_bars = input.int(500,”Max Bars Back”)
    indi_type = input.int(1,”Type”)
    alert_major_line_confirm = input.bool(true,”Major Line Confirmation”,group = “Alerts”)
    alert_major_line_cross = input.bool(true,”Major Line Crossing”,group = “Alerts”)
    alert_liquidity_line_touch = input.bool(true,”Liquidity Line Touching”,group = “Alerts”)
    //n = input.int(title=”Fractals Periods”, defval=2, minval=2)
    repaint = true

    // // UpFractal
    // bool upflagDownFrontier = true
    // bool upflagUpFrontier0 = true
    // bool upflagUpFrontier1 = true
    // bool upflagUpFrontier2 = true
    // bool upflagUpFrontier3 = true
    // bool upflagUpFrontier4 = true

    // for i = 1 to n
    // upflagDownFrontier := upflagDownFrontier and (high[n-i] < high[n])
    // upflagUpFrontier0 := upflagUpFrontier0 and (high[n+i] < high[n])
    // upflagUpFrontier1 := upflagUpFrontier1 and (high[n+1] <= high[n] and high[n+i + 1] < high[n])
    // upflagUpFrontier2 := upflagUpFrontier2 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+i + 2] < high[n])
    // upflagUpFrontier3 := upflagUpFrontier3 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+i + 3] < high[n])
    // upflagUpFrontier4 := upflagUpFrontier4 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+4] <= high[n] and high[n+i + 4] < high[n])
    // flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4

    // upFractal = (upflagDownFrontier and flagUpFrontier)

    // // downFractal
    // bool downflagDownFrontier = true
    // bool downflagUpFrontier0 = true
    // bool downflagUpFrontier1 = true
    // bool downflagUpFrontier2 = true
    // bool downflagUpFrontier3 = true
    // bool downflagUpFrontier4 = true

    // for i = 1 to n
    // downflagDownFrontier := downflagDownFrontier and (low[n-i] > low[n])
    // downflagUpFrontier0 := downflagUpFrontier0 and (low[n+i] > low[n])
    // downflagUpFrontier1 := downflagUpFrontier1 and (low[n+1] >= low[n] and low[n+i + 1] > low[n])
    // downflagUpFrontier2 := downflagUpFrontier2 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+i + 2] > low[n])
    // downflagUpFrontier3 := downflagUpFrontier3 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+i + 3] > low[n])
    // downflagUpFrontier4 := downflagUpFrontier4 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+4] >= low[n] and low[n+i + 4] > low[n])
    // flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4

    // downFractal = (downflagDownFrontier and flagDownFrontier)

    // var zz = array.new_float()
    // var yy = array.new_int()

    // if upFractal
    // array.push(zz, high)
    // array.push(yy,bar_index)

    // if downFractal
    // array.push(zz, low)
    // array.push(yy,bar_index)

    var Depth = 3
    var Deviation = 1
    var Backstep = 1

    if(indi_type==2)
    Depth := 2

    var last_h = 1, last_h := last_h + 1
    var last_l = 1, last_l := last_l + 1
    var lw = 1, var hg = 1
    lw := lw + 1, hg := hg + 1
    p_lw = -ta.lowestbars(Depth), p_hg = -ta.highestbars(Depth)
    lowing = lw == p_lw or low – low[p_lw] > Deviation*syminfo.mintick
    highing = hg == p_hg or high[p_hg] – high > Deviation*syminfo.mintick
    lh = ta.barssince(not highing[1]), ll = ta.barssince(not lowing[1])
    down = ta.barssince(not (lh > ll)) >= Backstep, lower = low[lw] > low[p_lw], higher = high[hg] < high[p_hg]
    if lw != p_lw and (not down[1] or lower)
    lw := p_lw < hg ? p_lw : 0
    if hg != p_hg and (down[1] or higher)
    hg := p_hg < lw ? p_hg : 0

    var zz = array.new_float()
    var yy = array.new_int()
    x1 = down ? lw : hg
    y1 = down ? low[lw] : high[hg]

    if down == down[1]
    if repaint
    if(array.size(zz)>0)
    array.pop(zz)
    array.pop(yy)
    down
    if down != down[1]
    if down
    last_h := hg
    else
    last_l := lw
    if not repaint
    nx = down?last_h:last_l
    array.push(zz, (down ? low[last_l] : high[last_h]))
    array.push(yy,bar_index-(down?last_l:last_h))
    down
    if repaint
    array.push(zz, y1)
    array.push(yy,bar_index-x1)

    allowPlot()=>
    (last_bar_index-bar_index<=max_bars)

    checkTrigger()=>
    value1 = 0.0, value2 = 0.0, value3 = 0.0, value4 = 0.0, counter = 0, res = false, pos = 0
    if(array.size(zz)>=4 and array.size(yy)>=4)
    for x = array.size(zz)-1 to 0
    if(x<array.size(zz))
    price = array.get(zz,x)
    counter += 1
    if(counter == 1)
    value1 := price
    if(counter == 2)
    value2 := price
    pos := array.get(yy,x)
    if(counter == 3)
    value3 := price
    if(counter == 4)
    value4 := price
    break
    if((value1<value2 and value1>value3 and value4>value2) or
    (value1>value2 and value1<value3 and value4<value2))
    res := true
    [res, math.max(value1,value2), math.min(value1,value2), pos]

    var minorBoxes = array.new_box()
    var minorBoxNames = array.new_string()
    var minorCrossedHigh = array.new_bool()
    var minorCrossedLow = array.new_bool()
    var expansionLines = array.new_line()
    var minorExpansionLines = array.new_line()
    [RES,Val1,Val2,POS] = checkTrigger()
    if(RES and allowPlot())
    array.push(minorBoxes, box.new(time[bar_index-POS],Val1,time,Val2,xloc=xloc.bar_time,border_color=(show_minor_boxes?Minor_Box_Color:na),bgcolor=(show_minor_boxes?Minor_Box_Color:na)))
    array.push(minorBoxNames, “Active Box”)
    array.push(minorCrossedHigh, false), array.push(minorCrossedLow, false)

    updateExpansionLines(Time,Line,clear,checktimes)=>
    if(array.size(Line)>0)
    for x = 0 to array.size(Line)-1
    if(x < array.size(checktimes) and x < array.size(Line))
    if(Time>array.get(checktimes,x))
    line.set_x2(array.get(Line,x),Time)
    if(clear)
    array.remove(Line,x)

    var check = array.new_int()
    var checkMinor = array.new_int()

    updateExpansionLines(time,expansionLines,false,check)
    updateExpansionLines(time,minorExpansionLines,false,checkMinor)

    var majorBoxLines = array.new_line()
    var majorBoxLineType = array.new_int()
    var majorBoxLineRef = array.new_int()
    var Crossed = array.new_bool()

    getHighOffset(Time)=>
    x = 1, hi = high, res = 0
    while(time[x]>=Time)
    if(high[x]>hi)
    hi := high[x]
    res := x
    x += 1
    res

    getLowOffset(Time)=>
    x = 1, lo = low, res = 0
    while(time[x]>=Time)
    if(low[x]<lo)
    lo := low[x]
    res := x
    x += 1
    res

    checkCross(line_array, price)=>
    result = false
    Prices = price
    if array.size(line_array) > 0
    for x = 0 to array.size(line_array)-1
    Price = line.get_y1(array.get(line_array,x))
    if (Prices > Price and Prices[1] <= Price) or (Prices < Price and Prices[1] >= Price)
    result := true
    result

    operateMinorBox(price,hi_price,lo_price,Time)=>
    var lastMinorExp = 0
    confirm = false

    if(array.size(minorBoxes)>0 and array.size(minorCrossedHigh)>0 and array.size(minorCrossedLow)>0 and array.size(minorBoxNames)>0)
    x = array.size(minorBoxes)-1
    if array.get(minorBoxNames,x)!=”NULL”
    top = box.get_top(array.get(minorBoxes,x)), bottom = box.get_bottom(array.get(minorBoxes,x))
    time1 = box.get_left(array.get(minorBoxes,x))
    time2 = box.get_right(array.get(minorBoxes,x)), ppp = bottom+(top-bottom)/2
    origCrossedHigh = array.get(minorCrossedHigh,x)
    origCrossedLow = array.get(minorCrossedLow,x)
    if(not array.get(minorCrossedHigh,x) and not array.get(minorCrossedLow,x))
    if(not barstate.islast or barstate.isconfirmed)
    if(price>top)
    array.set(minorCrossedHigh,x,true)
    if(price<bottom)
    array.set(minorCrossedLow,x,true)
    else
    if(hi_price>top)
    array.set(minorCrossedHigh,x,true)
    if(lo_price<bottom)
    array.set(minorCrossedLow,x,true)
    if(array.get(minorCrossedHigh,x) and array.get(minorCrossedLow,x))
    box.set_bgcolor(array.get(minorBoxes,x),Major_Box_Color)
    array.set(minorBoxNames,x,”NULL”)
    updateExpansionLines(time2,expansionLines,true,check)
    confirm := true
    if(show_minor_expansion)
    updateExpansionLines(time2,minorExpansionLines,true,checkMinor)
    array.push(expansionLines,line.new(time2,ppp,time,ppp,xloc.bar_time,extend.none,Major_Expansion_Line_Color,
    (Major_Expansion_Line_Style==”Solid”?line.style_solid:Major_Expansion_Line_Style==”Dotted”?line.style_dotted:
    line.style_dashed),Major_Expansion_Line_Thickness))
    array.push(check,time2)
    hi_pos = getHighOffset(time2)
    lo_pos = getLowOffset(time2)
    if(not origCrossedHigh)
    rrr = low[lo_pos]
    array.push(majorBoxLines, line.new(time[lo_pos],rrr,Time,rrr,xloc.bar_time,extend.none,Buy_Line_Color,
    (Buy_Line_Style==”Solid”?line.style_solid:Buy_Line_Style==”Dotted”?line.style_dotted:line.style_dashed),
    Buy_Line_Thickness))
    array.push(majorBoxLineType,0)
    else if(not origCrossedLow)
    rrr = high[hi_pos]
    array.push(majorBoxLines, line.new(time[hi_pos],rrr,Time,rrr,xloc.bar_time,extend.none,Sell_Line_Color,
    (Sell_Line_Style==”Solid”?line.style_solid:Sell_Line_Style==”Dotted”?line.style_dotted:line.style_dashed),
    Sell_Line_Thickness))
    array.push(majorBoxLineType,1)
    array.push(majorBoxLineRef,time2)
    array.push(Crossed,false)
    true
    else if(not array.get(minorCrossedHigh,x) and not array.get(minorCrossedLow,x))
    box.set_right(array.get(minorBoxes,x),Time)
    true
    else if(show_minor_expansion and time1!=lastMinorExp)
    updateExpansionLines(time2,minorExpansionLines,true,checkMinor)
    array.push(minorExpansionLines, line.new(time2,ppp,time,ppp,xloc.bar_time,extend.none,Minor_Expansion_Line_Color,
    (Minor_Expansion_Line_Style==”Solid”?line.style_solid:Minor_Expansion_Line_Style==”Dotted”?line.style_dotted:
    line.style_dashed),Minor_Expansion_Line_Thickness))
    array.push(checkMinor,time2)
    lastMinorExp := time1
    true
    confirm

    operateLiquidity(hi_price,lo_price,Time)=>
    result = false
    if(array.size(majorBoxLines)>0 and array.size(majorBoxLineRef)>0 and array.size(Crossed)>0)
    z = array.size(majorBoxLines)-1
    for x = 0 to z
    line_price = line.get_y2(array.get(majorBoxLines,x))
    hi_pos = getHighOffset(array.get(majorBoxLineRef,x))
    lo_pos = getLowOffset(array.get(majorBoxLineRef,x))
    qq = 0.0
    if(array.get(majorBoxLineType,x)==0 and lo_price <= line_price)
    if not array.get(Crossed,x)
    result := true
    qq := high[hi_pos]
    if x == z
    array.set(majorBoxLines,x,line.new(time[hi_pos],qq,Time,qq,xloc.bar_time,extend.none,Sell_Line_Color,(Sell_Line_Style==”Solid”?line.style_solid:
    Sell_Line_Style==”Dotted”?line.style_dotted:line.style_dashed),Sell_Line_Thickness))
    array.set(majorBoxLineType,x,1)
    else
    array.set(Crossed,x,true)
    else if(array.get(majorBoxLineType,x)==1 and hi_price >= line_price)
    if not array.get(Crossed,x)
    result := true
    qq := low[lo_pos]
    if x == z
    array.set(majorBoxLines,x,line.new(time[lo_pos],qq,Time,qq,xloc.bar_time,extend.none,Buy_Line_Color,(Buy_Line_Style==”Solid”?line.style_solid:
    Buy_Line_Style==”Dotted”?line.style_dotted:line.style_dashed),Buy_Line_Thickness))
    array.set(majorBoxLineType,x,0)
    else
    array.set(Crossed,x,true)
    if not array.get(Crossed,x)
    line.set_x2(array.get(majorBoxLines,x),Time)
    result

    major_line_confirm = operateMinorBox(close,high,low,time)
    major_line_cross = checkCross(expansionLines,close)
    liquidity_line_touch = operateLiquidity(high,low,time)

    if alert_major_line_confirm and major_line_confirm
    alert(“Major Line Confirmed.”)
    if alert_major_line_cross and major_line_cross
    alert(“Major Line Crossed.”)
    if alert_liquidity_line_touch and liquidity_line_touch
    alert(“Liquidity Line Touched.”)

    #252974 quote
    robertogozzi
    Moderator
    Master

    Please do NOT append different requests to existing topics, start a new one, instead.

    Thanks 🙂

    I just created it.

    #253151 quote
    yas
    Participant
    Junior

    Hi everyone just wondering when this will be converted to pro real time please

    #253213 quote
    Iván González
    Moderator
    Master

    Please be patient. I’m working on it.

    #253220 quote
    LaMaille
    Participant
    Junior

    Translated with IA

    I have not tried to read/understand the code at all : so try it and tell me if it’s behave the same for you…

    // === Master Pattern (ProBuilder) — transparence via COLOURED(...,alpha) / BORDERCOLOR(...,alpha) ===
    
    DEFPARAM DrawOnLastBarOnly = False
    
    // ----- Paramètres -----
    MaxBars = 500
    Depth = 3
    Deviation = 1
    Backstep = 1
    ShowMinorBoxes = 1
    ShowMinorExpansion = 1
    
    // Couleurs (RGB)
    MajBoxR = 81
    MajBoxG = 55
    MajBoxB = 226
    MinBoxR = 163
    MinBoxG = 160
    MinBoxB = 160
    ExpR = 238
    ExpG = 238
    ExpB = 238
    SellR = 255
    SellG = 0
    SellB = 0
    BuyR = 0
    BuyG = 170
    BuyB = 0
    
    // Transparence (0 = opaque, valeur plus grande = plus transparent)
    MinBoxAlpha = 100
    MajBoxAlpha = 60
    
    // ----- Init (une seule fois) -----
    once zz1 = 0.0
    once yy1 = 0
    once zz2 = 0.0
    once yy2 = 0
    once zz3 = 0.0
    once yy3 = 0
    once zz4 = 0.0
    once yy4 = 0
    once lastHighPrice = 0.0
    once lastHighIndex = 0
    once lastLowPrice = 0.0
    once lastLowIndex = 0
    once boxActive = 0
    once boxTop = 0.0
    once boxBot = 0.0
    once boxLeft = 0
    once boxRight = 0
    once crossHigh = 0
    once crossLow = 0
    once expActive = 0
    once expStart = 0
    once expPrice = 0.0
    once liqActive = 0
    once liqType = 0
    once liqPrice = 0.0
    once liqLeft = 0
    once LiqSide = 0
    
    // ----- Sorties (barre à barre) -----
    MajorConfirm = 0
    MajorCross = 0
    LiqTouch = 0
    
    // ----- Fractal centré (pivot confirmé) -----
    Per = 2*Depth + 1
    condPH = 0
    condPL = 0
    if barindex > Per then
    if high[Depth] = highest[Per](high)[Depth] then
    condPH = 1
    endif
    if low[Depth] = lowest[Per](low)[Depth] then
    condPL = 1
    endif
    if condPH = 1 then
    swingPrice = high[Depth]
    swingIndex = barindex - Depth
    lastHighPrice = swingPrice
    lastHighIndex = swingIndex
    zz4 = zz3
    yy4 = yy3
    zz3 = zz2
    yy3 = yy2
    zz2 = zz1
    yy2 = yy1
    zz1 = swingPrice
    yy1 = swingIndex
    endif
    if condPL = 1 then
    swingPrice = low[Depth]
    swingIndex = barindex - Depth
    lastLowPrice = swingPrice
    lastLowIndex = swingIndex
    zz4 = zz3
    yy4 = yy3
    zz3 = zz2
    yy3 = yy2
    zz2 = zz1
    yy2 = yy1
    zz1 = swingPrice
    yy1 = swingIndex
    endif
    endif
    
    // ----- Déclencheur motif (4 swings) -----
    res = 0
    val1 = zz1
    val2 = zz2
    val3 = zz3
    val4 = zz4
    pos2 = yy2
    if val4 <> 0 and pos2 > 0 then
    if val1 < val2 and val1 > val3 and val4 > val2 then
    res = 1
    endif
    if val1 > val2 and val1 < val3 and val4 < val2 then
    res = 1
    endif
    endif
    
    // ----- Boîte : création/MAJ (DRAWRECTANGLE) -----
    if res = 1 and barindex - pos2 <= MaxBars then
    boxTop = max(val1,val2)
    boxBot = min(val1,val2)
    boxLeft = pos2
    boxRight = barindex
    boxActive = 1
    crossHigh = 0
    crossLow = 0
    MajorConfirm = 0
    endif
    
    if boxActive = 1 then
    boxRight = barindex
    if ShowMinorBoxes = 1 then
    DRAWRECTANGLE(boxLeft, boxTop, boxRight, boxBot) COLOURED(MinBoxR,MinBoxG,MinBoxB,MinBoxAlpha) BORDERCOLOR(MinBoxR,MinBoxG,MinBoxB,MinBoxAlpha) STYLE(DOTTEDLINE,1)
    endif
    if high > boxTop then
    crossHigh = 1
    endif
    if low < boxBot then
    crossLow = 1
    endif
    endif
    
    // ----- Confirmation majeure : deux bords touchés -----
    if boxActive = 1 and crossHigh = 1 and crossLow = 1 then
    mid = (boxTop + boxBot) / 2
    expPrice = mid
    expStart = boxRight
    expActive = 1
    MajorConfirm = 1
    DRAWRECTANGLE(boxLeft, boxTop, boxRight, boxBot) COLOURED(MajBoxR,MajBoxG,MajBoxB,MajBoxAlpha) BORDERCOLOR(MajBoxR,MajBoxG,MajBoxB,MajBoxAlpha) STYLE(LINE,2)
    initSell = 0
    if crossHigh = 0 then
    initSell = 1
    endif
    if initSell = 1 then
    liqType = 1
    liqPrice = lastHighPrice
    liqLeft = lastHighIndex
    LiqSide = 1
    else
    liqType = 0
    liqPrice = lastLowPrice
    liqLeft = lastLowIndex
    LiqSide = -1
    endif
    liqActive = 1
    boxActive = 0
    endif
    
    // ----- Ligne d’expansion (milieu) -----
    if expActive = 1 then
    if ShowMinorExpansion = 1 then
    DRAWSEGMENT(expStart, expPrice, barindex, expPrice) COLOURED(ExpR,ExpG,ExpB) STYLE(LINE,2)
    endif
    if close > expPrice and close[1] <= expPrice then
    MajorCross = 1
    endif
    if close < expPrice and close[1] >= expPrice then
    MajorCross = 1
    endif
    endif
    
    // ----- Lignes de liquidité (toggle au toucher) -----
    if liqActive = 1 then
    if liqType = 1 then
    DRAWSEGMENT(liqLeft, liqPrice, barindex, liqPrice) COLOURED(SellR,SellG,SellB) STYLE(DOTTEDLINE,1)
    endif
    if liqType = 0 then
    DRAWSEGMENT(liqLeft, liqPrice, barindex, liqPrice) COLOURED(BuyR,BuyG,BuyB) STYLE(DOTTEDLINE,1)
    endif
    if liqType = 1 and high >= liqPrice then
    LiqTouch = 1
    endif
    if liqType = 0 and low <= liqPrice then
    LiqTouch = 1
    endif
    if LiqTouch = 1 then
    if liqType = 1 then
    liqType = 0
    liqPrice = lastLowPrice
    liqLeft = lastLowIndex
    LiqSide = -1
    else
    liqType = 1
    liqPrice = lastHighPrice
    liqLeft = lastHighIndex
    LiqSide = 1
    endif
    endif
    endif
    
    // ----- RETURN (obligatoire) -----
    RETURN  MajorConfirm COLOURED(MajBoxR,MajBoxG,MajBoxB) STYLE(HISTOGRAM,2) AS "MajorConfirm", MajorCross COLOURED(ExpR,ExpG,ExpB) STYLE(POINT,2)      AS "MajorCross", LiqTouch COLOURED(255,0,0) STYLE(HISTOGRAM,2) AS "LiqTouch", LiqSide STYLE(LINE,1) AS "LiqSide"
    robertogozzi and Iván González thanked this post
    #253295 quote
    yas
    Participant
    Junior

    Thanks Ivan looking forward to it

    #253296 quote
    yas
    Participant
    Junior
    • Hi thanks for the effort lamaille
    #253493 quote
    yas
    Participant
    Junior

    hi ivan

    Sorry to ask you again just wondering any update on the master pattern conversion looking forward to that

    thanks for your help in that

    #253494 quote
    Iván González
    Moderator
    Master

    Hi. This is what I have:

    // MASTER PATTERN INDICATOR
    
    //--- Configuración de Entradas ---
    indiType = 1 // 1 o 2
    Depth = 3
    Deviation = 1
    Backstep = 1
    
    //--- Colores
    MajorBoxColorR = 81
    MajorBoxColorG = 55
    MajorBoxColorB = 226
    MinorBoxColorR = 163
    MinorBoxColorG = 160
    MinorBoxColorB = 160
    MajorExpansionLineColorR = 238
    MajorExpansionLineColorG = 238
    MajorExpansionLineColorB = 238
    
    // (Nuevas entradas)
    SellLineColorR = 255
    SellLineColorG = 0
    SellLineColorB = 0
    BuyLineColorR = 0
    BuyLineColorG = 255
    BuyLineColorB = 0
    
    IF indiType = 2 THEN
    Depth = 2
    ENDIF
    
    //--- Lógica del Detector de Pivotes (ZigZag) ---
    
    ONCE hg = 1
    ONCE lw = 1
    ONCE llCounter = 0
    ONCE lhCounter = 0
    ONCE downCounter = 0
    ONCE p = 0
    ONCE b = 0
    ONCE l = 0
    
    IF barindex > Depth + 1 THEN
    
    pLw = lowestbars[Depth]
    pHg = highestbars[Depth]
    
    lowing = (lw[1] = pLw) OR (low - low[pLw] > Deviation * TickSize)
    highing = (hg[1] = pHg) OR (high[pHg] - high > Deviation * TickSize)
    
    IF NOT lowing[1] THEN
    llCounter = 0
    ELSE
    llCounter = llCounter + 1
    ENDIF
    ll = llCounter
    
    IF NOT highing[1] THEN
    lhCounter = 0
    ELSE
    lhCounter = lhCounter + 1
    ENDIF
    lh = lhCounter
    
    IF NOT (lh > ll) THEN
    downCounter = 0
    ELSE
    downCounter = downCounter + 1
    ENDIF
    down = (downCounter >= Backstep)
    
    lower = (low[lw[1]] > low[pLw])
    higher = (high[hg[1]] < high[pHg])
    
    myLw = lw[1]
    myHg = hg[1]
    
    IF myLw <> pLw AND (NOT down[1] OR lower) THEN
    
    IF pLw > myHg THEN
    myLw = pLw
    ELSE
    myLw = 0
    ENDIF
    ENDIF
    
    IF myHg <> pHg AND (down[1] OR higher) THEN
    
    IF pHg > myLw THEN
    myHg = pHg
    ELSE
    myHg = 0
    ENDIF
    ENDIF
    
    lw = myLw
    hg = myHg
    
    x1 = 0
    y1 = 0
    
    IF down THEN
    x1 = lw
    y1 = low[x1] 
    ELSE
    x1 = hg
    y1 = high[x1] 
    ENDIF
    
    //--- PASO 1 y 2: Almacenamiento de Pivotes y Cajas ---
    IF down <> down[1] THEN
    $pivotPrice[p] = y1[1]
    $pivotIndex[p] = barindex[1] - x1[1]
    IF down[1] THEN
    $pivotType[p] = -1
    ELSE
    $pivotType[p] = 1
    ENDIF
    p = p + 1
            
    IF p >= 4 THEN
    i = p - 1
    value1 = $pivotPrice[i]
    value2 = $pivotPrice[i-1]
    value3 = $pivotPrice[i-2]
    value4 = $pivotPrice[i-3]
    pos = $pivotIndex[i-1]
    cond1 = (value1 < value2 AND value1 > value3 AND value4 > value2)
    cond2 = (value1 > value2 AND value1 < value3 AND value4 < value2)
                
    IF (cond1 OR cond2) THEN
    $boxTop[b] = max(value1, value2)
    $boxBottom[b] = min(value1, value2)
    $boxLeftIndex[b] = pos
    $boxRightIndex[b] = $pivotIndex[i]
    $boxCrossedHigh[b] = 0
    $boxCrossedLow[b] = 0
    $boxIsConfirmed[b] = 0
    $boxFixedRightIndex[b] = $pivotIndex[i]
    $boxConfirmIndex[b] = $pivotIndex[i]
    $boxExpandidx[b] =  $pivotIndex[i]
    $CrossNumber[b]= 0
    b = b + 1
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    //--- Lógica de Dibujo y ESTADO (Sólo en la última barra) ---
    IF islastbarupdate THEN
    
    // 1. Dibujar Pivotes
    IF p > 0 THEN
    lastIdx = $pivotIndex[p-1]
    lastPrice = $pivotPrice[p-1]
    DRAWSEGMENT(lastIdx, lastPrice, barindex - x1, y1) COLOURED(200, 200, 200) STYLE(dottedline)
    FOR i = 0 TO p - 1 DO
    IF $pivotType[i] = 1 THEN
    DRAWPOINT($pivotIndex[i], $pivotPrice[i], 1) COLOURED(0, 255, 0)
    ELSE
    DRAWPOINT($pivotIndex[i], $pivotPrice[i], 1) COLOURED(255, 0, 0)
    ENDIF
    NEXT
    ENDIF
        
    // 2. Dibujar y Gestionar Cajas
    IF b > 0 THEN
    FOR i = 0 TO b - 1 DO
                
    
    IF $boxCrossedHigh[i] = 0 AND $boxCrossedLow[i] = 0 THEN
    
    distancia = barindex - $boxRightIndex[i]
    FOR j = distancia DOWNTO 0 DO
    currentBarIndex = barindex - j
    IF high[j] > $boxTop[i] THEN
    $boxCrossedHigh[i] = 1
    $boxFixedRightIndex[i] = currentBarIndex
    $CrossNumber[i]=1
    BREAK
    ELSIF low[j] < $boxBottom[i] THEN
    $boxCrossedLow[i] = 1
    $boxFixedRightIndex[i] = currentBarIndex
    $CrossNumber[i]=1
    BREAK
    ENDIF
    NEXT
    endif
    
    IF $CrossNumber[i]=1 and $boxCrossedHigh[i] = 1 AND $boxCrossedLow[i] = 0 THEN
    
    distancia = barindex - $boxFixedRightIndex[i]
    FOR j = distancia DOWNTO 0 DO
    currentBarIndex = barindex - j
    IF low[j] < $boxBottom[i] THEN
    $boxCrossedLow[i] = 1
    $boxConfirmIndex[i] = currentBarIndex
    $boxIsConfirmed[i] = 1
    $CrossNumber[i]=2
    $boxExpandidx[i] =  currentBarIndex+1
    BREAK
    ENDIF
    NEXT
    endif
    
    IF $CrossNumber[i]=1 and $boxCrossedLow[i] = 1 AND $boxCrossedHigh[i] = 0 THEN
    
    distancia = barindex - $boxFixedRightIndex[i]
    FOR j = distancia DOWNTO 0 DO
    currentBarIndex = barindex - j
    IF high[j] > $boxTop[i] THEN
    $boxCrossedHigh[i] = 1
    $boxConfirmIndex[i] = currentBarIndex
    $boxIsConfirmed[i] = 1
    $CrossNumber[i]=2
    $boxExpandidx[i] =  currentBarIndex
    BREAK
    ENDIF
    NEXT
    ENDIF
    
    if $CrossNumber[i]=1 then
    DRAWRECTANGLE($boxLeftIndex[i], $boxBottom[i], $boxFixedRightIndex[i], $boxTop[i]) COLOURED("blue")style(line,2)fillcolor("blue",35)
    DRAWRECTANGLE($boxFixedRightIndex[i], $boxBottom[i], barindex, $boxTop[i]) COLOURED("fuchsia",45)style(dottedline,2)
    elsif $CrossNumber[i]=2 then
    DRAWRECTANGLE($boxLeftIndex[i], $boxBottom[i], $boxFixedRightIndex[i], $boxTop[i]) COLOURED("blue")style(line,2)fillcolor("blue",35)
    DRAWRECTANGLE($boxFixedRightIndex[i], $boxBottom[i], $boxConfirmIndex[i], $boxTop[i]) COLOURED("fuchsia",45)style(dottedline,2)
    endif
    NEXT
    ENDIF
        
    ENDIF
    
    RETURN
    
    #253497 quote
    yas
    Participant
    Junior

    Thanks mate

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Master Pattern Indicator conversion


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
yas @yas Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by yas
2 months, 4 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/23/2025
Status: Active
Attachments: No files
Logo Logo
Loading...