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

 
makssub #:
Hello. Please advise how to find the opening price of the order closest to the current price. MQL4. Do you have any examples?

We go through all open positions and compare the number of pips from the current price to the opening of a deal.

You can take any example, just above there is a code - search for orders in a loop.

 
MakarFX #:

What is OrdersClose ?

See here.

Got it, thanks.

 
PapaYozh #:


There is no need to fantasise. The essence of what happens is that you call a method, which is a constructor with a different set of parameters. No object is created in this case.

You should understand the difference between a constructor call and a method/function call.

PapaYozh #:

A similar constructor call that won't lead to the desired result either:

For the sake of argument, add a pointer to the signature of a method (constructor ? which is called like a method ?) by passing a pointer by reference

 
Taras Slobodyanik #:

We go through all open positions and compare the number of pips from the current price to the opening of a deal.

You can take any example, just above there is a code - search for orders in a loop.

Sorry, I am not writing it correctly again. Let me try again)

There is a grid of open orders. I need to find the opening price (OrderOpenPrice) of the order closest to the current price. In order to continue to build the grid, but my orders are almost chaotically built.

I understand how to write the overshoot, but I'm unable to express it correctly in the language (I'm like a dog, I understand everything)).

If you have examples or link to examples, post them, please. MQL4

 
Igor Makanu #:

You need to understand the difference between a constructor call and a method/function call

For the sake of argument, add a pointer to the signature of a method (constructor ? which is called like a method ?) and pass it by reference.

In Java it's OK.

You can also call the parent constructor from the child constructor, the only requirement is that the parent constructor is called by the first command in the child constructor.

In MQL, the problem is, if there's no empty constructor for the parent, the parent constructor is called implicitly when creating the child.

--

PS.

And if the parent has a constructor without parameters and a constructor with parameters, which one is called implicitly from the descendant constructor with parameters?

 
Igor Makanu #:


for the subject - in the signature of the method (constructor ? which is called as a method ?) add passing a pointer by reference


This looks like a crutch.

Isn't it?

 

Hi all. This may be a silly question, but I haven't found a solution yet.

I have created an indicator. It has buttons on the chart and when I press it, the line is drawn and the button becomes active.

How to make button activity and location remain active, when I switch timeframe?

When switching the TF, the function Deinit works, and it has the deletion of all objects. It is kind of a prerequisite, to clear everything from the chart.

I have tried to store the button status in a variable, but as I noticed in indicators they are zeroed if we switch the TF.

It is not like that in EA, the value of internal variables is not zeroed there. It turns out that if indicator has calculated some values and saved them in internal variables, they will be reset at TF switch. Why and how to avoid it.

 
makssub #:

Sorry, I'm writing it wrong again. Let me try again)

There is a grid of open orders. I need to find the opening price (OrderOpenPrice) of the order closest to the current price. In order to continue to build the grid, but my orders are almost chaotically built.

I understand how to write the overshoot, but I'm unable to express it correctly in the language (I'm like a dog, I understand everything)).

If you have examples or link to examples, post them, please. MQL4

First the difference is equal to 1000 before the cycle. In the loop, if the opening price minus the current price is modulo less than the difference, then the difference is equal to the obtained value and the ticket is stored in a variable.
 
Igor Makanu #:

You should know the difference between a constructor call and a method/function call.


What is the difference, by the way, apart from the fact that it is called implicitly when the object is created?

 
void ClosseAll()
{
  for(int i = OrdersTotal()-1; i>=0; i--)
  {
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
     {
       if (OrderType() == OP_BUY)
         { 
         if (!OrderClose(OrderTicket(), OrderLots(), Bid, slip))
             Print("Не удалось закрыть ордера на покупку!");
         }
       if (OrderType() == OP_SELL)
         { 
         if (!OrderClose(OrderTicket(), OrderLots(), Ask, slip))
             Print("Не удалось закрыть ордер на продажу!");
         }
     }
  }
}

Good day !!!

Please help in writing code for closing min and max orders in a grid EA when a certain level of drawdown is reached

I wrote two functions to calculate the profit of max and min orders

//+----------------------------------------------------------------------------+
//| Расчет профита максимального ордера в сетке                                |
//+----------------------------------------------------------------------------+
double GetProfitMaxOrder()
{
  int max_ticket = 0;
  double max_ticket_profit = 0 ;
  {
   for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) 
    {
    if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) 
     {
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
       {
        if(OrderType() == OP_BUY || OrderType() == OP_SELL)
        {
          if(OrderTicket() > max_ticket) max_ticket = ticket;
          {
           max_ticket_profit =  OrderProfit();
          }
        }
       }
     }
    }
  }
  return( max_ticket_profit);
}
//+----------------------------------------------------------------------------+
//| Расчет профита минимального ордера в сетке                                 |
//+----------------------------------------------------------------------------+
double GetProfitMinOrder()
{
  int min_ticket=INT_MAX;
  double min_ticket_profit = 0;
  {
   for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) 
    {
     if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
     {
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) 
        {
          if (OrderType() == OP_BUY || OrderType() == OP_SELL)
           {
            if(OrderTicket() < min_ticket)
              min_ticket = OrderTicket();
              {
               min_ticket_profit = OrderProfit(); 
              }
           }
        }
      }
    }
  }
  return(min_ticket_profit);
}

I have a function that calculates the amount of these orders. There seems to be no problem here.

The question is how to close only these two orders I have found the ClosseAll() function.

The question is how to change the OrderTicket() function which closes all orders

to attach variables max_ticket and min_ticket which determine tickets of only min and max orders in the grid

Or do YOU have YOUR solution to this question

Reason: