This code snippet demonstrates how to manage a trading strategy that involves multiple stages of position closing and setting a breakeven stop loss for the remaining position using ProBuilder language.
// Paramètres initiaux
NbContratsInitiaux = 3 // Nombre initial de contrats
NbContrats = NbContratsInitiaux // Variable pour suivre le nombre de contrats actuellement ouverts
// Conditions pour clôturer des contrats
IF longonmarket THEN
IF NbContrats = NbContratsInitiaux AND positionperf > 0 THEN
SELL 1 CONTRACT AT market // Clôturer 1 contrat à la première clôture gagnante
NbContrats = NbContrats - 1
ELSIF NbContrats = NbContratsInitiaux - 1 AND positionperf > 0 THEN
SELL 1 CONTRACT AT market // Clôturer un second contrat à la bougie suivante gagnante
NbContrats = NbContrats - 1
SET STOP breakeven // Mettre le dernier contrat en breakeven
ENDIF
ENDIF
// Même logique pour les positions courtes (si nécessaire)
IF shortonmarket THEN
// Votre logique pour les positions courtes ici
ENDIF
This script is structured to handle a trading strategy where positions are closed in stages as profits are realized, and a breakeven stop loss is set for the final position. Here’s a breakdown of the code:
This example is useful for understanding how to programmatically manage trades in stages and adjust stop losses dynamically based on the trading conditions and performance.
Check out this related content for more information:
https://www.prorealcode.com/topic/se-mettre-breakeven-apres-clotures-partielles/#post-226909
Visit Link