OrderSend not sending order

 

Hello,

I am trying to send an order with this function:

OrderSend(currencies[i], OP_BUY, 0.1, MarketInfo(currencies[i],MODE_ASK), 10, MarketInfo(currencies[i],MODE_ASK)-0.0005,  MarketInfo(currencies[i],MODE_ASK)+0.001,"Sell", Peru);

For this one I am trying to set a stop loss of 5 pips and a takeprofit of 10 pips. Am I doing this right and if not how would I do? The error code that it's returning is 0. Btw, currencies[i] is just a string array of currency symbols. I get the error for all symbols.

Any help is appreciated. Thank you.

 

If Error_Code equals Zero then make sure that the order send is being executed. Place a Print/Alert statement before the order send function. Example: Print("Before_OrderSend"); OrderSend(......); Print("After_OrderSend");. In most cases just the print before is needed.

Ecn type brokers do-not allow the stoploss and/or takeprofit to be summited during the order send. For these brokers, you'll want to send the order with Zero{0} for sl and tp then perform an order_modify should the order_send succeed.

You'll also need to check Broker's minimum stop-distance when adding stoploss/takeprofit upon an order.

Your order_send is too long and cumbersome in-my-opinion. I'll recommend shorting the expressions passed to the orders send by using local variables before the send.

 
bkhan:

Hello,

I am trying to send an order with this function:

For this one I am trying to set a stop loss of 5 pips and a takeprofit of 10 pips. Am I doing this right and if not how would I do? The error code that it's returning is 0. Btw, currencies[i] is just a string array of currency symbols. I get the error for all symbols.

Any help is appreciated. Thank you.

Where are you capturing the return value ? if you aren't how do you know it is failing aand if it isn't failing why are you checking for GetLastError() ?

Read this: What are Function return values ? How do I use them ?

 

Here's a fuller version of my code:

int currentOrder = OrderSend(currencies[i], OP_BUY, 0.1, MarketInfo(currencies[i],MODE_ASK), 10, MarketInfo(currencies[i],MODE_ASK)-0.001, MarketInfo(currencies[i],MODE_ASK)+0.001,"Sell", Peru);
               
if(currentOrder==-1)
 {
    currentOrder=0;
    Alert("Long order fail with: ",currencies[i], ". Error: ",GetLastError());
    return;
 }
 Alert("Trade was made with ", currencies[i]," ticketnumber= ",currentOrder);

Ordersend is clearly returning -1 as I always get into the if statement, and it tells me the GetLastError...

 
bkhan:

Here's a fuller version of my code:

Ordersend is clearly returning -1 as I always get into the if statement, and it tells me the GetLastError...

Try with TP and SL set to 0.0 to rule out this issue : https://www.mql5.com/en/forum/138291
 

Probably the stops are less than MarketInfo(Symbol(), MODE_STOPLEVEL) allows or there is something wrong with your string array of symbols, or the loop accessing it.

Also you should set your stops reletive to the Bid price on Buy orders. SL = Bid - nPips otherwise the spread takes away from it.

 
SDC:

Probably the stops are less than MarketInfo(Symbol(), MODE_STOPLEVEL) allows or there is something wrong with your string array of symbols, or the loop accessing it.

Also you should set your stops reletive to the Bid price on Buy orders. SL = Bid - nPips otherwise the spread takes away from it.

None of which would explain the error 0
 

As he is calling an array of currency symbols it suggests he is opening a string of orders on different currency pairs in a loop. If there really is an OrderSend() fail and GetLastError() returns zero, I thought maybe he is getting the OrderSend() fail somewhere in the string of orders but calling GetLastError() at the wrong time, perhaps a successful order was opened since the failed one or something of that nature. Anyway so I looked at his OrderSend() and my suggestions are due to the varying spread of different currency pairs will affect his stops in relation to MODE_STOPLEVEL because he is basing them on the Ask price, and that an error in his string array may be calling a misspelt currency pair or an error in the loop may be calling an array index that is empty.

 

I also recommend adding all the parameters of the ordersend() and avoid over/under loading it. Make sure you're providing the correct variable types as-well.

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
 

I have a similar problem.I try to  send orders in the same time (Buy and BuyLimit),but after second positions , buylimit send does not work.Works only a Buy order. That is mean buycount >buylimitcount , but the point its buycount = buylimit in the first time  Please , can you some one help me, where is the mistake ?

This is my code :

some code

if(Ask>=NextBuyPrice)

   if(signal=="buy")

   {

 int buyticket=  OrderSend (_Symbol,OP_BUY,0.01,Ask,3,Ask-1000*_Point,Ask+1000*_Point,NULL,0,0,Green);

 int buyticket1=OrderSend(_Symbol,OP_BUYLIMIT,0.01,Ask-(countBuyLimitPosition()*200*_Point)-((countBuyLimitPosition()+1)*400*_Point),0,Ask-1000*_Point,Ask+1000*_Point,NULL,0,0,Green);

   NextBuyPrice=Ask+200*_Point; 

}

See attachment 

Files:
Capture.JPG  31 kb
Reason: