[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 216

 
artsnz >> :

Is this possible? DoC offer to close an order at a better price???? This is the first time I've heard of a brokerage company getting so sloppy.

The robot was not stupid, by definition it cannot be stupid.

It is necessary simply to correct the code, if you want you can lay it out here and you can help here, you can write in your personal message and surely too will help.

1. Yes, it happened - it is clear from the log.

2. I used the word "stupid" in a figurative sense meaning that something was wrong in the code.

3. Here is the code of pose closing:

for ( cop=0; cop< t_o; cop++)
 {
  OrderSelect( cop, SELECT_BY_POS, MODE_TRADES);//Выбор ордера по позиции среди открытых
  if(OrderMagicNumber()== MN) 
  {
   ot=OrderTicket();
   if(!OrderClose(OrderTicket(),OrderLots(), price,3, Color))
    Print("Ошибка при закрытии ордера! ED:", ErrorDescription(GetLastError()));
   
  }
 }

But the pose doesn't always close, and it's not an error, it's considered normal, a message like this comes from the server:

2009.09.08 00:44:42 '64766': requote 1.51893 / 1.51933 for order #11573500 sell 1.80 EURCHF closing at 1.51914

As you know, this means that the price has changed in the short term while the closing request went to the server.

And the server suggests a new closing price. The server is given time to respond - 3 seconds. And here is the problem - the server refuses to close the order at the new price!

How this happens is not clear... Help me understand, please.

 

Guys, please explain the meaning of the exclamation mark(!ExistPosition).

if(cnt > 0 && !ExistPosition(OP_BUY) && Ask <= price - PipsForOpenMore * Point)

 
001 >> :

Guys, please explain the meaning of the exclamation mark(!ExistPosition).

if(cnt > 0 && !ExistPosition(OP_BUY) && Ask <= price - PipsForOpenMore * Point)

literal translation of this line will be

if cnt is MORE than 0 and the ExistPosition(OP_BUY) function returns FALSE and Ask is LESS than or equal to price - PipsForOpenMore * Point, then....

The "!" is a negation. If it were not, the if condition would assume that the ExistPosition(OP_BUY) function should return TRUE.

 
Hello, could you please advise how to catch and process a stop loss or take profit event in an EA? I would like to ask you how to process a closing event for a Stop Loss or Take Profit.
 
cdover >> :
Hello, Could you please advise how to catch and handle in an EA the event of closing a deal at stoploss or takeprofit. >> Thank you.

Do you want something to be executed before closing on stop/profit?

 
MrSoros писал(а) >>

Do you want something to be executed before closing on stop/profit?

No, right after the close.

 

OrdersTotal() - will return 0 as soon as the order has been closed.

Accordingly, if OrdersTotal() returns 0, then you do the processing...

This is the case when only one order is open.

If you describe your situation in more details, what you want to do after the order is closed, then I will be able to give you a better answer :)

 
Alex5757000 >> :
Colleagues, I have a question about averaging. purely mathematical. let's assume we have averaged 3 times: positions with the same volume of 1 lot. at a price of 1.8 and 1.6 and 1.4. The actual opening price here will be 1.6. With this it is clear. But I don't understand how I can calculate the actual open price, if we opened with different lots, e.g. with an averaging factor of N. // For example: 0.1 lot and 0.2 and 0.4 - here N==2 at 1.8 and 1.6 and 1.4 . What will be the actual opening price?

I don't understand the logic.

Can you explain it more precisely, from an example?

 
MrSoros писал(а) >>

3. Here's the code to close the position:

Increase the slippage value to 50, you have 5 digits, so 0.3 pips doesn't work.

 
cdover писал(а) >>
Hello, could you please tell me how to capture and handle in my EA the event of closing a deal at Stop Loss or Take Profit. >> Thank you.

Look at the last order in the history, determine the order type.

For example for a long position:

If the order closed at a price equal to or lower than the stop loss, then it was a stop loss.

If at the price equal to or higher than TakeProfit - TakeProfit.