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

 

Please tell me why in the code I copied from this site the compiler writes "undeclared identifier" beforeMagic?

for (int pos=0; pos<=OrdersTotal()-1; pos ++) 
{
 if(OrderSelect (pos, SELECT_BY_POS)==true)
  {if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic &&OrderCloseTime()==0) // если у Вас есть отложенные ордера и открытие
  return;}
 else
  Print("OrderSelect() вернул ошибку - ",GetLastError());
}            
 //продолжае
 
VasiliKolchanov:

Can you please tell me why in the code I copied from this site beforeMagic the compiler writes " undeclared identifier" ?

it must be because it is not declared.

declare it at the beginning. or as an advisor parameter or constant...or a variable, at least somehow...the entity must exist :-)

input int Magic=5566; // это чтобы он был в параметрах и можно поменять

// или const int Magic = 8899;

 
VasiliKolchanov:

Could you please tell me why in the code I copied from this site the compiler writes "undeclared identifier" beforeMagic?

Because I used identifier Magic, which type (and value, respectively) is not described anywhere. You need to declare a variable (or constant) with that name and assign a value to it.

 
VasiliKolchanov:

Please tell me why in the code I copied from this site the compiler writes "undeclared identifier" beforeMagic?

Because it's not declared anywhere in your code - it's obvious.
 
Artyom Trishkin:
Because it's not declared anywhere in your code - that's obvious.
Thank you all!
 

Guys, tell me how to deal and where to start!

Example: I have 15 orders with 0.01 lot. I need to close some trade(s) with 0.07 lot size at some point.

My question is, how can I close 7 orders or 0.07 in one OrderClose(...)?

If I put 0.07 at once it does not see trades with volume 0.01.

I am new to programming

 
Rustam Bikbulatov:

Guys, tell me how to deal and where to start!

Example: I have 15 orders with 0.01 lot. I need to close some trade(s) with 0.07 lot size at some point.

My question is, how can I close 7 orders or 0.07 in one OrderClose(...)?

If I put 0.07 at once it does not see trades with volume 0.01.

I am new to programming.

There is no way to close it by one order. We can only make a selection of orders and consequently delete each order. And if you delete the order of a smaller volume, you still have an open volume. We compare it with our remaining open volume. We close until the volume of 0.07 reaches its limit. That's the only way.

 
Rustam Bikbulatov:

Guys, tell me how to deal and where to start!

Example: I have 15 orders with 0.01 lot. I need to close some trade(s) with 0.07 lot size at some point.

My question is, how can I close 7 orders or 0.07 in one OrderClose(...)?

If I put 0.07 at once it does not see trades with volume 0.01.

I am new to programming.

If the broker allows using counter-closing, you may open one opposite order with the volume 0.07, thus fixing the profit/loss price for this volume. Well, after that, we would still need to perform 7 opposite close operations (OrderCloseBy() function). There are one more trading operation to be executed using this approach. The advantage is that all seven orders are closed at one price.

 

Hi all.

Please advise on the speed of the EA, and probably the reliability and correctness of the code.

I am referring to open and pending orders in every tick and change them if necessary.

In the manual for OrderSelect, it is written:"When orders are sequentially selected using the SELECT_BY_POS parameter, the information is given in the order in which it was received from the trade server."

From this, the question arises: Can we create an array, in which the type, entry price and, for example, a unique comment of an order would be stored? Would you run through the array in each tick and then, if necessary, address to the OrderSelect function and make a selection using the unique comment of the order?

 
Decromor:

Hi all.

Please give your advice, it is mainly about the speed of the EA and probably its reliability and correctness in writing.

I am referring to open and pending orders in every tick and change them if necessary.

In the manual for OrderSelect, it is written:"When orders are sequentially selected using the SELECT_BY_POS parameter, the information is given in the order in which it was received from the trade server."

From this, the question arises: Can we create an array, in which the type, entry price and, for example, a unique comment of an order would be stored? In each tick, we should run through the array and, if necessary, address to the OrderSelect function and make a selection by the unique comment of the order?

The OrderSelect() is implemented inside the terminal, and there is no request to the server. That is why there is nothing bad in calling the order list on every tick. This is exactly what most EAs do.

And your question about the array is related to the architecture of the program. In case of a complex EA that operates with a large amount of orders, this is absolutely necessary. If the Expert Advisor operates with a single order with simple logic, the array is redundant.

It is only worth to mention the fact that even if we have an array of orders, we cannot do without calling OrderSelect(). After all, we have to check at every tick whether the order still exists or not. And we can also change its parameters.