ProOrder stop dinámico, ayuda!!

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #256737 quote
    Eduardo Blasco
    Participant
    New

    Hola a todos!!

    Estoy intentado configurar un stop dinámico en ProOrder, y que me lo muestre en el gráfico. Tanto para compras como ventas. Pero no consigo hacerlo funcionar. Veo que no funciona bien y luego tampoco los muestra correctamente. Por si alguien me puede orientar, añado el código, gracias!!

    // Definición de los parámetros

    DEFPARAM CumulateOrders = False


    // RESET VALORES

    StopVisualLong = UNDEFINED

    StopVisualShort = UNDEFINED


    // — 2. ENTRADAS —

    indicator1 = WeightedAverage(close)

    indicator2 = Average(close)

    c1 = (indicator1 CROSSES OVER indicator2)

    c3 = (indicator1 CROSSES UNDER indicator2)

    IF c1 AND NOT LONGONMARKET THEN

    BUY 5000 CASH AT MARKET

    SET STOP %LOSS 15

    SLCompra = tradeprice(1) * 0.85

    ENDIF


    IF c3 AND NOT SHORTONMARKET THEN

    SELLSHORT 5000 CASH AT MARKET

    SET STOP %LOSS 15

    SLVenta = tradeprice(1) * 1.15

    ENDIF


    // — 3. LÓGICA DE TRAILING Y ASIGNACIÓN —

    StopDinamico = 0.15

    StopStep = 0.05


    IF LONGONMARKET THEN

    // Trailing Largos

    IF close >= tradeprice(1) * (1 + StopDinamico) THEN

    NivelTemporal = tradeprice(1) * (1 + StopStep)

    IF NivelTemporal > SLCompra OR SLCompra = UNDEFINED THEN

    SLCompra = NivelTemporal

    ENDIF

    ENDIF

    IF SLCompra <> UNDEFINED AND close >= SLCompra * (1 + StopStep) THEN

    SLCompra = SLCompra * (1 + StopStep)

    ENDIF

    // Asignación visual

    StopVisualLong = SLCompra

    SLVenta = UNDEFINED

    SLCompra = UNDEFINED


    ELSIF SHORTONMARKET THEN

    // Trailing Cortos

    IF close <= tradeprice(1) * (1 – StopDinamico) THEN

    NivelTemporal = tradeprice(1) * (1 – StopStep)

    IF NivelTemporal < SLVenta OR SLVenta = UNDEFINED THEN

    SLVenta = NivelTemporal

    ENDIF

    ENDIF

    IF SLVenta <> UNDEFINED AND close <= SLVenta * (1 – StopStep) THEN

    SLVenta = SLVenta * (1 – StopStep)

    ENDIF

    // Asignación visual

    StopVisualShort = SLVenta


    ELSE

    // RESET TOTAL (Usamos UNDEFINED para que no dibuje el nivel 0)

    SLVenta = UNDEFINED

    SLCompra = UNDEFINED

    ENDIF


    // — 4. ÓRDENES DE SALIDA —

    IF SLCompra <> UNDEFINED THEN

    IF LONGONMARKET THEN

    SELL AT SLCompra STOP

    ENDIF

    ENDIF

    IF SLVenta <> UNDEFINED THEN

    IF SHORTONMARKET THEN

    EXITSHORT AT SLVenta STOP

    ENDIF

    ENDIF


    SET TARGET %PROFIT 40


    // — 5. GRÁFICOS —

    GRAPHONPRICE StopVisualLong AS “Stop Compra” COLOURED(0,255,0)

    GRAPHONPRICE StopVisualShort AS “Stop Venta” COLOURED(255,0,0)

    #256740 quote
    Iván González
    Moderator
    Master

    Buenas, aquí tienes tu código modificado ligeramente. Ten en cuenta que cuando se da la señal de compra aún no estás dentro del mercado por lo que tradeprice no coge el valor de entrada. El sistema entra al dia siguiente. Como aproximacion puedes coger el precio de cierre. Si quieres ser más riguroso podrías actualizarlo una vez dentro del mercado.


    // --- 1. PARAMETERS DEFINITION ---
    DEFPARAM CumulateOrders = False
    
    // Parameters for indicators (User should define these values)
    avgPeriod = 20
    
    // Trailing parameters (using decimals: 0.15 = 15%)
    stopDynamic = 0.15
    stopStep = 0.05
    
    // --- 2. INDICATORS AND SIGNALS ---
    indicator1 = WeightedAverage[avgPeriod](close)
    indicator2 = Average[avgPeriod](close)
    
    c1 = (indicator1 CROSSES OVER indicator2)
    c3 = (indicator1 CROSSES UNDER indicator2)
    
    // --- 3. ENTRY LOGIC ---
    IF c1 AND NOT LONGONMARKET THEN
       BUY 5000 CASH AT MARKET
       // Initial stop at 15% loss
       setStopPrice = close * 0.85
    ENDIF
    
    IF c3 AND NOT SHORTONMARKET THEN
       SELLSHORT 5000 CASH AT MARKET
       // Initial stop at 15% loss
       setStopPrice = close * 1.15
    ENDIF
    
    // --- 4. TRAILING STOP LOGIC ---
    IF LONGONMARKET THEN
       // If we reach the dynamic threshold (15% above entry)
       IF close >= PositionPrice * (1 + stopDynamic) THEN
          // Potential new level based on step
          tempLevel = close * (1 - stopStep)
          // Only update if the new level is higher than current stop
          IF tempLevel > setStopPrice THEN
             setStopPrice = tempLevel
          ENDIF
       ENDIF
       
       // Visualization assignment
       stopVisualLong = setStopPrice
       stopVisualShort = UNDEFINED
       
    ELSIF SHORTONMARKET THEN
       // If we reach the dynamic threshold (15% below entry)
       IF close <= PositionPrice * (1 - stopDynamic) THEN
          // Potential new level based on step
          tempLevel = close * (1 + stopStep)
          // Only update if the new level is lower than current stop
          IF tempLevel < setStopPrice OR setStopPrice = 0 THEN
             setStopPrice = tempLevel
          ENDIF
       ENDIF
       
       // Visualization assignment
       stopVisualShort = setStopPrice
       stopVisualLong = UNDEFINED
       
    ELSE
       // Reset variables when not on market
       setStopPrice = 0
       stopVisualLong = UNDEFINED
       stopVisualShort = UNDEFINED
    ENDIF
    
    // --- 5. EXIT ORDERS ---
    IF LONGONMARKET THEN
       SELL AT setStopPrice STOP
    ENDIF
    
    IF SHORTONMARKET THEN
       EXITSHORT AT setStopPrice STOP
    ENDIF
    
    SET TARGET %PROFIT 40
    
    // --- 6. VISUALIZATION ---
    GRAPHONPRICE stopVisualLong AS "Long Stop" COLOURED(0, 255, 0)
    GRAPHONPRICE stopVisualShort AS "Short Stop" COLOURED(255, 0, 0)
    


    robertogozzi thanked this post
    #256906 quote
    Eduardo Blasco
    Participant
    New

    Buenos días Iván.

    Gracias por la ayuda. He estado revisando el código, entiendo que para ser más rigoroso como dices y que se actualice dentro del mercado no puedo usar el close. Al estar trabajando en gráfico diario, ¿debo usar precio actual?

    Y veo que a veces no se establece el stop, estándo en el mercado. Y se me cierra la posición, no veo que sea por señal de cierre. Algo tengo que tener mal en el código. ¿Se te ocurre a que se puede deber?


    Saludos.

    #256909 quote
    Iván González
    Moderator
    Master

    el sistema evalua el precio de la vela a cierre de esta, por lo que no puedes hacer mucho más. Lo único es que sí podrías bajar el timeframe si quisieras que no esperase a cerrar la vela.

    por ejemplo si operas con tf1h puedes bajar a tf1minuto.

    quizas sea por la logica de entrada. en lugar de escribir if not longonmarket/shortonmarket escribe if not onmarket

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

ProOrder stop dinámico, ayuda!!


Soporte ProOrder

New Reply
Author
Summary

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

Topic Details
Forum: Soporte ProOrder
Language: Spanish
Started: 01/23/2026
Status: Active
Attachments: No files
Logo Logo
Loading...