problem with OrderClose()

 

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?

 
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() 

 
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.
 

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.