I use this script to open a order. I get an error -1.

 

Hello,

I use this script to open a order.
I get an error -1.
Why?

Regards,

Pierre8r

//--------------------------------------------------------------------
// simpleopen.mq4 
// Ïðåäíàçíà÷åí äëÿ èñïîëüçîâàíèÿ â êà÷åñòâå ïðèìåðà â ó÷åáíèêå MQL4.
//--------------------------------------------------------------------
int start()                                  // Ñïåö. ôóíêöèÿ start()
  {                                          // Îòêðûòèå BUY
   int iReturnOrder = OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point);
   Alert(iReturnOrder);
   return;                                   // Âûõîä èç start()
  }
//--------------------------------------------------------------------

 

-1 is not the error . . . -1 is the return value meaning the OrderSend failed . . . read the Documentation

Add a Print if iReturnOrder is < 0 and Print GetLastError()

It may well be an ECN Broker issue . . . . if it is there is plenty of info here: ECN

 
tintin92:

Hello,

I use this script to open a order.

I get an error -1.

Why ?

Regards,

Pierre8r

Did you still install at C:\Program Files\ on 7/Vista ? The other you can't even open chm help files ?

 

Do what RaptorUK said, check GetLastError(). I think you should change some parameter :

    ,Bid-150*Point, Ask+150*Point);

You probably sending order with TP and SL within broker STOP_LEVEL. Look for MarketInfo.

 

I can see two reason why the OrderSend in your code would return a -1.

First, if you are dealing with an ECN broker, you must use OrderSend without setting a stoploss or takeprofit (that is, make those values = 0). Once the order has been successfully placed, modify the order (using OrderModify) to set the stoploss and takeprofit values.

Second, if you are dealing with a 5 digit broker, Point will be 0.00001. In your code, that means you are trying to set a stoploss and takeprofit of 1.5 pips (15 points). This value (15 points; aka, 1.5 pips) may be inside the broker's stoplevel, and if so, the broker will reject the trade. See Requirements and Limitations in Making Trades. If you want a 15 pip stoploss and takeprofit and are dealing with a 5 digit broker (and therefore Point is 0.00001), your code should be:

int iReturnOrder = OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-150*Point,Bid+150*Point); 

Out of curiosity, why are you using the Bid price (rather than the Ask price) when calculating your stoploss and takeprofit prices?

Hope the above helps.

 

Hello,

Changed my code.

Now, it works.

Thanks,

Pierre8r

//--------------------------------------------------------------------
// simpleopen.mq4 
// Ïðåäíàçíà÷åí äëÿ èñïîëüçîâàíèÿ â êà÷åñòâå ïðèìåðà â ó÷åáíèêå MQL4.
//--------------------------------------------------------------------
int start()                                  // Ñïåö. ôóíêöèÿ start()
  {                                          // Îòêðûòèå BUY
  
   int ticket;
   ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0);
   Alert(ticket);
   if(ticket<0)
   {
      Print("OrderSend failed with error #",GetLastError());
      return(0);
   }
   return;                                   // Âûõîä èç start()
  }
//--------------------------------------------------------------------
 
tintin92:

Hello,

Changed my code.

Now, it works.

Thanks,

Pierre8r

Well done ! :-)