Errors, bugs, questions - page 1471

 

What is the purpose of the const modifier at the end of a method?

SetPoint(const int point,const datetime time,const double price) const;    < ------

What benefits do we get when using this modifier in initialization of variable names?

I am aware of the fact that the variable cannot change and get a different value.

Maybe this modifier speeds up the program's work?

 
Vladimir Pastushak:

What is the purpose of the const modifier at the end of a method?

What benefits do we get when using this modifier in initialization of variable names?

I am aware of the fact that the variable cannot change and get a different value.

May be this modifier speeds up the program operation?

This is from OOP. It means that the method does not change the object it is called from. Arguments have nothing to do with it.

The benefit is that when you look at the prototype you will see that the object will not be changed, i.e. visibility.

 
If you right-click in the chart tab of the MT4 tester and select "Copy", the pop-up window/menu does not disappear.
 

Hi guys all ) Please help me to write a code (more correctly one small part) my goal is to write a function select order history and there i need to see the value at which the last order was closed, positive or negative. Please advise who does this (I'm already wracking my brains )))))

Thank you in advance.

 
Tema97:

Hi guys all ) Please help me to write a code (more correctly one small part) the purpose is to write a function select order history and there I need to see what value was the last order closed, positive or negative. Who knows the code please advise me (I've already wracked my brains )))))

Thank you in advance.

MQL4

//+------------------------------------------------------------------+
   // Возвращает флаг закрытия последней позиции в убытке. Позиция выбирается по символу, типу и магику
   bool isLossLastClosePos(string sy, int op, int mn) {
      datetime t=0;
      int i, j=EMPTY;
      for(i=OrdersHistoryTotal()-1; i>=0; i--) {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
            if(OrderMagicNumber()!=mn) continue;
            if(OrderSymbol()!=sy)      continue;
            if(OrderType()!=op)        continue;
            if(t<OrderCloseTime()) {
               t=OrderCloseTime();
               j=i;
               }
            }
         }
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)) {
         if(OrderProfit()+OrderCommission()+OrderSwap()<0) return(true);
         }
      return(false);
   }
//+------------------------------------------------------------------+
   // Возвращает флаг закрытия последней позиции в убытке. Позиция выбирается по символу и магику
   bool isLossLastClosePos(string sy, int mn) {
      datetime t=0;
      int i, j=EMPTY;
      for(i=OrdersHistoryTotal()-1; i>=0; i--) {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
            if(OrderMagicNumber()!=mn) continue;
            if(OrderSymbol()!=sy)      continue;
            if(OrderType()>1)          continue;
            if(t<OrderCloseTime()) {
               t=OrderCloseTime();
               j=i;
               }
            }
         }
      if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)) {
         if(OrderProfit()+OrderCommission()+OrderSwap()<0) return(true);
         }
      return(false);
   }
//+------------------------------------------------------------------+

This is how we check:

if(isLossLastClosePos(symbol, magic)) {
   // последняя позиция закрыта в убытке
   }
 
Tema97:

Hi guys all ) Please help me to write a code (more correctly one small part) my goal is to write a function select order history and there i need to see the value at which the last order was closed, positive or negative. Please advise who does this (I'm already wracking my brains )))))

Thanks in advance.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает тип закрытия по профиту, 
//|  1= позиция закрыта в профите,                                             |
//|  2- позиция закрыта в минусе                                               |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int isCloseLastPosByStoporTake(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
      double ocp=OrderProfit();
if (OrderProfit()+OrderCommission()+OrderSwap()>0) return(1);
if (OrderProfit()+OrderCommission()+OrderSwap()<0) return(2);
  }
  return(0);
}

To find out, you do this:

if(isCloseLastPosByStoporTake("",-1,-1)==1) // Позиция закрыта в плюсе
if(isCloseLastPosByStoporTake("",-1,-1)==2) // Позиция закрыта в минусе
 
Artyom Trishkin:

MQL4

Check it this way:

))))

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает флаг убыточности последней позиции.                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isLossLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, j=-1, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                j=i;
              }
            }
          }
        }
      }
    }
  }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
    if (OrderProfit()<0) return(True);
  }
  return(False);
}
 
Vladislav Andruschenko:

))))

You do realise you're being silly with your innuendos now, don't you?

The code is mine. I took the logic and variable names from Igor. So I don't take your hint. The function name? Does it reflect the meaning, or are you no clueless in English?

 
Artyom Trishkin:

MQL4

Check it this way:

Thank you very much!!!!
 
Vladislav Andruschenko:

to find out what you're doing:

Thank you very much !!!

Reason: