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

 
Vitaly Muzichenko:

Thank you, for some reason it doesn't work that way with the lot.

double GetLotLastOrder(string sy="", int op=-1, int mn=-1) {
double   r=-1;
  if (sy=="0") sy=Symbol();
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()>1 && OrderType()<6) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (r>OrderLots() || r==-1) {
                r=OrderLots();
  }}}}}}}
  return(r);
}

How do I return the lot of the fourteenth sell stop on the snapshot lot= 0.03?

 
Marina Korotkih:

Thank you, for some reason it doesn't work that way with the lot.

double GetLotLastOrder(string sy="", int op=-1, int mn=-1) {
  if (sy=="0") sy=Symbol();
  double r=MarketInfo(sy, MODE_MINLOT);
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()>1 && OrderType()<6) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (r>OrderLots()) {
                r=OrderLots();
  }}}}}}}
  return(r);
}
This is the minimum, if you need the most recent order, then I will do it now
 
Vitaly Muzichenko:

This is the minimum, if you need the most recent order, then I will do it now

Here's looking for the lot furthest away from the price

double GetLotLastOrder(string sy="", int op=-1, int mn=-1) {
datetime t=0;
double r=-1,l=0;
if (sy=="0") sy=Symbol();
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()>1 && OrderType()<6) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (r>OrderOpenPrice() || r==-1) {
                r=OrderOpenPrice();
                l=OrderLots();
  }}}}}}}
  return(l);
}
 
Marina Korotkih:

Thank you, for some reason it doesn't work that way with the lot.

double GetLotLastOrder(string sy="", int op=-1, int mn=-1) {
double   r=-1;
  if (sy=="0") sy=Symbol();
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()>1 && OrderType()<6) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (r>OrderLots() || r==-1) {
                r=OrderLots();
  }}}}}}}
  return(r);
}

How do I return the lot of the fourteenth sell stop in the snapshot lot= 0.03?



No the function works correctly, why is the return value not 1 and14 orders but 2?

is it a tester?

It works correctly for me.

 
Vitaly Muzichenko:

Here's looking for the lot furthest away from the price


Thank you, that makes sense. Found it, now you can find out all you need to know about it )

 
Alekseu Fedotov:

No the function works correctly, why is the return value not 1 and14 orders but 2?

is it a tester?

It works correctly for me.

You need to sort by price, because you can't search by size, the grid may be mixed, and you will find either the biggest or the smallest, but not the first and not the last
 
Marina Korotkih:

Thank you, that makes sense. Found it, now you can find out everything you need to know about it )

To find out all the information about an order or a position, it's better to do it by ticket

if(OrderSelect(i, SELECT_BY_TICKET)) {
  // всё что угодно
}
 
Alekseu Fedotov:

...why is the return value not 1 and14 orders but 2?


Because I call it like this

GetOrderOpenPrice(Symbol(),OP_SELLSTOP,_Magic)
 
Vitaly Muzichenko:

To find out the full details of an order or position, it is better to do so from the ticket

if(OrderSelect(i, SELECT_BY_TICKET)) {
  // всё что угодно
}

But to do this, we first need to know the ticket of the last order 14

So the order still has to be searched first, like in the first function?

Or just replace SELECT_BY_POS with SELECT_BY_TICKET

 
Marina Korotkih:

But in order to do this, you must first find out the ticket of the last order 14

So the order still needs to be searched first as in the first function?

Or just replace SELECT_BY_POS with SELECT_BY_TICKET

It depends on what you need to check. In fact, we may find out everything here, select the order by price and then write the required parameters for it and return everything.

Using loops one more time is not a good idea, so, it's better to realize everything in one loop; it is not noticeable in the real trading, but tests in the tester will run for a long time. However, it all depends on the task, someone writes programs for the tester, and someone for trading, so you can use more than one cycle.

P.S. If the Expert Advisor is a pipsqueak, of course, it is better not to use a single cycle)
Reason: