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

 
Artyom Trishkin:

That's a strange feeling you have. Just showed you how to keep it simple - without any unnecessary variables.


So I'm tired and it's time for me to go get some rest - sleep, yeah.

 

Good afternoon! What is the function of the indicator window in the Expert Advisor?

 
Nauris Zukas:

Good afternoon! What functions in the Expert Advisor can you make the indicator window?


Call an empty indicator from the Expert Advisor.

 
Alekseu Fedotov:

Call out an empty indicator from the expert.

Thank you!

 
Vitaly Muzichenko:

Find the code you need here


Hello! I took the function to determine the price of the last open Sell order

PriceS(string sy="0", int op=OP_SELL, int mn=-1) {             //Цена последнего открытого Селл ордера
  datetime t;
  double   r=0;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) {
                t=OrderOpenTime();
                r=OrderOpenPrice();
              }
            }
          }
        }
      }
    }
  }
  return(r);
}

But when I paste it into my EA, I get a compile-time error in the 'sy' function's condition - unexpected token

=' - unexpected token 252 18

l-value required 1 1

implicit conversion from 'string' to 'number' 252 19

'=' - l-value required 252 18

'=' - expression of 'void' type is illegal 252 18

'op' - unexpected token 252 28

'=' - unexpected token 252 30

l-value required 1 1

'OP_SELL' - illegal operation use 252 31

possible loss of data due to type conversion 252 30

'=' - l-value required 252 30

'=' - expression of 'void' type is illegal 252 30

'mn' - unexpected token 252 44

'=' - unexpected token 252 46

l-value required 1 1

'1' - illegal operation use 252 48


Seems like everything should be correct!?? Please advise, I copied it and did not change anything.


 
vikzip:

Hello! I took the function to determine the price of the last open Sell order

But when I paste it into an EA, I get a compile-time error in the 'sy' function condition - unexpected token

=' - unexpected token 252 18

l-value required 1 1

implicit conversion from 'string' to 'number' 252 19

'=' - l-value required 252 18

'=' - expression of 'void' type is illegal 252 18

'op' - unexpected token 252 28

'=' - unexpected token 252 30

l-value required 1 1

'OP_SELL' - illegal operation use 252 31

possible loss of data due to type conversion 252 30

'=' - l-value required 252 30

'=' - expression of 'void' type is illegal 252 30

'mn' - unexpected token 252 44

'=' - unexpected token 252 46

l-value required 1 1

'1' - illegal operation use 252 48


Seems like everything should be correct!?? Please advise, I copied it and did not change anything.


I need to return the function type

PriceS(string sy="0", int op=OP_SELL, int mn=-1) {
double PriceS(string sy="0", int op=OP_SELL, int mn=-1) {
 
vikzip:


I think everything should be correct!?? Please advise, I copied it anddidn't change anything.



And the header of the function, and didn't copy the function type


The function originally looks like this:

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

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) {
                t=OrderOpenTime();
                r=OrderOpenPrice();
              }
            }
          }
        }
      }
    }
  }
  return(r);
}
 
'op' - unexpected token Армата.mq4 248 28 'OP_SELL' - illegal operation use Армата.mq4 248 31 'mn' - unexpected token Армата.mq4 248 44 
double PriceS(string sy="", int op=OP_SELL, int mn=-1) {             //Цена последнего открытого Селл ордера
  datetime t;
  double   r=0;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) {
                t=OrderOpenTime();
                r=OrderOpenPrice();
              }
            }
          }
        }
      }
    }
  }
  return(r);
}
Alekseu Fedotov
:


And the function header, and did not copy the function type


The function originally looks like this:


Alekseu Fedotov:

A function header, and have not copied the function type


The function originally looks like this:


Correct, the example also said. If I have understood correctly, you can select the order type, which I have done.

  • Op- Trade operation, position type. Valid values:OP_BUY,OP_SELL or-1. The default value of-1 means any position.
Then I made the function global by putting it before start. But if I return the double type right before the function's name, an error will occur. Please tell me why!

'PriceS' - function can be declared only in the global scope 252 10

I understood that the function must be global!

Translated the error in the translator it says

The function may be defined only in the global scope. If I understand the meaning of these words correctly, it must be defined globally and therefore don't precede it with double. It is not clear why it generates an error on sy even if I just copy it from the pattern.

'sy' - unexpected token 248 17 '=' - unexpected token 248 19 l-value required 1 1

Can i make sy global? and same error with other declared variables in the function.

'op' - unexpected token 248 28 'OP_SELL' - illegal operation use 248 31 'mn' - unexpected token 248 44

 
vikzip:


That's right, it was also written in the example. If I understood correctly it is possible to select the order type, which I did.

  • op- Trade operation, position type. Valid values:OP_BUY,OP_SELL or-1. The default value of-1 means any position.
Then I made the function global by putting it before start. But if I return the double type right before the function's name, an error will occur. Please tell me why!

'PriceS' - function can be declared only in the global scope 252 10

I understood that the function must be global!

Translated the error in the translator says


Place the function outside the start function

And in the body of the start function, you call it like this:

PriceOpenLastPos(); //текущий символ  любая последняя поз.


PriceOpenLastPos(Symbol(),OP_SELL);//текущий символ  OP_SELL   без магика


PriceOpenLastPos(Symbol(),OP_BUY);//текущий символ   OP_BUY  без магика

3 parameter magik, comma separated, put your own or 0

 
Alekseu Fedotov:

Place the function outside the start function

In the body of the start function, you call it like this:

3 parameter magik, comma separated, put your own or 0


Thank you so much!!! As soon as I put the function outside the start function, all the errors disappeared!!!

Reason: