Répondre

Somme des profits ouverts Long/Short pour le symbole spécifié

0 réponses

tomas262

Administrateur, sq-ultimate, 2 réponses.

Visiter le profil

il y a 6 ans #117426

Si vous avez besoin d'obtenir le profit ouvert actuel pour un symbole spécifié, vous pouvez utiliser la fonction suivante dans EA WIzard

 

1) ajouter le code personnalisé dans le fichier CustomFunction.mq4 placé dans le dossier Wizard

float sumOpenProfit(string direction, string symbolString) {
   float totalProfit = 0 ;
   for(int i=OrdersTotal()-1 ; i>=0 ; i--) {
      if (OrderSelect(i,SELECT_BY_POS)==true) {
         
         if (direction == "LONG" && symbolString != "" && OrderType() == OP_BUY && OrderSymbol() == symbolString) {
            totalProfit += OrderProfit() ;
         }
         
         else if (direction == "LONG" && symbolString == "" && OrderType() == OP_BUY) {
            totalProfit += OrderProfit() ;
         }
         else if (direction == "SHORT" && symbolString != "" && OrderType() == OP_SELL && OrderSymbol() == symbolString) {
            totalProfit += OrderProfit() ;
         }
         
         else if (direction == "SHORT" && symbolString == "" && OrderType() == OP_SELL) {
            totalProfit += OrderProfit() ;
         }
      }
   }
   return totalProfit ;
}

2) ajouter Action personnalisée comme ceci dans Wizard

 

Obtenir un P/L ouvert à partir de positions longues en EURUSD

sumOpenProfit("LONG", "EURUSD") ;

ou

 

obtenir le P/L ouvert pour tous les shorts actifs

sumOpenProfit("SHORT", "")

L'exemple d'EA est joint en annexe

0