Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1822

 
Alexander Avksentyev #:
// профит в пунктах
 int getOrderProfit() {
  switch (OrderType()) {
  case OP_BUY:
    return (int)((Bid - OrderOpenPrice()) / Point);
  case OP_SELL:
    return (int)((OrderOpenPrice() - Ask) / Point);
  default: 
    return 0;
  }
}

It is mandatory to select an order (OrderSelect) before calling.

 
Alexander Avksentyev #:

The close function is under what condition should an order be closed?

I did not notice the elephant))) What do you think the closing price of the open order is equal to?

OrderClose(min_ticket,OrderLots(),OrderClosePrice(),iSlippage,clrPink);

Try to do it this way

   int min_ticket=FindTicketOrder();

   if(OrderSelect(min_ticket, SELECT_BY_TICKET,MODE_TRADES)) 
    { 
      if(OrderProfit()<=-x)
        {
         if(OrderType()==OP_BUY)
           {
            if(OrderClose(min_ticket,OrderLots(),Bid,iSlippage,clrPink))
               Print("Buy Order Close");
            else
               Print("Order вернул ошибку - ",GetLastError());
           }
         if(OrderType()==OP_SELL)
           {
            if(OrderClose(min_ticket,OrderLots(),Ask,iSlippage,clrPink))
               Print("Sell Order Close");
            else
               Print("Order вернул ошибку - ",GetLastError());
           }
        }
    } 
 
Mihail Matkovskij #:

It is mandatory to select an order (OrderSelect) before calling.

If the order is not from the current character?

 
Tretyakov Rostyslav #:

And I didn't notice the elephant))) What do you think the closing price of an open order equals?

Try it this way

Bid symbol

 
Tretyakov Rostyslav #:

And I didn't notice the elephant))) What do you think the closing price of an open order equals?

Try it that way.

I've got it that way.

OrderClosePrice()

I read on the forum that you can specify it instead of bid and ask and it will work. I trusted it. I'm a naive fool. Tried another Bid || Ask, also did not work.
Thanks for the help!

 
Artyom Trishkin #:

If the order is not from the current symbol?

Then SymbolInfoDouble

 
Tretyakov Rostyslav #:

And I didn't notice the elephant))) What do you think the closing price of an open order equals?

Try to do it that way.

Another question

How do you calculate the profit in points - is this OrderProfit * Point?

 
Mihail Matkovskij #:

Then SymbolInfoDouble

Why not right away?

 
Alexander Avksentyev #:

Another question

Is the profit calculation in pips an OrderProfit * Point?

OrderProfit Returns net profit value, (those in the deposit currency)
Point-
Point size of the current instrument in the quote currency

All from reference

 
Andrey Sokolov #:

OrderProfit Returns the net profit value, (those in the deposit currency)
Point - Current instrument point size in the quote currency

All from reference

I agree, I read the reference.

I multiplied the profit by the Point and got 0.00001 or less.

Reason: