Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 842

 
Escapee:

OrderClose(OrderTicket(),0.01,Bid,2);

in "experts" it says "invalid ticket for OrderClose function".

Help? my goal is to close an order on the current chart.

if (OrdersTotal()==true)
{
if(OrderSelect(ticket,SELECT_BY_TICKET)>0 && OrderType()==(OP_BUY/OP_SELL здесь поставишь какой ордер) && (здесь можешь написать условия закрытия т.е. сигнал) 
{
bool close = OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed); 
if(!close)
Print("Ошибка закрытия ордера. Код ошибки=",GetLastError());
else
Print("Ордер BUY успешно закрыт.");
}
}
 
I need to REALLY close the order, if I may? Why doesn't orderticket work in the line of the program I wrote?
 
Pokrov:

Good evening! Help me understand the code below, sell is written on the same principle, why three options to open, because I had to fiddle with the option to avoid opening an order then - when the order opens on the current bar and closes on a no draw,

and the signal remains and opens again, so I have had to write it like this. The problem is that only one buy and sell order is opened and all else is silent. I cannot find any further errors. I am very grateful in advance.

How do you understand this line?

if (!OrdersTotal()==true)

I do not know how to read this line and this one.

if (!OrdersHistoryTotal()==true)

and this one...

if(OrderSelect(ticket,SELECT_BY_TICKET)>0 // дальше я не смотрел

Although this last line will work, but it is not so write ... I'm speechless.

Well, if you can't find the error, then there's probably no error...

 
Escapee:

OrderClose(OrderTicket(),0.01,Bid,2);

in "experts" it says "invalid ticket for OrderClose function".

Help? my goal is to close order on current chart.

Because before working with an order I need to select it with OrderSelect() function
 
AlexeyVik:

What is the meaning of this line?

and this one.

And this one...

Although this last line will work, but that's not the way to write ... I'm speechless.

Well, if you didn't find the error, then there's probably no error...

1. If there are no open orders

2. If there are no closed orders.

What is wrong?

 
Pokrov:

1. If there are no open orders

2. If there are no closed orders.

What is wrong?

int OrdersTotal(); - returns number, not truth-false, that's what's wrong. If there are no orders, it means 0. If there are orders, it's not only 1.

And there are no closed orders only on a freshly opened account that we haven't traded on yet. Again, this is an incorrect use of the function.

And why RefreshRates(); AFTER the order has been sent to the server? It's like to pay for something first and then ask "how much is it?

 
Pokrov:

if (OrdersTotal()==true)
{
if(OrderSelect(ticket,SELECT_BY_TICKET)>0 && OrderType()==(OP_BUY/OP_SELL здесь поставишь какой ордер) && (здесь можешь написать условия закрытия т.е. сигнал) 
{
bool close = OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed); 
if(!close)
Print("Ошибка закрытия ордера. Код ошибки=",GetLastError());
else
Print("Ордер BUY успешно закрыт.");
}
}

What kind of nonsense are you making here?

If the total number of orders and positions is 1 or more...
If an order is selected on an unknown ticket and it is not clear if it is closed or open...
...etc...

Do you think it helped?

 
evillive:

... No orders means 0, and if there are orders, it's not just 1.

...

This is where I will correct with permission so to speak.

In bool if there is 0 then it is false, everything else other than zero is true

 
Escapee:

OrderClose(OrderTicket(),0.01,Bid,2);

in "experts" it says "invalid ticket for OrderClose function".

Help? my goal is to close order on current chart.

To close a position using a ticket, you first need to know the exact ticket number of the position to be closed. Then you need to select the order using the OrderSelect(ticket,SELECT_BY_TICKET) function, with checks for successful selection. Then we need to check the time of closing of the successfully selected order. Why? Because when we select by ticket, the pool parameter of the OrderSelect(..., ..., pool) function is ignored (it is used only when we select by index). And it means that even if we have successfully selected an order, we still need to know in which list we have chosen it - the list of closed or open positions. It is the check of close time that allows us to find out "if the order is still in the market". If the time of closing is equal to zero, the order is still in the market. If the time is different from zero, the order has already been closed earlier. And after all this procedure, we can send an order to close that order.
 
artmedia70:
To close a position with a ticket, you first need to know the exact ticket number of the position to be closed. Then you must select the order using the OrderSelect(ticket,SELECT_BY_TICKET) function, with verification of successful selection. Then we need to check the time of closing of the successfully selected order. Why? Because when we select by ticket, the pool parameter of the OrderSelect(..., ..., pool) function is ignored (it is used only when we select by index). And it means that even if we have successfully selected an order, we still need to know in which list we have chosen it - the list of closed or open positions. It is the check of close time that allows us to find out "if the order is still in the market". If the time of closing is equal to zero, the order is still in the market. If the time is different from zero, the order has already been closed earlier. And after all this procedure, we can send an order to close that order.

I have a chart in front of me. I see that an order is open on it. I decide to close it. that's it. nothing else is needed.

(I ask because. I can close with a "one-click trade" cross, but I'm very comfortable with the hotkeys)

Reason: