ABC on Recursive Zigzag

Category: Indicators By: Iván González Created: July 20, 2026, 10:36 AM
July 20, 2026, 10:36 AM
Indicators
0 Comments

1. Introduction

Most pattern detectors work at a single scale. They pick one pivot lookback, find the swings it produces, and everything larger or smaller than that is invisible. The consequence is familiar: a clean ABC on the 4-hour structure goes unnoticed because the indicator is busy tracking 20-bar noise.

This indicator, adapted to ProBuilder from the “ABC on Recursive Zigzag [Trendoscope]” pinescript, takes a different route. It builds a recursive zigzag: level 0 is an ordinary zigzag, level 1 is the zigzag of level 0’s pivots, level 2 the zigzag of level 1’s, and so on. The same ABC pattern is then searched at every level simultaneously, so small and large structures are detected by one indicator on one chart, without changing a setting.

Each valid pattern projects its entry, stop and target, is tracked bar by bar until it resolves, and feeds a statistics panel that keeps score of what actually happened.

 

2. How It Works

The recursive zigzag. Level 0 marks a pivot whenever the current bar holds the highest high or lowest low of the last zigzagLength bars. Each higher level is then distilled from the one below it: a pivot survives to the next level only if it is an extreme within its own series, meaning a high must exceed both the previous high and the following high. Consecutive pivots of the same type are collapsed onto the most extreme one, so every level comes out properly alternating.

Pivot classification. Every pivot carries a direction flag that says whether it extended the structure or merely retraced it. A high that exceeds the previous high is a supersession (higher high); a high that fails to is a retracement (lower high). Lows work in mirror. This classification is recomputed at each level, because a pivot can be a higher high on the base zigzag and not on the level above it.

Pattern validation. At each level the last three pivots are read as A, B and C. The pattern is accepted when leg BC retraces between 61.8% and 78.6% of leg AB. An optional filter then restricts which combinations of pivot types are allowed:

  • any – no filter
  • trend – A retraced, B superseded
  • reverse – A superseded, B retraced
  • contracting – both A and B retraced
  • expanding – both A and B superseded

Trade levels. From point C the indicator projects three levels, using either the ABC extension (the AB impulse) or the BC retracement as the base:

Level(ratio) = C + span x ratio

with span = B - A for the extension mode and span = B - C for the retracement mode. Entry, target and stop each have their own ratio, and a logarithmic mode is available for instruments where proportional moves matter more than absolute ones.

Tracking. A pattern starts as pending. It becomes entered when price reaches the entry level and complete when it reaches the target. It closes as invalid if price breaks the stop before entering, or as stopped if it breaks the stop after entering. Every closed pattern is added to the statistics panel.

 

3. Reading the Indicator

  • Solid A-B and B-C lines: the impulse and its retracement, in green for bullish setups and red for bearish.
  • Dotted A-C line: the guide connecting the outer points of the structure.
  • Number at the middle of A-C: the measured BC/AB retracement ratio.
  • Red box: the risk area, from entry down to stop.
  • Green box: the reward area, from entry up to target.
  • Grey dotted structures: patterns that have already resolved, kept on the chart as context so the recent history stays readable.
  • Top-right panel: invalidated, stopped and completed counts for each direction, plus the win ratio and the theoretical risk-reward of the current settings.

4. Trading Applications

  • Multi-scale confluence: when patterns from two different levels point the same way in the same area, the structure is agreeing with itself across scales.
  • Ready-made invalidation: the stop level is part of the pattern definition, not an afterthought. A setup that breaks it is removed rather than left on the chart to be rationalised later.
  • Setting comparison: the panel makes it easy to see how the entry, target and stop ratios trade off against each other. A tighter entry fills more often but leaves less room; the win ratio and R:R columns show both sides of that trade at once.
  • Condition filtering: the trend and reverse modes separate continuation setups from counter-trend ones, which behave very differently on most instruments.

5. Parameters

  • zigzagLength (default 13): lookback for the base zigzag. Larger values give fewer and bigger swings.
  • maxLevel (default 3): how many recursive levels to scan. In practice the useful ceiling is set by maxPivots, not by this value.
  • minLevel (default 0): skip the smallest levels by raising this.
  • maxPivots (default 120): how many base pivots feed the scan. This is the real performance lever, and also what limits how many levels can form.
  • baseMode (default 1): 1 = ABC extension, 2 = BC retracement.
  • entryRatio / targetRatio / stopRatio (0.3 / 1.0 / 0.0): the three projected levels. stopRatio should stay at or below zero.
  • useLogScale (default 0): compute the projections on a logarithmic scale.
  • tradeCondition (default 0): 0 any, 1 trend, 2 reverse, 3 contracting, 4 expanding.
  • useCloseEntry / useCloseTarget / useCloseStop: track with closing prices instead of intrabar extremes.
  • maxPatterns (default 10): how many patterns stay active at once.
  • showClosed / maxClosed (1 / 6): keep the last resolved patterns on the chart in grey.
  • showZigzag / showBoxes / showStats: toggle the base zigzag, the risk-reward boxes and the panel.

6. A Note on Repainting

The underlying zigzag does not wait for confirmation: a pivot is marked as soon as the current bar holds the extreme of its window, which means the most recent pivot can still move while its bar is forming. This is by design in the original and it is preserved here, but it has a practical consequence worth stating plainly: the newest pattern on the chart is provisional until the swing that defines it is complete. Completed patterns and the statistics panel are unaffected, as they only count structures that have already resolved.

The panel is a running tally over the loaded history, not a backtest. It ignores costs, slippage and the fact that several patterns can overlap. Use it to compare settings against each other, not to validate a strategy.

 

7. ABC on Recursive Zigzag Code

//-----------------------------------------------------------//
//PRC_ABC on Recursive Zigzag (by Trendoscope)
//version = 0
//20.07.26
//Ivan Gonzalez @ www.prorealcode.com
//Sharing ProRealTime knowledge
//-----------------------------------------------------------//
// Detecta patrones ABC sobre un zigzag recursivo multinivel.
// C debe retroceder entre el 61.8% y el 78.6% de la pata AB.
// Proyecta entrada / stop / objetivo y sigue el estado de cada
// patron hasta su cierre, con panel de estadisticas.
//-----------------------------------------------------------//
defparam drawonlastbaronly = true
//-----Inputs (parametros configurables)---------------------//
zigzagLength = 13     //Longitud del zigzag de nivel 0
maxLevel = 3          //Nivel maximo de zigzag recursivo (0 = solo base)
minLevel = 0          //Nivel minimo a escanear
maxPivots = 120       //Pivotes de nivel 0 usados en el escaneo

baseMode = 1          //1 = ABC Extension, 2 = BC Retracement
entryRatio = 0.3      //Ratio de entrada
targetRatio = 1.0     //Ratio de objetivo
stopRatio = 0.0       //Ratio de stop (<= 0)
useLogScale = 0       //1 = calcular ratios en escala logaritmica

tradeCondition = 0    //0 any, 1 trend, 2 reverse, 3 contracting, 4 expanding

useCloseEntry = 1     //Usar cierre para detectar la entrada
useCloseTarget = 1    //Usar cierre para detectar el objetivo
useCloseStop = 1      //Usar cierre para detectar el stop

maxPatterns = 10      //Patrones activos simultaneos
showClosed = 0        //1 = mantener en gris los ultimos patrones cerrados
maxClosed = 6         //Cuantos patrones cerrados se conservan en pantalla
showZigzag = 0        //1 = dibujar el zigzag de nivel 0
showBoxes = 1         //1 = dibujar las cajas de riesgo/objetivo
showStats = 1         //1 = mostrar el panel de estadisticas
//-----------------------------------------------------------//
//-----Colores (RGB)-----------------------------------------//
rBull = 0             //alcista
gBull = 150
bBull = 80
rBear = 200           //bajista
gBear = 50
bBear = 50
//-----------------------------------------------------------//
//-----NIVEL 0: deteccion de pivotes-------------------------//
// ZigzagLite marca pivote cuando el extremo de la ventana cae
// en la barra actual (highestbars / lowestbars = 0).
newPivot = 0

IF barindex >= zigzagLength THEN
   hb = highestbars[zigzagLength](high)
   lb = lowestbars[zigzagLength](low)
   
   IF hb = 0 AND lb <> 0 THEN
      pvDir = 1
      pvVal = high
   ELSIF lb = 0 AND hb <> 0 THEN
      pvDir = -1
      pvVal = low
   ELSIF hb = 0 AND lb = 0 THEN
      pvDir = prevDir
      IF pvDir = 1 THEN
         pvVal = high
      ELSE
         pvVal = low
      ENDIF
   ELSE
      pvDir = 0
      pvVal = 0
   ENDIF
   
   IF pvDir <> 0 THEN
      IF pvDir = 1 THEN
         isHi = 1
      ELSE
         isHi = 0
      ENDIF
      
      // Primer pivote: sembrar sin filtro (learning 155)
      IF npv = 0 THEN
         $zI[0] = barindex
         $zP[0] = pvVal
         $zH[0] = isHi
         npv = 1
         newPivot = 1
      ELSE
         lastH = $zH[npv-1]
         IF lastH = isHi THEN
            // Misma direccion: extender el pivote vigente si mejora
            lastP = $zP[npv-1]
            IF isHi = 1 THEN
               IF pvVal > lastP THEN
                  $zI[npv-1] = barindex
                  $zP[npv-1] = pvVal
                  newPivot = 1
               ENDIF
            ELSE
               IF pvVal < lastP THEN
                  $zI[npv-1] = barindex
                  $zP[npv-1] = pvVal
                  newPivot = 1
               ENDIF
            ENDIF
         ELSE
            // Cambio de direccion: nuevo pivote
            $zI[npv] = barindex
            $zP[npv] = pvVal
            $zH[npv] = isHi
            npv = npv + 1
            newPivot = 1
         ENDIF
      ENDIF
      prevDir = pvDir
   ENDIF
ENDIF
//-----------------------------------------------------------//
//-----ESCANEO MULTINIVEL (solo cuando hay pivote nuevo)-----//
IF newPivot = 1 AND npv >= 4 THEN
   
   // Cargar la ventana de trabajo desde la capa de acumulacion
   startK = npv - maxPivots
   IF startK < 0 THEN
      startK = 0
   ENDIF
   nw = 0
   FOR k = startK TO npv - 1 DO
      $wI[nw] = $zI[k]
      $wP[nw] = $zP[k]
      $wH[nw] = $zH[k]
      nw = nw + 1
   NEXT
   
   FOR lev = 0 TO maxLevel DO
      
      IF nw >= 4 THEN
         
         // --- dir de cada pivote: +-1 retroceso, +-2 superacion ---
         FOR k = 0 TO nw - 1 DO
            IF $wH[k] = 1 THEN
               $wD[k] = 1
            ELSE
               $wD[k] = -1
            ENDIF
            IF k >= 2 THEN
               prevSame = $wP[k-2]
               IF $wH[k] = 1 THEN
                  IF $wP[k] > prevSame THEN
                     $wD[k] = 2
                  ENDIF
               ELSE
                  IF $wP[k] < prevSame THEN
                     $wD[k] = -2
                  ENDIF
               ENDIF
            ENDIF
         NEXT
         
         // --- Candidato ABC: los tres ultimos pivotes ---
         IF lev >= minLevel THEN
            cK = nw - 1
            bK = nw - 2
            aK = nw - 3
            
            pA = $wP[aK]
            pB = $wP[bK]
            pC = $wP[cK]
            iA = $wI[aK]
            iB = $wI[bK]
            iC = $wI[cK]
            
            legAB = abs(pB - pA)
            legBC = abs(pC - pB)
            abcRatio = 0
            IF legAB > 0 THEN
               abcRatio = legBC / legAB
            ENDIF
            
            // Filtro de retroceso 0.618 - 0.786
            ratioOk = 0
            IF abcRatio >= 0.618 AND abcRatio <= 0.786 THEN
               ratioOk = 1
            ENDIF
            
            // Filtro de condicion sobre |dir| de A y B
            aDir = abs($wD[aK])
            bDir = abs($wD[bK])
            condOk = 0
            IF tradeCondition = 0 THEN
               condOk = 1
            ELSIF tradeCondition = 1 AND aDir = 1 AND bDir = 2 THEN
               condOk = 1
            ELSIF tradeCondition = 2 AND aDir = 2 AND bDir = 1 THEN
               condOk = 1
            ELSIF tradeCondition = 3 AND aDir = 1 AND bDir = 1 THEN
               condOk = 1
            ELSIF tradeCondition = 4 AND aDir = 2 AND bDir = 2 THEN
               condOk = 1
            ENDIF
            
            IF ratioOk = 1 AND condOk = 1 THEN
               
               // Ya registrado? (mismo A y mismo B)
               dup = 0
               IF npt > 0 THEN
                  FOR q = 0 TO npt - 1 DO
                     IF $ptPA[q] = pA AND $ptPB[q] = pB THEN
                        dup = 1
                     ENDIF
                  NEXT
               ENDIF
               
               IF dup = 0 THEN
                  // Direccion: C por debajo de B = patron alcista
                  IF pB > pC THEN
                     pDirn = 1
                  ELSE
                     pDirn = -1
                  ENDIF
                  
                  // --- Niveles de entrada / objetivo / stop ---
                  IF useLogScale = 1 AND pA > 0 AND pB > 0 AND pC > 0 THEN
                     lA = log(pA)
                     lB = log(pB)
                     lC = log(pC)
                     IF baseMode = 1 THEN
                        spanL = lB - lA
                        eLvl = exp(lC + spanL * entryRatio)
                        tLvl = exp(lC + spanL * targetRatio)
                        sLvl = exp(lC + spanL * stopRatio)
                     ELSE
                        spanL = lB - lC
                        eLvl = exp(lC + spanL * entryRatio)
                        tLvl = exp(lC + spanL * targetRatio)
                        sLvl = exp(lC + spanL * stopRatio)
                     ENDIF
                  ELSE
                     IF baseMode = 1 THEN
                        spanP = pB - pA
                     ELSE
                        spanP = pB - pC
                     ENDIF
                     eLvl = pC + spanP * entryRatio
                     tLvl = pC + spanP * targetRatio
                     sLvl = pC + spanP * stopRatio
                  ENDIF
                  
                  // Solo se registra si el precio aun no alcanzo la entrada
                  inEntry = 0
                  IF close * pDirn < eLvl * pDirn THEN
                     inEntry = 1
                  ENDIF
                  
                  IF inEntry = 1 THEN
                     // FIFO: si esta lleno, descartar el mas antiguo
                     IF npt >= maxPatterns AND npt > 0 THEN
                        FOR q = 0 TO npt - 2 DO
                           $ptIA[q] = $ptIA[q+1]
                           $ptPA[q] = $ptPA[q+1]
                           $ptIB[q] = $ptIB[q+1]
                           $ptPB[q] = $ptPB[q+1]
                           $ptIC[q] = $ptIC[q+1]
                           $ptPC[q] = $ptPC[q+1]
                           $ptDir[q] = $ptDir[q+1]
                           $ptEn[q] = $ptEn[q+1]
                           $ptSt[q] = $ptSt[q+1]
                           $ptTg[q] = $ptTg[q+1]
                           $ptStat[q] = $ptStat[q+1]
                           $ptRt[q] = $ptRt[q+1]
                        NEXT
                        npt = npt - 1
                     ENDIF
                     
                     $ptIA[npt] = iA
                     $ptPA[npt] = pA
                     $ptIB[npt] = iB
                     $ptPB[npt] = pB
                     $ptIC[npt] = iC
                     $ptPC[npt] = pC
                     $ptDir[npt] = pDirn
                     $ptEn[npt] = eLvl
                     $ptSt[npt] = sLvl
                     $ptTg[npt] = tLvl
                     $ptStat[npt] = 0
                     $ptRt[npt] = abcRatio
                     npt = npt + 1
                  ENDIF
               ENDIF
            ENDIF
         ENDIF
         
         // --- Construir el zigzag del nivel siguiente ---
         // Se conservan los pivotes que son extremo respecto a su
         // homologo anterior y posterior; los consecutivos del mismo
         // tipo se colapsan quedandose con el mas extremo.
         IF lev < maxLevel THEN
            nv = 0
            FOR k = 0 TO nw - 1 DO
               keep = 1
               IF k < nw - 1 THEN
                  IF k >= 2 THEN
                     prevSame = $wP[k-2]
                     IF $wH[k] = 1 THEN
                        IF $wP[k] < prevSame THEN
                           keep = 0
                        ENDIF
                     ELSE
                        IF $wP[k] > prevSame THEN
                           keep = 0
                        ENDIF
                     ENDIF
                  ENDIF
                  IF k + 2 <= nw - 1 THEN
                     nextSame = $wP[k+2]
                     IF $wH[k] = 1 THEN
                        IF $wP[k] < nextSame THEN
                           keep = 0
                        ENDIF
                     ELSE
                        IF $wP[k] > nextSame THEN
                           keep = 0
                        ENDIF
                     ENDIF
                  ENDIF
               ENDIF
               
               IF keep = 1 THEN
                  doPush = 1
                  IF nv > 0 THEN
                     prevH = $vH[nv-1]
                     IF prevH = $wH[k] THEN
                        doPush = 0
                        prevP = $vP[nv-1]
                        IF $wH[k] = 1 THEN
                           IF $wP[k] > prevP THEN
                              $vP[nv-1] = $wP[k]
                              $vI[nv-1] = $wI[k]
                           ENDIF
                        ELSE
                           IF $wP[k] < prevP THEN
                              $vP[nv-1] = $wP[k]
                              $vI[nv-1] = $wI[k]
                           ENDIF
                        ENDIF
                     ENDIF
                  ENDIF
                  IF doPush = 1 THEN
                     $vI[nv] = $wI[k]
                     $vP[nv] = $wP[k]
                     $vH[nv] = $wH[k]
                     nv = nv + 1
                  ENDIF
               ENDIF
            NEXT
            
            // Volcar el nivel construido a la ventana de trabajo
            FOR k = 0 TO nv - 1 DO
               $wI[k] = $vI[k]
               $wP[k] = $vP[k]
               $wH[k] = $vH[k]
            NEXT
            nw = nv
         ENDIF
      ENDIF
   NEXT
ENDIF
//-----------------------------------------------------------//
//-----SEGUIMIENTO DE PATRONES ACTIVOS (cada barra)----------//
IF npt > 0 THEN
   nAlive = 0
   FOR k = 0 TO npt - 1 DO
      pdr = $ptDir[k]
      stt = $ptStat[k]
      
      IF useCloseTarget = 1 THEN
         vTarget = close
      ELSIF pdr > 0 THEN
         vTarget = high
      ELSE
         vTarget = low
      ENDIF
      
      IF useCloseStop = 1 THEN
         vStop = close
      ELSIF pdr > 0 THEN
         vStop = low
      ELSE
         vStop = high
      ENDIF
      
      IF useCloseEntry = 1 THEN
         vEntry = close
      ELSIF pdr > 0 THEN
         vEntry = high
      ELSE
         vEntry = low
      ENDIF
      
      // Estado: 0 pendiente, 1 entrada alcanzada, 2 objetivo alcanzado
      newStat = stt
      IF vEntry * pdr >= $ptEn[k] * pdr THEN
         newStat = 1
      ENDIF
      IF vTarget * pdr >= $ptTg[k] * pdr THEN
         newStat = 2
      ENDIF
      IF newStat < stt THEN
         newStat = stt
      ENDIF
      
      // Cierre: stop tocado tras entrar, invalidacion antes de entrar,
      // u objetivo ya alcanzado
      closed = 0
      IF newStat > 0 AND vStop * pdr <= $ptSt[k] * pdr THEN
         closed = 1
      ENDIF
      IF newStat = 0 AND close * pdr <= $ptSt[k] * pdr THEN
         closed = 1
      ENDIF
      IF stt = 2 THEN
         closed = 1
      ENDIF
      
      $ptStat[k] = newStat
      
      IF closed = 1 THEN
         // Conservar el patron cerrado para seguir mostrandolo en gris.
         // No altera deteccion ni estadisticas: solo evita que el grafico
         // quede vacio cuando no hay ningun patron activo.
         IF showClosed = 1 AND maxClosed > 0 THEN
            IF nhs >= maxClosed THEN
               FOR q = 0 TO nhs - 2 DO
                  $hsIA[q] = $hsIA[q+1]
                  $hsPA[q] = $hsPA[q+1]
                  $hsIB[q] = $hsIB[q+1]
                  $hsPB[q] = $hsPB[q+1]
                  $hsIC[q] = $hsIC[q+1]
                  $hsPC[q] = $hsPC[q+1]
                  $hsRt[q] = $hsRt[q+1]
               NEXT
               nhs = nhs - 1
            ENDIF
            $hsIA[nhs] = $ptIA[k]
            $hsPA[nhs] = $ptPA[k]
            $hsIB[nhs] = $ptIB[k]
            $hsPB[nhs] = $ptPB[k]
            $hsIC[nhs] = $ptIC[k]
            $hsPC[nhs] = $ptPC[k]
            $hsRt[nhs] = $ptRt[k]
            nhs = nhs + 1
         ENDIF
         
         // Registrar en el contador correspondiente
         IF pdr > 0 THEN
            IF newStat = 0 THEN
               bullInvalid = bullInvalid + 1
            ELSIF newStat = 1 THEN
               bullStopped = bullStopped + 1
            ELSE
               bullDone = bullDone + 1
            ENDIF
         ELSE
            IF newStat = 0 THEN
               bearInvalid = bearInvalid + 1
            ELSIF newStat = 1 THEN
               bearStopped = bearStopped + 1
            ELSE
               bearDone = bearDone + 1
            ENDIF
         ENDIF
      ELSE
         // Compactar: los vivos se reubican al principio del array
         $ptIA[nAlive] = $ptIA[k]
         $ptPA[nAlive] = $ptPA[k]
         $ptIB[nAlive] = $ptIB[k]
         $ptPB[nAlive] = $ptPB[k]
         $ptIC[nAlive] = $ptIC[k]
         $ptPC[nAlive] = $ptPC[k]
         $ptDir[nAlive] = $ptDir[k]
         $ptEn[nAlive] = $ptEn[k]
         $ptSt[nAlive] = $ptSt[k]
         $ptTg[nAlive] = $ptTg[k]
         $ptStat[nAlive] = $ptStat[k]
         $ptRt[nAlive] = $ptRt[k]
         nAlive = nAlive + 1
      ENDIF
   NEXT
   npt = nAlive
ENDIF
//-----------------------------------------------------------//
//-----DIBUJO (solo en la ultima barra)----------------------//
IF islastbarupdate THEN
   
   atrv = averagetruerange[14]
   
   // --- Zigzag de nivel 0 ---
   IF showZigzag = 1 AND npv >= 2 THEN
      firstK = npv - 30
      IF firstK < 1 THEN
         firstK = 1
      ENDIF
      FOR k = firstK TO npv - 1 DO
         drawsegment($zI[k-1], $zP[k-1], $zI[k], $zP[k]) coloured(130, 130, 130) style(dottedline, 1)
      NEXT
   ENDIF
   
   // --- Patrones ya cerrados (contexto historico, en gris) ---
   IF showClosed = 1 AND nhs > 0 THEN
      FOR k = 0 TO nhs - 1 DO
         drawsegment($hsIA[k], $hsPA[k], $hsIB[k], $hsPB[k]) coloured(150, 150, 150) style(dottedline, 1)
         drawsegment($hsIB[k], $hsPB[k], $hsIC[k], $hsPC[k]) coloured(150, 150, 150) style(dottedline, 1)
         drawtext("A", $hsIA[k], $hsPA[k]) coloured(150, 150, 150)
         drawtext("B", $hsIB[k], $hsPB[k]) coloured(150, 150, 150)
         drawtext("C", $hsIC[k], $hsPC[k]) coloured(150, 150, 150)
      NEXT
   ENDIF
   
   // --- Patrones activos ---
   IF npt > 0 THEN
      FOR k = 0 TO npt - 1 DO
         IF $ptDir[k] > 0 THEN
            pr = rBull
            pg = gBull
            pb = bBull
         ELSE
            pr = rBear
            pg = gBear
            pb = bBear
         ENDIF
         
         xA = $ptIA[k]
         yA = $ptPA[k]
         xB = $ptIB[k]
         yB = $ptPB[k]
         xC = $ptIC[k]
         yC = $ptPC[k]
         
         // Estructura A-B-C y linea guia A-C
         drawsegment(xA, yA, xB, yB) coloured(pr, pg, pb) style(line, 2)
         drawsegment(xB, yB, xC, yC) coloured(pr, pg, pb) style(line, 2)
         drawsegment(xA, yA, xC, yC) coloured(pr, pg, pb) style(dottedline, 1)
         
         // Etiquetas de los pivotes, desplazadas fuera de la vela
         IF yA < yB THEN
            offA = 0 - atrv * 0.4
            offB = atrv * 0.4
         ELSE
            offA = atrv * 0.4
            offB = 0 - atrv * 0.4
         ENDIF
         drawtext("A", xA, yA + offA) coloured(pr, pg, pb)
         drawtext("B", xB, yB + offB) coloured(pr, pg, pb)
         drawtext("C", xC, yC + offA) coloured(pr, pg, pb)
         
         // Ratio de retroceso en el punto medio de A-C
         midX = (xA + xC) / 2
         midY = (yA + yC) / 2
         rtx = round($ptRt[k] * 1000) / 1000
         drawtext("#rtx#", midX, midY) coloured(pr, pg, pb)
         
         // Cajas de riesgo y objetivo
         IF showBoxes = 1 THEN
            barDiff = min((xC - xA) / 2, 490)
            IF barDiff < 5 THEN
               barDiff = 5
            ENDIF
            xEnd = xC + barDiff
            drawrectangle(xC, $ptEn[k], xEnd, $ptSt[k]) coloured(pr, pg, pb) fillcolor(200, 60, 60, 20)
            drawrectangle(xC, $ptEn[k], xEnd, $ptTg[k]) coloured(pr, pg, pb) fillcolor(60, 200, 60, 20)
         ENDIF
      NEXT
   ENDIF
   
   // --- Panel de estadisticas ---
   IF showStats = 1 THEN
      bullClosed = bullDone + bullStopped
      IF bullClosed > 0 THEN
         bullWin = bullDone * 100 / bullClosed
      ELSE
         bullWin = 0
      ENDIF
      bearClosed = bearDone + bearStopped
      IF bearClosed > 0 THEN
         bearWin = bearDone * 100 / bearClosed
      ELSE
         bearWin = 0
      ENDIF
      
      riskSpan = entryRatio - stopRatio
      IF riskSpan > 0 THEN
         rrv = round((targetRatio - entryRatio) / riskSpan * 100) / 100
      ELSE
         rrv = 0
      ENDIF
      bwin = round(bullWin * 10) / 10
      swin = round(bearWin * 10) / 10
      
      pX = -530
      pY = -30
      drawtext("ABC on Recursive Zigzag", pX, pY, sansserif, bold, 11) coloured(60, 60, 60) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      
      drawtext("Invalid", pX + 150, pY - 22, sansserif, bold, 10) coloured(60, 60, 60) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("Stopped", pX + 225, pY - 22, sansserif, bold, 10) coloured(60, 60, 60) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("Complete", pX + 305, pY - 22, sansserif, bold, 10) coloured(60, 60, 60) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("Win %", pX + 375, pY - 22, sansserif, bold, 10) coloured(60, 60, 60) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("R:R", pX + 425, pY - 22, sansserif, bold, 10) coloured(60, 60, 60) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      
      drawtext("Bullish", pX + 40, pY - 44, sansserif, bold, 10) coloured(rBull, gBull, bBull) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bullInvalid#", pX + 150, pY - 44) coloured(rBull, gBull, bBull) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bullStopped#", pX + 225, pY - 44) coloured(rBull, gBull, bBull) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bullDone#", pX + 305, pY - 44) coloured(rBull, gBull, bBull) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bwin#", pX + 375, pY - 44) coloured(rBull, gBull, bBull) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#rrv#", pX + 425, pY - 44) coloured(rBull, gBull, bBull) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      
      drawtext("Bearish", pX + 40, pY - 66, sansserif, bold, 10) coloured(rBear, gBear, bBear) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bearInvalid#", pX + 150, pY - 66) coloured(rBear, gBear, bBear) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bearStopped#", pX + 225, pY - 66) coloured(rBear, gBear, bBear) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#bearDone#", pX + 305, pY - 66) coloured(rBear, gBear, bBear) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#swin#", pX + 375, pY - 66) coloured(rBear, gBear, bBear) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
      drawtext("#rrv#", pX + 425, pY - 66) coloured(rBear, gBear, bBear) ANCHOR(TOPRIGHT, XSHIFT, YSHIFT)
   ENDIF
ENDIF
//-----------------------------------------------------------//
return

Download
Filename: PRC_ABC-on-recursive-zigzag.itf
Downloads: 11
Iván González Legend
I usually let my code do the talking, which explains why my bio is as empty as a newly created file. Bio to be initialized...
Author’s Profile

Comments

Logo Logo
Loading...