problem with OrderClose()

Alberto Tortella
866
Alberto Tortella  

Hi all, I manually opened a sell order on USDCAD, size 0.10, order ticket 162078588.

I wrote a simple expert that I attached on the USDCAD graph.

int start() 
  {  
   OrderClose(162078588,OrderLots(),Ask,NULL,PaleGoldenrod) ;                 
  }

The expert does not close the order. In the Journal tab there is nothing, no errors or advice.

Where is the problem?

Simon Gniadkowski
17393
Simon Gniadkowski  
Alberto_jazz:

Hi all, I manually opened a sell order on USDCAD, size 0.10, order ticket 162078588.

I wrote a simple expert that I attached on the USDCAD graph.

The expert does not close the order. In the Journal tab there is nothing, no errors or advice.

Where is the problem?

Check your return value from the function OrderClose() and report the error and any other useful information,  when you don't understand what is happening check that you are using the functions correctly.

Read these:

What are Function return values ? How do I use them ?

OrderLots() 

William Roeder
25092
William Roeder  
Alberto_jazz:

Hi all, I manually opened a sell order on USDCAD, size 0.10, order ticket 162078588.

I wrote a simple expert that I attached on the USDCAD graph.

int start() 
  {  
   OrderClose(162078588,OrderLots(),Ask,NULL,PaleGoldenrod) ;                 
  }

The expert does not close the order. In the Journal tab there is nothing, no errors or advice.

Where is the problem?

  1. Not checking your function return codes
  2. Useing OrderLots() BEFORE doing a successful OrderSelect()
  3. The fourth argument to OrderClose is NOT a string.
Alain Verleyen
41920
Alain Verleyen  

This give you an idea how to process :

for (int position = OrdersTotal()-1; position >= 0; position--)
{
    if (OrderSelect(position, SELECT_BY_POS, MODE_TRADES) && OrderTicket() == 162078588 ) {

        if (!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, PaleGoldenrod) {
            //TODO process error
            Print("Error .... ", GetLastError());
        }
    }
}

I have not compiled and tested.