[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 498

 
VOLDEMAR:

How do I calculate a profit on one currency pair in my EA?

For example, I have seven buy orders open on euros at different prices. How do I calculate a profit on euros without affecting other orders on other pairs? ????


Example,

 // ------------------------------------------------в цикле перебираем все ордера по инструменту и накапливаем общий профит---------------------------------
   double Sum_Profit;
   int orderType;
   for (int orderIndex = (OrdersTotal() - 1); orderIndex >= 0; orderIndex--)
   {
      if (!OrderSelect(orderIndex, SELECT_BY_POS))
      {
         continue;
      }

      if ((OrderSymbol() != Symbol()))
      {
         continue;
      }

      orderType = OrderType();
      if ((orderType != OP_BUY) && (orderType != OP_SELL))
      {
         continue;
      }
          // запоминаем характеристики ордера
         
          orderProfit = OrderProfit() + OrderSwap();       // Profit
          
          // накапливаем общий профиит
          Sum_Profit=Sum_Profit+orderProfit               // В цикле по всем ордерам валютной пары считаем общий профит                         
     
       
      return (0);
   }

 // Вывод текущего состояния на экран

      Comment("Общий профит по инструменту = ", Sum_Profit);
   
 
Roman.:


Example,

Thank you....
 
VOLDEMAR:
Thanks.... But Sum_Profit is still 0 ............

either in global variables

double Sum_Profit;

or in a function

static double Sum_Profit;
 
Tell me if you can write variables in MQL4 in Russian ???? And what are the possible consequences ???????
 
VOLDEMAR:
Tell me if you can write variables in MQL4 in Russian ???? And what are the consequences ???????

Available at
 

VOLDEMAR:
1. Скажите можно ли в MQL4 переменные писать русским языком ????

2. and what the consequences might be ???????


1. Already answered...

2. Problems with selling your Creations to the English-speaking public. :-)))

 
Can you please tell me if at weekends, when there are no ticks and the Start function is not running, is it possible to redraw objects on the chart, for example by mouse click? Tired of restarting the terminal and removing/inserting the Expert Advisor:)
 
Fam:
Can you please tell me if at weekends, when there are no ticks and the Start function is not running, is it possible to redraw objects on the chart somehow, e.g. by mouse click? Tired of restarting the terminal and removing/inserting the Expert Advisor :)

Do

init()
{
  start();
}

start()
{
  while(true)
  {
    if (IsStopped()) break;
    // ваш имеющийся код
  }
}
 
Thanks, I guessed it was possible to do something with the cycle, but didn't know how.
 
sergeev:

Do

The documentation says that init() should not be abused like this.
Reason: