break even avec plusieurs conditions dans la stratégie
Forums › ProRealTime forum Français › Support ProOrder › break even avec plusieurs conditions dans la stratégie
- This topic has 4 replies, 3 voices, and was last updated 4 weeks ago by
Lju.
-
-
02/23/2025 at 1:32 PM #244223
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 avance1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Définition des paramètres du codeDEFPARAM 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éenoEntryBeforeTime = 153000timeEnterBefore = 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éenoEntryAfterTime = 213000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions pour ouvrir une position acheteuse 1indicator1 = MACD[37/3, 77/3, 9](close)c1 = (indicator1 >= 1.7)IF NOT ONMARKET AND c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 1 SHARES AT MARKETSET TARGET pPROFIT 6ENDIF// Conditions pour ouvrir une position acheteuse 2indicator2 = SmoothedStochastic[14,3](close)c2 = (indicator2 >= 13.3)IF c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 1 SHARES AT MARKETSET TARGET pPROFIT 4ENDIF//exit long order on red candle (if breakeven is set)if longonmarket and close<open and breakevenLevel>0 thensell at marketENDIF//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF02/24/2025 at 3:47 PM #244292Je 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 :1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Définition des paramètres du codeDEFPARAM 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éenoEntryBeforeTime = 153000timeEnterBefore = 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éenoEntryAfterTime = 213000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions pour ouvrir une position acheteuse 1indicator1 = MACD[37/3, 77/3, 9](close)c1 = (indicator1 >= 1.7)IF NOT ONMARKET AND c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 1 SHARES AT MARKETSET TARGET pPROFIT 60ENDIF// Conditions pour ouvrir une position acheteuse 2indicator2 = SmoothedStochastic[14,3](close)c2 = (indicator2 >= 13.3)IF c2 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 1 SHARES AT MARKETSET TARGET pPROFIT 40ENDIF//exit long order on red candle (if breakeven is set)if longonmarket and close<open and breakevenLevel>0 thensell at marketENDIF//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF02/24/2025 at 4:14 PM #244295Bonjour ! 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.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107// Définition des paramètres du codeDEFPARAM CumulateOrders = False // Cumul des positions désactivéstartBreakeven1 = 2.5 // Niveau d'activation du breakeven pour la stratégie 1startBreakeven2 = 3.0 // Niveau d'activation du breakeven pour la stratégie 2PointsToKeep1 = 1 // Points conservés pour la stratégie 1PointsToKeep2 = 0.5 // Points conservés pour la stratégie 2// Gestion des horaires de tradingnoEntryBeforeTime = 153000timeEnterBefore = time >= noEntryBeforeTimenoEntryAfterTime = 213000timeEnterAfter = time < noEntryAfterTimedaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Indicateurs pour les conditions d'achatindicator1 = MACD[12, 26, 9](close)c1 = (indicator1 >= 1)indicator2 = SmoothedStochastic[14,3](close)c2 = (indicator2 < 15)// Variables de breakeven distinctesonce breakevenLevel1 = 0once breakevenLevel2 = 0// Reset des niveaux de breakeven lorsque la position est clôturéeIF NOT ONMARKET THENentry=0breakevenLevel = undefinedbuyprice=undefinedtargetprice=undefinedcheck=0ENDIF// --- Conditions d'achat 1 (MACD) ---IF not onmarket AND c1 AND timeEnterBefore AND timeEnterAfter AND NOT daysForbiddenEntry THENentry=1BUY 1 SHARES AT MARKETSET TARGET pPROFIT 6set stop ploss 10ENDIF// --- Conditions d'achat 2 (Stochastic) ---IF NOT ONMARKET AND c2 AND timeEnterBefore AND timeEnterAfter AND NOT daysForbiddenEntry THENentry=2BUY 1 SHARES AT MARKETSET TARGET pPROFIT 4set stop ploss 10ENDIFif not onmarket[1] and onmarket and entry=1 thenbuyprice=opentargetprice=buyprice+6*pipsizecheck=0.5elsif not onmarket[1] and onmarket and entry=2 thenbuyprice=opentargetprice=buyprice+4*pipsizecheck=0.5endif// --- Gestion du breakeven pour la stratégie 1 ---IF LONGONMARKET and entry=1 thenr=255g=0b=255IF close - buyprice >= startBreakeven1 * pipsize THENbreakevenLevel = buyprice + PointsToKeep1 * pipsizeENDIFENDIF// --- Gestion du breakeven pour la stratégie 2 ---IF LONGONMARKET AND entry=2 THENr=0g=0b=255IF close - buyprice >= startBreakeven2 * pipsize THENbreakevenLevel = buyprice + PointsToKeep2 * pipsizeENDIFENDIF// --- Exécution des stops breakeven ---IF breakevenLevel > 0 and close crosses under breakevenLevel THENSELL AT marketentry=0ENDIF// --- Fermeture de position si bougie rouge ---IF LONGONMARKET AND close < open AND breakevenLevel > 0 THENSELL AT MARKETentry=0ENDIFgraphonprice buyprice coloured(r,g,b)graphonprice breakevenLevel coloured("orange")graphonprice targetprice coloured("green")graph entry1 user thanked author for this post.
02/24/2025 at 4:16 PM #24429702/25/2025 at 10:17 AM #244331 -
AuthorPosts
Find exclusive trading pro-tools on