Strange problem, Orders not passed

 
Here is the code:

      ticket=OrderSend(Symbol(), OP_BUY, max_slippage, Ask, max_slippage, Ask-take_profit*Point, Ask+lot_size*Point, "Long Order", 31337, 0, Green);
      write_time("OrderSend BUY");
      if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        write_time("OrderSend failed with error #"+GetLastError());
        return(0);
       }


Everytime the code is executed, ticket value is -1, meaning there has been a problem but GetLastError() returns 0, meaning everything is OK.

The order is not passed.

This happens on backtesting, and probably real trading too.

write_time() is my own function to log data into a file.

Any clue?
 
Isn't this the case?
The function returns the last occurred error, then the value of special last_error variable where the last error code is stored will be zeroized. So, the next call for GetLastError() will return 0.

Try to have a look into the log in metatrader, since you call the function twice, so I think the error will be saved through your Print function in the MetaTrader log but not in your own file.

Jan
 

Check your parameters for the OrderSend.

Use GetLastError like this:

{
int error = GetLastError();
Print("OrderSend failed with error #", error );
write_time("OrderSend failed with error #"+error );
return(0);
}

 
Great help there. Thanks both of you.

The error code is 134, meaning "Not enough money."

I'm trading 0.2 lot with 1k account. I tried with 0.01 lot and got the same error code. I don't understand that issue...
 
mjollnir:
Great help there. Thanks both of you.

The error code is 134, meaning "Not enough money."

I'm trading 0.2 lot with 1k account. I tried with 0.01 lot and got the same error code. I don't understand that issue...



And I don't have any open position.
 
Looking at your OrderSend function, you have this:

ticket=OrderSend(Symbol(), OP_BUY, max_slippage, Ask, max_slippage, Ask-take_profit*Point, Ask+lot_size*Point, "Long Order", 31337, 0, Green);
You know what the first one should be :).
 
Thanks! Silly search and replace error :)
Reason: