Screener doble suelo y doble techo con MACD en semanal

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #258262 quote
    lycos83
    Participant
    New

    Hola buenos dias, me gustaría verificar si estoy en lo correcto en el codigo de este screener para doble techo / suelo



    REM Defino techos
    TIMEFRAME (weekly)
    c1=Lowest[2](close)
    c2=Lowest[10](close)
    
    REM Defino divergencias alcistas sobreañadidas en MACD, al Doble Suelo
    MiMACD=MACD[12,26,9](close)
    
    c4=Lowest[2](MiMACD)
    c5=Lowest[10](MiMACD)
    
    REM añado variabilidad: mínimos relativos "similares"
    IF c1<1.03*c2 AND c1>0.97*c2 AND c4>c5 THEN
       c3
    ENDIF
    SCREENER (c3 AS "Doble suelo")
    


    #258263 quote
    lycos83
    Participant
    New

    Perdón, el correcto son estos:


    REM Defino suelos
    TIMEFRAME (weekly)
    c1=Lowest[2](close)
    c2=Lowest[10](close)
    
    REM Defino divergencias alcistas sobreañadidas en MACD, al Doble Suelo
    MiMACD=MACD[12,26,9](close)
    
    c4=Lowest[2](MiMACD)
    c5=Lowest[10](MiMACD)
    
    REM añado variabilidad: mínimos relativos "similares"
    IF c1<1.03*c2 AND c1>0.97*c2 AND c4>c5 THEN
       c3
    ENDIF
    SCREENER (c3 AS "Doble suelo")
    



    REM Defino techos
    TIMEFRAME (weekly)
    c1=Highest[2](close)
    c2=Highest[10](close)
    
    REM Defino divergencias bajistas sobreañadidas en MACD, al Doble Techo
    MiMACD=MACD[12,26,9](close)
    
    c4=Highest[2](MiMACD)
    c5=Highest[10](MiMACD)
    
    REM añado variabilidad: máximos relativos "similares"
    IF c1<1.03*c2 AND c1>0.97*c2 AND c4<c5 THEN
       c3
    ENDIF
    SCREENER (c3 AS "Doble techo")
    


    #258285 quote
    Iván González
    Moderator
    Master

    hola. Con ese código no lo conseguirás. primero antes de nada, encontrarás un error en la línea donde defines c3. no puedes poner sin más c3, tienes que definirla (c3=xx).

    Segundo, para identificar un doble suelo tienes que almacenar los puntos para poder luego mirar atrás y ver si ahora mismo están ahí.

    Mira, te pongo un ejemplo de indicador que podrías adaptar para screener. No haría falta usar arrays, se podrían almacenar simplemente los 2 ultimos minimos.

    //----------------------------------------------------------//
    // PRC_Double Top / Bottom
    // version = 0
    // 28.01.2025
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //----------------------------------------------------------//
    // Inputs
    //----------------------------------------------------------//
    //x = 21 // Time horizon for the pivot detection (number of bars back)
    src = close // Source price (close price in this case)
    //onlysignals = 0 // Whether to display only the signals or include visualization
    //----------------------------------------------------------//
    // Limit for price difference
    //----------------------------------------------------------//
    limit1 = average[100](abs(open - close)) // Average of the absolute difference between open and close (over 100 periods)
    //----------------------------------------------------------//
    // Pivots high and low
    //----------------------------------------------------------//
    // Pivots low
    if src > src[x] AND lowest[x](src) > src[x] AND src[x] < lowest[x](src)[x+1] THEN
       $pivoty[n+1] = src[x]
       $pivotx[n+1] = barindex[x]
       $pivotdir[n+1] = -1
       n = n + 1
    ENDIF
    // Pivots high
    if src < src[x] AND highest[x](src) < src[x] AND src[x] > highest[x](src)[x+1] THEN
       $pivoty[n+1] = src[x]
       $pivotx[n+1] = barindex[x]
       $pivotdir[n+1] = 1
       n = n + 1
    ENDIF
    //----------------------------------------------------------//
    // Checking for double top / bottom patterns
    //----------------------------------------------------------//
    if n > 3 THEN
       // Checking for a double bottom pattern
       if n <> n[1] AND $pivotdir[n] < 0 AND $pivotdir[n-1] > 0 AND $pivotdir[n-2] < 0 AND $pivotdir[n-3] > 0 AND abs(close[x] - $pivoty[n-2]) < limit1 THEN
          drawarrowup($pivotx[n], $pivoty[n]) coloured("green") // Draw an upward arrow for double bottom signal
          
          if onlysignals = 0 THEN
             drawsegment($pivotx[n-1], $pivoty[n-1], $pivotx[n], $pivoty[n]) coloured("green")
             drawsegment($pivotx[n-1], $pivoty[n-1], $pivotx[n-2], $pivoty[n-2]) coloured("green")
             drawsegment($pivotx[n-3], $pivoty[n-3], $pivotx[n-2], $pivoty[n-2]) coloured("green")
          ENDIF
          
          awaitingDBC = 1 // Mark as awaiting double bottom confirmation
          Bthresh = $pivoty[n-1] // Set the threshold price for confirmation
          BthreshIdx = $pivotx[n-1] // Store the bar index of the threshold
       ENDIF
       
       // Checking for a double top pattern
       if n <> n[1] AND $pivotdir[n] > 0 AND $pivotdir[n-1] < 0 AND $pivotdir[n-2] > 0 AND $pivotdir[n-3] < 0 AND abs(close[x] - $pivoty[n-2]) < limit1 THEN
          drawarrowdown($pivotx[n], $pivoty[n]) coloured("red") // Draw a downward arrow for double top signal
          
          if onlysignals = 0 THEN
             drawsegment($pivotx[n-1], $pivoty[n-1], $pivotx[n], $pivoty[n]) coloured("red")
             drawsegment($pivotx[n-1], $pivoty[n-1], $pivotx[n-2], $pivoty[n-2]) coloured("red")
             drawsegment($pivotx[n-3], $pivoty[n-3], $pivotx[n-2], $pivoty[n-2]) coloured("red")
          ENDIF
          
          awaitingDTC = 1 // Mark as awaiting double top confirmation
          Tthresh = $pivoty[n-1] // Set the threshold price for confirmation
          TthreshIdx = $pivotx[n-1] // Store the bar index of the threshold
       ENDIF
    ENDIF
    //----------------------------------------------------------//
    // Confirmation of patterns
    //----------------------------------------------------------//
    if awaitingDBC AND onlysignals = 0 THEN
       barsDBC = barsDBC + 1 // Increment the bar counter for double bottom confirmation
       if close < Bthresh AND barsDBC > x THEN
          awaitingDBC = 0
          drawsegment(BthreshIdx, Bthresh, barindex, Bthresh) coloured("green") style(dottedline)
          drawpoint(barindex, Bthresh, 3) coloured("orange")
       ELSIF close > Bthresh THEN
          awaitingDBC = 0
          drawsegment(BthreshIdx, Bthresh, barindex, Bthresh) coloured("green") style(dottedline)
       ENDIF
    ENDIF
    
    if awaitingDTC AND onlysignals = 0 THEN
       barsDTC = barsDTC + 1 // Increment the bar counter for double top confirmation
       if close > Tthresh AND barsDTC > x THEN
          awaitingDTC = 0
          drawsegment(TthreshIdx, Tthresh, barindex, Tthresh) coloured("red") style(dottedline)
          drawpoint(barindex, Tthresh, 3) coloured("orange") // Mark the confirmation point
       ELSIF close < Tthresh THEN
          awaitingDTC = 0
          drawsegment(TthreshIdx, Tthresh, barindex, Tthresh) coloured("red") style(dottedline)
       ENDIF
    ENDIF
    //----------------------------------------------------------//
    return
    


    #258288 quote
    Iván González
    Moderator
    Master

    mira, ya que estamos te pongo un ejemplo concreto. Aqui tienes un indicador para poder ver el resultado:

    // --- VARIABLES DE AJUSTE ---
    prd = 5 // Velas a izquierda y derecha para conformar el pivote (5 es el estandar fractal)
    toleranceUP = 1.01 // Margen superior (+1%)
    toleranceDOWN = 0.99 // Margen inferior (-1%)
    minBarsBetweenPivots = 10 // Separacion minima en velas entre los dos suelos
    
    // --- MACD ---
    myMACD = MACDline[12,26,9](close)
    
    // Inicializacion de variables de memoria (historico de pivotes)
    ONCE lastPivotLow = 0
    ONCE prevPivotLow = 0
    ONCE lastPivotMACD = 0
    ONCE prevPivotMACD = 0
    ONCE lastPivotBar = 0
    ONCE prevPivotBar = 0
    
    // --- DETECCION DE PIVOTES MINIMOS ---
    isPivotLow = (low[prd] = lowest[2 * prd + 1](low))
    
    c3 = 0
    IF isPivotLow THEN
       IF barindex[prd] > lastPivotBar + prd THEN
          // Desplazamos el pivote anterior a la memoria secundaria
          prevPivotLow = lastPivotLow
          prevPivotMACD = lastPivotMACD
          prevPivotBar = lastPivotBar
          // Registramos el nuevo pivote actual
          lastPivotLow = low[prd]
          lastPivotMACD = myMACD[prd]
          lastPivotBar = barindex[prd]
          // --- COMPROBACION DE DOBLE SUELO Y DIVERGENCIA ---
          IF prevPivotLow > 0 THEN
             isDoubleBottom = (lastPivotLow <= prevPivotLow * toleranceUP) AND (lastPivotLow >= prevPivotLow * toleranceDOWN)
             isDivergence = (lastPivotMACD > prevPivotMACD)
             isSeparated = (lastPivotBar - prevPivotBar) >= minBarsBetweenPivots
             
             IF isDoubleBottom AND isDivergence AND isSeparated THEN
                c3 = 1
                DRAWARROWUP(lastPivotBar, lastPivotLow - AverageTrueRange[14](close)) COLOURED(0, 255, 0)
                drawpoint(lastPivotBar, lastPivotLow,2)coloured("red")
                drawpoint(prevPivotBar, prevPivotLow,2)coloured("orange")
             ENDIF
          ENDIF
       ENDIF
    ENDIF
    
    RETURN
    

    Y aquí tienes el screener que localiza los activos (yo he puesto +-2%)

    // --- VARIABLES DE AJUSTE ---
    prd = 5
    toleranceUP = 1.02
    toleranceDOWN = 0.98
    minBarsBetweenPivots = 10
    
    // --- MACD ---
    myMACD = MACDline[12,26,9](close)
    
    ONCE lastPivotLow = 0
    ONCE prevPivotLow = 0
    ONCE lastPivotMACD = 0
    ONCE prevPivotMACD = 0
    ONCE lastPivotBar = 0
    ONCE prevPivotBar = 0
    
    // --- DETECCION DE PIVOTES ---
    isPivotLow = (low[prd] = lowest[2 * prd + 1](low))
    
    c3 = 0
    
    IF isPivotLow THEN
       IF barindex[prd] > lastPivotBar + prd THEN
          
          prevPivotLow = lastPivotLow
          prevPivotMACD = lastPivotMACD
          prevPivotBar = lastPivotBar
          
          lastPivotLow = low[prd]
          lastPivotMACD = myMACD[prd]
          lastPivotBar = barindex[prd]
          
          IF prevPivotLow > 0 THEN
             isDoubleBottom = (lastPivotLow <= prevPivotLow * toleranceUP) AND (lastPivotLow >= prevPivotLow * toleranceDOWN)
             isDivergence = (lastPivotMACD > prevPivotMACD)
             isSeparated = (lastPivotBar - prevPivotBar) >= minBarsBetweenPivots
             
             IF isDoubleBottom AND isDivergence AND isSeparated THEN
                c3 = 1
             ENDIF
          ENDIF
       ENDIF
    ENDIF
    
    SCREENER[c3]
    


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

Screener doble suelo y doble techo con MACD en semanal


ProScreener: Buscadores de Mercado y Rastreo

New Reply
Author
author-avatar
lycos83 @lycos83 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Iván González
1 week, 2 days ago.

Topic Details
Forum: ProScreener: Buscadores de Mercado y Rastreo
Language: Spanish
Started: 02/18/2026
Status: Active
Attachments: No files
Logo Logo
Loading...