Screener % Drawdown

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

    Hola buenos días.

    Estoy construyendo un screener donde quiero obtener el máximo drawdown en las ultimas 300 sesiones.


    El código sería el siguiente:

    maxabs=highest[300](close)

    minabs=lowest[300](close)

    maxdrawdown=(maxabs-minabs)/maxabs*100


    El problema veo que la secuencia temporal en esas últimas 300 sesiones puede no ser: máximo absoluto –> drawdown (mínimo) –>recuperación, por lo que si el “drawdown” es previo al máximo absoluto, tras dicho máximo la caida que pueda venir ya no la coge el indicador (que es justo lo que quiero).


    No se si me he explicado…..


    Saludos y gracias.

    #264575 quote
    robertogozzi
    Moderator
    Legend

    La verdad es que no me queda muy claro. ¿Podrías adjuntar un ejemplo o una foto con las líneas dibujadas de lo que quieres?

    #264577 quote
    JS
    Participant
    Master

    Hola, prueba este…

    LookBack = 300
    
    
    maxDD = 0
    peak = High
    
    
    For i= 0 to (LookBack-1) DO
    peak = Max(peak, High[i])
    DD= (peak - Low[i]) / peak * 100
    maxDD=Max(maxDD,DD)
    Next
    
    
    Screener[maxDD](maxDD AS "Max Drawdown %")
    


    Nicolas and robertogozzi thanked this post
    Scherm­afbeelding-2026-08-19-om-12.21.23-scaled.png Scherm­afbeelding-2026-08-19-om-12.21.23-scaled.png
    #264578 quote
    Nicolas
    Keymaster
    Legend

    Sí, te has explicado perfectamente. El problema es clásico: tu fórmula actual simplemente coge el máximo y el mínimo absolutos del período sin importar el orden temporal. Si el mínimo ocurrió antes que el máximo, no es un drawdown real desde ese máximo.

    El drawdown máximo real requiere que para cada barra, busques el máximo que ocurrió antes (o en esa barra), y luego la caída desde ese máximo hasta el mínimo posterior.

     Aquí tienes una solución: (sin probar)

    // Max Drawdown en las últimas 300 sesiones
    // Lógica: para cada barra dentro de la ventana, se rastrea el pico anterior
    // y la mayor caída pico->valle respetando el orden temporal
    
    
    NPeriods = 300
    
    
    lastHigh  = 0
    lowestLow = 0
    biggestDD = 0
    
    
    FOR i = NPeriods - 1 DOWNTO 0 DO
        currentHigh = high[i]
        currentLow  = low[i]
    
    
        IF i = NPeriods - 1 THEN
            lastHigh  = currentHigh
            lowestLow = currentLow
        ELSE
            IF currentHigh > lastHigh THEN
                lastHigh  = currentHigh
                lowestLow = currentLow
            ELSIF currentHigh < lastHigh THEN
                lowestLow = Min(lowestLow, currentLow)
                drawdown  = (lastHigh - lowestLow) / lastHigh * 100
                biggestDD = Max(biggestDD, drawdown)
            ENDIF
        ENDIF
    NEXT
    
    
    SCREENER[biggestDD > 0](biggestDD AS "Max DrawDown %")
    
    robertogozzi thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Screener % Drawdown


ProScreener: Buscadores de Mercado y Rastreo

New Reply
Author
author-avatar
lycos83 @lycos83 Participant
Summary

This topic contains 3 replies,
has 4 voices, and was last updated by Nicolas
3 weeks, 4 days ago.

Topic Details
Forum: ProScreener: Buscadores de Mercado y Rastreo
Language: Spanish
Started: 08/19/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...