Resposta

Soma aberta Profit Long/Short para o símbolo especificado

0 respostas

tomas262

Administrador, sq-ultimate, 2 respostas.

Perfil da visita

6 anos atrás #117426

Se você precisar obter o lucro aberto atual para o símbolo especificado, poderá usar a seguinte função no EA WIzard

 

1) adicione o código personalizado em CustomFunction.mq4 colocado na pasta 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) adicionar CustomAction assim no Wizard

 

Obter P/L aberto de posições compradas em EURUSD

sumOpenProfit("LONG", "EURUSD");

ou

 

obter P/L aberto para todas as posições vendidas ativas

sumOpenProfit("SHORT", "")

O exemplo de EA está anexado

0