Aide à la création d’une stratégie: achat si la bougie journalière verte

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #253976 quote
    Poupouille
    Participant
    New

    Bonjour, je suis en train de me former à la programmation mais je n’en suis qu’aux débuts, càd nulle part 🙂

    J’aurais dans l’immédiat besoin d’un code je pense assez simple pour une stratégie de base que je compte améliorer au fure et à mesure de mon apprentissage.

    Voici les données pour la création de ce code.

    Instruments : Indices, graphique 30 min

    Je souhaiterais qu’à 13h30 (variable que je pourrais modifier), le robot prenne une position à l’achat si la bougie journalière (la bougie du jour jusque 13h30) est verte (en hausse) et inversément, une position à la vente si la bouge du jour est rouge (en baisse).

    Je souhaiterais que ce code me donne la possibilité de :

    • choisir le nombre de contrats souhaité
    • clôturer ma position à une heure précise, par exemple 22h (variable que je pourrais modifier)

    Enfin, mettre un SL à 1X l’ATR et un TP à 2X l’ATR : l’idéal serait que je puisse modifier les variables ATR et même mieux, me donner la possiblité de mettre ou non un TP et un SL (Par exemple, avant de lancer la stratégie, je devrais dire SL oui ou non et TP oui ou non.

    J’espère avoir été clair 🙂

    Si parmi vous quelqu’un pouvait me réaliser cela ce serait super sympa.

    Mille mercis et bons trades à toutes et à tous.

    #253990 quote
    Iván González
    Moderator
    Master

    voici:

    // Main Parameters Definition
    DEFPARAM CumulateOrders = False // Do not cumulate positions
    DEFPARAM FlatAfter = 220000 // Force close all positions after this time
    
    // --- CONFIGURABLE VARIABLES (For optimization or manual adjustment) ---
    // Entry Time (Format HHMMSS)
    TimeEntry = 133000
    // Forced Exit Time (Format HHMMSS)
    TimeExit = 220000
    // Position Size
    n = 1
    // ATR Period for risk calculation
    ATRLength = 14
    // Stop Loss Configuration
    activeSL = 1 // 1 = Yes, 0 = No
    multSL = 1.0
    // Take Profit Configuration
    activeTP = 1 // 1 = Yes, 0 = No
    multTP = 2.0
    
    // -----------------------------------------------------------------
    // STRATEGY LOGIC
    // -----------------------------------------------------------------
    // Current ATR Calculation
    ATR = AverageTrueRange[ATRLength](close)
    
    // Check conditions only at the defined entry closing time
    IF Time = TimeEntry THEN
       
       // Determine the color of the daily candle up to this moment
       isBullish = Close > DOpen(0)
       isBearish = Close < DOpen(0)
       
       // Long Entry (Buy)
       IF isBullish THEN
          BUY n CONTRACTS AT MARKET
          
          // Stop and Target Configuration for the position
          IF activeSL THEN
             SET STOP LOSS ATR * multSL
          ENDIF
          
          IF activeTP THEN
             SET TARGET PROFIT ATR * multTP
          ENDIF
       ENDIF
       
       // Short Entry (Sell)
       IF isBearish THEN
          SELLSHORT n CONTRACTS AT MARKET
          
          // Stop and Target Configuration for the position
          IF activeSL THEN
             SET STOP LOSS ATR * multSL
          ENDIF
          
          IF activeTP THEN
             SET TARGET PROFIT ATR * multTP
          ENDIF
       ENDIF
       
    ENDIF
    // -----------------------------------------------------------------
    // TIME EXIT
    // -----------------------------------------------------------------
    
    // If we reach the exit time, close everything
    // This acts as a safeguard before the FlatAfter triggers
    IF Time >= TimeExit THEN
       SELL AT MARKET
       EXITSHORT AT MARKET
    ENDIF
    
    // Visual check on chart
    GRAPHONPRICE DOpen(0) AS "Daily Open" COLOURED(0, 0, 255)
    
    robertogozzi and JS thanked this post
    #253996 quote
    Poupouille
    Participant
    New

    Waouw, mille mercis, c’est super sympa.

    Ce code est très facile à utiliser, top de chez top.

    J’ai maintenant de quoi travailler.

    Merciiiiiiiiiiiii

    Iván González thanked this post
    #254023 quote
    Poupouille
    Participant
    New

    Re bonjour. J’aurais encore besoin d’une petite aide pour le code que vous m’avez créé.

    J’ai la possibilité de mettre des SL et TP en fonction d’un multiplicateur de l’ATR.

    Serait-il possible de rajouter la possibilité de mettre des SL et TP en fonvtion d’un nombre de pips (je mets alors NON pour les SL et TP en fonction de l’ATR) ?

    Je vous remercie,

    Patrick

    #254048 quote
    Iván González
    Moderator
    Master

    claro. Puedes utilizar la instrucción

    SET STOP PLOSS 50
    SET TARGET PPROFIT 50

    https://www.prorealcode.com/documentation/ploss-2/

    PPROFIT

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

Aide à la création d’une stratégie: achat si la bougie journalière verte


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Poupouille @poupouille Participant
Summary

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

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 11/26/2025
Status: Active
Attachments: No files
Logo Logo
Loading...