dca strategie. pas d’erreur mais ne donne aucun resultat !

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #250096 quote
    arrot
    Participant
    Junior

    bjr,

    j’ai réalisé un backtest de la stratégie DCA

    il n’y a pas d’erreur de code mais je n’obtiens aucun résultat

    pouvez vous m’aider

    merci,

    AT

    // ========================================
    // STRATEGIE DCA (DOLLAR COST AVERAGING)
    // ========================================

    DEFPARAM CumulateOrders = true // cumul des positions

    // — PARAMETRES DE LA STRATEGIE —
    DCAInterval = 20 // Nombre de barres entre chaque achat DCA
    InvestAmount = 1000 // Montant en cash à investir à chaque fois
    MaxPositions = 10 // Nombre maximum de positions simultanées
    StopLossPct = 15 // Stop loss en pourcentage (15 = -15%)
    TakeProfitPct = 20 // Take profit en pourcentage (20 = +20%)

    // — VARIABLES —
    ONCE BarsSinceLastBuy = 0
    ONCE TotalPositions = 0
    ONCE TotalInvestment = 0
    ONCE AveragePrice = 0

    // — COMPTEUR DE BARRES —
    BarsSinceLastBuy = BarsSinceLastBuy + 1

    // — CONDITION D’ACHAT DCA —
    // Acheter tous les X barres si on n’a pas atteint le maximum de positions
    IF BarsSinceLastBuy >DCAInterval AND TotalPositions < MaxPositions THEN BUY InvestAmount CASH AT MARKET BarsSinceLastBuy = 0 TotalPositions = TotalPositions + 1 TotalInvestment = TotalInvestment + InvestAmount IF COUNTOFLONGSHARES > 0 THEN
    AveragePrice = TotalInvestment / COUNTOFLONGSHARES
    ENDIF
    endif

    // — CONDITIONS DE SORTIE —
    // Stop Loss : Vendre si le prix descend sous le seuil défini
    IF LONGONMARKET AND Close <= AveragePrice * (1 - StopLossPct/100) THEN SELL AT MARKET // Réinitialiser les variables TotalPositions = 0 TotalInvestment = 0 AveragePrice = 0 BarsSinceLastBuy = 0 ENDIF // Take Profit : Vendre si le prix monte au-dessus du seuil défini IF LONGONMARKET AND Close >= AveragePrice * (1 + TakeProfitPct/100) THEN
    SELL AT MARKET
    // Réinitialiser les variables
    TotalPositions = 0
    TotalInvestment = 0
    AveragePrice = 0
    BarsSinceLastBuy = 0
    ENDIF

    // — VERSION ALTERNATIVE AVEC MOYENNES MOBILES —
    // Décommentez ces lignes pour ajouter un filtre de tendance

    // MM20 = AVERAGE[20](CLOSE)
    // MM50 = AVERAGE[50](CLOSE)

    // Condition d’achat DCA améliorée avec filtre de tendance
    // IF BarsSinceLastBuy >= DCAInterval AND TotalPositions < MaxPositions AND MM20 > MM50 THEN
    // BUY InvestAmount CASH AT MARKET
    // BarsSinceLastBuy = 0
    // TotalPositions = TotalPositions + 1
    // TotalInvestment = TotalInvestment + InvestAmount
    // IF COUNTOFLONGSHARES > 0 THEN
    // AveragePrice = TotalInvestment / COUNTOFLONGSHARES
    // ENDIF
    // ENDIF

    // ========================================
    // PARAMETRES DE BACKTEST RECOMMANDES
    // ========================================
    //
    // 1. Capital initial : 50 000 € (pour permettre 10 achats de 1000€)
    // 2. Spread : Selon l’instrument (ex: 2 points pour CAC40)
    // 3. Commission : Selon votre courtier
    // 4. Période de test : Au moins 2-3 ans pour évaluer la robustesse
    // 5. Timeframe : H1 ou D1 pour éviter le bruit
    //
    // METRIQUES A ANALYSER :
    // – Gain total et pourcentage
    // – Maximum Drawdown
    // – Ratio gain/perte
    // – Nombre de trades gagnants/perdants
    // – Profit Factor
    // – Sharpe Ratio (si disponible)

    // ========================================
    // VARIANTES A TESTER
    // ========================================
    //
    // 1. DCA avec RSI : Acheter seulement si RSI < 70 // 2. DCA avec support/résistance // 3. DCA pyramidal : Augmenter la taille lors des baisses // 4. DCA avec stop time : Arrêter après X mois // 5. DCA adaptatif : Modifier l'intervalle selon la volatilité

    prt-dca.txt
    #250102 quote
    Iván González
    Moderator
    Master

    Bonjour. J’ai modifié le moins possible ton code pour qu’il soit fonctionnel.
    J’ai ajouté au tout début le calcul de la variable totalpositions et de averageprice.

    // ========================================
    // STRATEGIE DCA (DOLLAR COST AVERAGING)
    // ========================================
    dEFPARAM CumulateOrders = true // Pas de cumul des position
    // --- PARAMETRES DE LA STRATEGIE ---
    DCAInterval = 20        // Nombre de barres entre chaque achat DCA
    InvestAmount = 1000     // Montant en cash à investir à chaque fois
    MaxPositions = 10       // Nombre maximum de positions simultanées
    StopLossPct = 15        // Stop loss en pourcentage (15 = -15%)
    TakeProfitPct = 20      // Take profit en pourcentage (20 = +20%)
    // --- VARIABLES ---
    ONCE BarsSinceLastBuy = 0
    ONCE TotalPositions = 0
    ONCE TotalInvestment = 0
    ONCE AveragePrice = 0
    
    if not onmarket then
    TotalPositions=0
    else
    IF COUNTOFLONGSHARES > 0 THEN
    AveragePrice = TotalInvestment / COUNTOFLONGSHARES
    ENDIF
    endif
    // --- COMPTEUR DE BARRES ---
    BarsSinceLastBuy = BarsSinceLastBuy + 1
    // --- CONDITION D'ACHAT DCA ---
    // Acheter tous les X barres si on n'a pas atteint le maximum de positions
    IF BarsSinceLastBuy >DCAInterval AND TotalPositions < MaxPositions THEN
    BUY InvestAmount CASH AT MARKET
    BarsSinceLastBuy = 0
    TotalPositions = TotalPositions + 1
    TotalInvestment = TotalInvestment + InvestAmount
    endif
    // --- CONDITIONS DE SORTIE ---
    // Stop Loss : Vendre si le prix descend sous le seuil défini
    IF LONGONMARKET AND Close <= AveragePrice * (1 - StopLossPct/100) THEN
    SELL AT MARKET
    // Réinitialiser les variables
    TotalPositions = 0
    TotalInvestment = 0
    AveragePrice = 0
    BarsSinceLastBuy = 0
    ENDIF
    // Take Profit : Vendre si le prix monte au-dessus du seuil défini
    IF LONGONMARKET AND Close >= AveragePrice * (1 + TakeProfitPct/100) THEN
    SELL AT MARKET
    // Réinitialiser les variables
    TotalPositions = 0
    TotalInvestment = 0
    AveragePrice = 0
    BarsSinceLastBuy = 0
    ENDIF
    
    graphonprice AveragePrice
    graphonprice AveragePrice * (1 + TakeProfitPct/100) coloured("blue")
    graphonprice AveragePrice * (1 - StopLossPct/100)coloured("red")
    

    De plus, je te transmets une variante de ce code pour que tu puisses voir une autre façon de calculer le prix moyen ainsi que la sortie par take profit et stop loss.

    // ========================================
    // STRATEGIE DCA (DOLLAR COST AVERAGING)
    // ========================================
    DEFPARAM CumulateOrders = true // Pas de cumul des positions
    // --- PARAMETRES DE LA STRATEGIE ---
    DCAInterval = 20        // Nombre de barres entre chaque achat DCA
    InvestAmount = 1000     // Montant en cash à investir à chaque fois
    MaxPositions = 10       // Nombre maximum de positions simultanées
    StopLossPct = 15        // Stop loss en pourcentage (15 = -15%)
    TakeProfitPct = 20      // Take profit en pourcentage (20 = +20%)
    // --- VARIABLES ---
    ONCE BarsSinceLastBuy = 0
    // --- COMPTEUR DE BARRES ---
    BarsSinceLastBuy = BarsSinceLastBuy + 1
    if not onmarket then
    TotalPositions=0
    TotalInvestment = 0
    endif
    // --- CONDITION D'ACHAT DCA ---
    // Acheter tous les X barres si on n'a pas atteint le maximum de positions
    IF BarsSinceLastBuy > DCAInterval AND TotalPositions < MaxPositions THEN
    BUY InvestAmount CASH AT MARKET
    BarsSinceLastBuy = 0
    TotalPositions=TotalPositions+1
    TotalInvestment = TotalInvestment + InvestAmount
    endif
    // --- CONDITIONS DE SORTIE ---
    set target %profit TakeProfitPct
    set stop %loss StopLossPct
    
    graphonprice positionprice
    graphonprice positionprice * (1 - StopLossPct/100) coloured("red")
    graphonprice positionprice * (1 + TakeProfitPct/100) coloured("blue")
    
    graph TotalInvestment
    
    robertogozzi thanked this post
    #250215 quote
    arrot
    Participant
    Junior

    merci beaucoup IVAN

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

dca strategie. pas d’erreur mais ne donne aucun resultat !


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
arrot @arrot Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by arrot
6 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 08/27/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...