ABCD pattern using arrays – help needed please

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #191229 quote
    JMat45
    Participant
    Senior

    Hi there,

    I’ve been trying to find an open source ABCD pattern indicator on here for some time. I know Roberto has done an excellent job with the following indicator:

    https://www.prorealcode.com/prorealtime-indicators/abcd-pattern-indicator

    but I thought there must be a neater way of doing it utilising the new array functionality. Plus if you look at the first 35 mins price action today on the DAX after the market open at 8.00am (BST), whatever you set the parameter LMinBars to, it doesn’t seem to capture the ‘major’ 100% ABCD between 0812 and 0828 (in blue). It is valid as the retracement is just over 38.2% as per the text on the chart. I know Roberto’s indicator isn’t designed to capture ABCD extensions, but it would be great if an ABCD indicator could also capture the 127.2% extension in red. The attached picture shows those ABCDs marked on the chart plus Roberto’s outstanding indicator with LMinBars set to 2. I have coloured it orange to make it more visible.

    [attachment file=”191230″]

    So I had a go myself, using Nicolas’s array-based double top/bottom code as a template (https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/page/2/#post-120721), but struggled – kept getting infinite loop errors.

    This is my attempt for what it’s worth:

    // https://www.prorealcode.com/TOPic/array-variables-availability-in-prorealtime/
    // (please do not remove the link above for future reference)
    // Example #6: flat base triangle or double TOP/bottom
    defparam drawonlastbaronly=true
     
    // --- settings
    fractalP = 10 // fractal period
    barlimit = 100 // maximum no. of bars between points B and D of ABCD pattern
    // --- end of settings
     
    //fractals
    cp = fractalP
    if high[cp] >= highest[(cp)*2+1](high) then //new fractal high found
    $TOPy[lastset($TOPy)+1] = high[cp] //store fractal value
    $TOPx[lastset($TOPx)+1] = barindex[cp] //store fractal barindex
    endif
     
    // if low[cp] <= lowest[(cp)*2+1](low)  then //new fractal low found
    // $BOTy[lastset($BOTy)+1] = low[cp] //store fractal value
    // $BOTx[lastset($BOTx)+1] = barindex[cp] //stire fractal barindex
    // endif
     
    if(islastbarupdate and isset($TOPy[0])) then                                      // and isset($boty[0])
    //check points in a range of X percent
    for i = 0 to lastset($TOPy) do //loop through the tops
    for y = 0 to lastset($TOPy) do //check first top with other tops
    change = abs(($TOPy[y]-$TOPy[i])/$TOPy[i]) //percent delta between the 2 tops
    bardiff = abs($TOPx[i]-$TOPx[y]) //how many bars between the 2 points?
    if change >= percent/100 and bardiff >= fractalP and bardiff < barlimit and $TOPx[i] <> $TOPx[y] then
    PointDLevel = max($TOPy[i],$TOPy[y])
    PointDIndex = max($TOPx[i],$TOPx[y])
    PointBLevel = min($TOPy[i],$TOPy[y])
    PointBIndex = min($TOPx[i],$TOPx[y])
    
    PointCLevel = lowest[bardiff](low)[barindex-PointDIndex]
    PointCIndex = 0
    for a = 0 to bardiff do
    if low[a+(barindex-PointDIndex)] = PointCLevel then
    PointCIndex = PointDIndex-a
    break
    endif
    next
    bardiffPointCtoD = PointDIndex-PointCIndex
    
    PointALevel = 0
    PointAIndex = 0
    for b = -barsmarginerror to barsmarginerror do
    if low[(barindex-PointBIndex)+bardiffPointCtoD+b] = lowest[bardiffPointCtoD+b+cp](low)[barindex-PointBIndex] then
    PointALevel = low[(barindex-PointBIndex)+bardiffPointCtoD+b]
    PointAIndex = PointBIndex-bardiffPointCtoD-b
    break
    endif
    next
    
    if (PointBLevel-PointCLevel) >= (Fibthreshold1*(PointBLevel-PointALevel)) and (PointBLevel-PointCLevel) >= (Fibthreshold2*(PointBLevel-PointALevel)) then
    ABCD = 1
    DRAWSEGMENT(PointCIndex,PointCLevel,PointDIndex,PointDLevel)coloured(255,10,10) style(line)
    DRAWSEGMENT(PointBIndex,PointBLevel,PointCIndex,PointCLevel)coloured(255,10,10) style(line)
    DRAWSEGMENT(PointAIndex,PointALevel,PointBIndex,PointBLevel)coloured(255,10,10) style(line)
    else
    ABCD = 0
    endif
    endif
    next
    next
    endif
     
    return ABCD COLOURED(0, 255, 0) STYLE(histogram) as "Bearish ABCD"
    

    The only version that gets close to resembling what I’m looking for is this:

    // https://www.prorealcode.com/TOPic/array-variables-availability-in-prorealtime/
    // (please do not remove the link above for future reference)
    // Example #6: flat base triangle or double TOP/bottom
    
    defparam calculateonlastbars=500
    // defparam drawonlastbaronly=false
     
    // --- settings
    fractalP = 10 // fractal period
    barlimit = 100 // maximum no. of bars between points B and D of ABCD pattern
    // --- end of settings
     
    //fractals
    cp = fractalP
    if high[cp] >= highest[(cp)*2+1](high) then //new fractal high found
    $TOPy[lastset($TOPy)+1] = high[cp] //store fractal value
    $TOPx[lastset($TOPx)+1] = barindex[cp] //store fractal barindex
    endif
     
    // if low[cp] <= lowest[(cp)*2+1](low)  then //new fractal low found
    // $BOTy[lastset($BOTy)+1] = low[cp] //store fractal value
    // $BOTx[lastset($BOTx)+1] = barindex[cp] //stire fractal barindex
    // endif
     
    if(islastbarupdate and isset($TOPy[0])) then                     // and isset($boty[0])
    //check points in a range of X percent
    for i = 0 to lastset($TOPy) do //loop through the TOPs
    for y = 0 to lastset($TOPy) do //check first TOP with other TOPs
    change = abs(($TOPy[y]-$TOPy[i])/$TOPy[i]) //percent range between the 2 TOPs
    bardiff = abs($TOPx[i]-$TOPx[y]) //how many bars between the 2 points?
    if change >= percent/100 and bardiff >= fractalP and bardiff < barlimit and $TOPx[i] <> $TOPx[y] then
    PointDLevel = max($TOPy[i],$TOPy[y])
    PointDIndex = max($TOPx[i],$TOPx[y])
    PointBLevel = min($TOPy[i],$TOPy[y])
    PointBIndex = min($TOPx[i],$TOPx[y])
    
    PointCLevel = lowest[bardiff](low)[barindex-PointDIndex]
    PointCIndex = 0
    for a = 0 to bardiff do
    if low[a+(barindex-PointDIndex)] = PointCLevel then
    PointCIndex = PointDIndex-a
    break
    endif
    next
    bardiffPointCtoD = PointDIndex-PointCIndex
    
    // PointALevel = 0
    // PointAIndex = 0
    // for b = -barsmarginerror to barsmarginerror do
    // if low[(barindex-PointBIndex)+bardiffPointCtoD+b] = lowest[bardiffPointCtoD+b+cp](low)[barindex-PointBIndex] then
    // PointALevel = low[(barindex-PointBIndex)+bardiffPointCtoD+b]
    // PointAIndex = PointBIndex-bardiffPointCtoD-b
    // break
    // endif
    // next
    
    // if (PointBLevel-PointCLevel) >= (Fibthreshold1*(PointBLevel-PointALevel)) and (PointBLevel-PointCLevel) >= (Fibthreshold2*(PointBLevel-PointALevel)) then
    // ABCD = 1
    // DRAWSEGMENT($TOPx[i],$TOPy[i],$TOPx[y],$TOPy[y])coloured(255,10,10) style(line,3)
    DRAWSEGMENT(PointCIndex,PointCLevel,PointDIndex,PointDLevel)coloured(255,10,10) style(line,3)
    DRAWSEGMENT(PointBIndex,PointBLevel,PointCIndex,PointCLevel)coloured(10,10,255) style(line,3)
    // DRAWSEGMENT(PointAIndex,PointALevel,PointBIndex,PointBLevel)coloured(0,255,0) style(line,3)
    // else
    // ABCD = 0
    // endif
    endif
    next
    next
    endif
     
    return
    

    but then take a look at this….

    [attachment file=”191231″]

    Oops…

    I suspect one has to use zig zags as opposed to pivots in arrays – at least that’s what harmonic indicators on other platforms seem to use. Anyway, I’m at the limit of my coding ability here, but I’ve tried not to cause annoyance by simply coming on here and asking straight up if someone can just do it for me…

    I know there is a harmonic collection available on the Marketplace courtesy of Ale, but I’m not ready to spend EUR200+ without a trial first. Plus I’m only really looking for ABCDs – I can dispense with the other patterns for now. Surely ABCDs can be made available open source…?

    Thanks in advance for your help,

    JM

    y97843978.jpg y97843978.jpg y7079008943.jpg y7079008943.jpg
    #191294 quote
    robertogozzi
    Moderator
    Master

    Arrays make it easier to store multiple  patterns to be plotted, but they do not provide any help in coding the pattern.

    When I wrote it, it took me so long that I swore to myself that I wouldn’t approach harmonic patterns any more!

    JMat45 thanked this post
    #191309 quote
    JMat45
    Participant
    Senior

    OK thanks, Roberto. I wonder how Alessandro from Automatic Trading has done it…

    https://market.prorealcode.com/product/eurhythmic-patterns-v11/

    #191314 quote
    robertogozzi
    Moderator
    Master

    Apart from fancier graphics, anyone who wants to code harmonic patterns has to detect all involved points doing all required calculations, then plot it when the pattern is complete.
    Instructions are the same for everybody, what’s different is the use anyone can do of them, but here’s not much to be done differently.
    Coding harmonic patterns is not an easy task.

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

ABCD pattern using arrays – help needed please


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
JMat45 @jmat45 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
3 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/05/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...