break even avec plusieurs conditions dans la stratégie

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

    Bonjour à tous,

    je cherche a mettre en place la solution de sortie breakeven dans ma stratégie globale qui à plusieurs conditions d’achat différentes et de sortie différente.
    Lorsque j’ajoute le code suivant, le code fonctionne mais je n’arrive pas à lui donner des valeurs différentes pour chaque conditions dans la même stratégie.
    Avez vous un code pour que chaque ensemble de conditions soit autonome avec un breakene different au sein d’une stratégie globale ?
    Merci par avance

    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    
    startBreakeven = 2.5 //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 153000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 213000
    timeEnterAfter = time < noEntryAfterTime
    
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions pour ouvrir une position acheteuse 1
    
    indicator1 = MACD[37/3, 77/3, 9](close)
    c1 = (indicator1 >= 1.7)
    
    IF NOT ONMARKET AND c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 SHARES AT MARKET
    SET TARGET pPROFIT 6
    
    ENDIF
    
    // Conditions pour ouvrir une position acheteuse 2
    indicator2 = SmoothedStochastic[14,3](close)
    c2 = (indicator2 >= 13.3)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 SHARES AT MARKET
    SET TARGET pPROFIT 4
    ENDIF
    
    //exit long order on red candle (if breakeven is set)
    if longonmarket and close<open and breakevenLevel>0 then
    sell at market
    ENDIF
    
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    
    #244292 quote
    robertogozzi
    Moderator
    Master

    Je pense que ça ne marche pas car vos valeurs sont extrêmement petites.
    Je les ai changés et essayés sur DAX, TF 1 maintenant, et cela fonctionne bien.
    Voici le code :

    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    
    startBreakeven = 25 //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
    noEntryBeforeTime = 153000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
    noEntryAfterTime = 213000
    timeEnterAfter = time < noEntryAfterTime
    
    // Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions pour ouvrir une position acheteuse 1
    
    indicator1 = MACD[37/3, 77/3, 9](close)
    c1 = (indicator1 >= 1.7)
    
    IF NOT ONMARKET AND c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 SHARES AT MARKET
    SET TARGET pPROFIT 60
    ENDIF
    
    // Conditions pour ouvrir une position acheteuse 2
    indicator2 = SmoothedStochastic[14,3](close)
    c2 = (indicator2 >= 13.3)
    
    IF c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 1 SHARES AT MARKET
    SET TARGET pPROFIT 40
    ENDIF
    
    //exit long order on red candle (if breakeven is set)
    if longonmarket and close<open and breakevenLevel>0 then
    sell at market
    ENDIF
    
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    #244295 quote
    Iván González
    Moderator
    Master

    Bonjour ! En ajoutant la variable entry vous pouvez contrôler avec quel signal l’entrée a été produite et gérer la position.
    Voici un exemple. J’ai modifié les valeurs parce qu’elles ne donnaient pas de signaux.

    // Définition des paramètres du code
    DEFPARAM CumulateOrders = False // Cumul des positions désactivé
    
    startBreakeven1 = 2.5 // Niveau d'activation du breakeven pour la stratégie 1
    startBreakeven2 = 3.0 // Niveau d'activation du breakeven pour la stratégie 2
    
    PointsToKeep1 = 1 // Points conservés pour la stratégie 1
    PointsToKeep2 = 0.5 // Points conservés pour la stratégie 2
    
    // Gestion des horaires de trading
    noEntryBeforeTime = 153000
    timeEnterBefore = time >= noEntryBeforeTime
    
    noEntryAfterTime = 213000
    timeEnterAfter = time < noEntryAfterTime
    
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Indicateurs pour les conditions d'achat
    indicator1 = MACD[12, 26, 9](close)
    c1 = (indicator1 >= 1)
    
    indicator2 = SmoothedStochastic[14,3](close)
    c2 = (indicator2 < 15)
    
    // Variables de breakeven distinctes
    once breakevenLevel1 = 0
    once breakevenLevel2 = 0
    // Reset des niveaux de breakeven lorsque la position est clôturée
    IF NOT ONMARKET  THEN
    
    entry=0
    breakevenLevel = undefined
    buyprice=undefined
    targetprice=undefined
    check=0
    
    ENDIF
    // --- Conditions d'achat 1 (MACD) ---
    IF not onmarket AND c1 AND timeEnterBefore AND timeEnterAfter AND NOT daysForbiddenEntry THEN
    entry=1
    BUY 1 SHARES AT MARKET
    SET TARGET pPROFIT 6
    set stop ploss 10
    
    ENDIF
    
    // --- Conditions d'achat 2 (Stochastic) ---
    IF NOT ONMARKET AND c2 AND timeEnterBefore AND timeEnterAfter AND NOT daysForbiddenEntry THEN
    entry=2
    BUY 1 SHARES AT MARKET
    SET TARGET pPROFIT 4
    set stop ploss 10
    
    ENDIF
    
    if not onmarket[1] and onmarket and entry=1 then
    buyprice=open
    targetprice=buyprice+6*pipsize
    check=0.5
    elsif not onmarket[1] and onmarket and entry=2 then
    buyprice=open
    targetprice=buyprice+4*pipsize
    check=0.5
    endif
    // --- Gestion du breakeven pour la stratégie 1 ---
    IF LONGONMARKET and entry=1 then
    r=255
    g=0
    b=255
    
    IF close - buyprice >= startBreakeven1 * pipsize THEN
    breakevenLevel = buyprice + PointsToKeep1 * pipsize
    ENDIF
    
    ENDIF
    
    // --- Gestion du breakeven pour la stratégie 2 ---
    IF LONGONMARKET AND entry=2 THEN
    
    r=0
    g=0
    b=255
    
    IF close - buyprice >= startBreakeven2 * pipsize THEN
    breakevenLevel = buyprice + PointsToKeep2 * pipsize
    ENDIF
    
    ENDIF
    
    // --- Exécution des stops breakeven ---
    IF breakevenLevel > 0 and close crosses under breakevenLevel THEN
    SELL AT market
    entry=0
    ENDIF
    
    // --- Fermeture de position si bougie rouge ---
    IF LONGONMARKET AND close < open AND breakevenLevel > 0 THEN
    SELL AT MARKET
    entry=0
    ENDIF
    
    graphonprice buyprice coloured(r,g,b)
    graphonprice breakevenLevel coloured("orange")
    graphonprice targetprice coloured("green")
    
    graph entry
    
    robertogozzi thanked this post
    #244297 quote
    Iván González
    Moderator
    Master

    Je vois que Roberto a également répondu 🙂 Deux réponses valent mieux que rien.

    #244331 quote
    Lju
    Participant
    New

    merci beaucoup de vos retours
    je vais essayer ça pour le mettre en place sur mes stratégies
    je reviendrai vers vous

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

break even avec plusieurs conditions dans la stratégie


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Lju @lju Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Lju
1 year ago.

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