Error opening SELL order = 130

 
ticket=OrderSend(Symbol(),OP_SELL,LotsOptimizedsell(),NormalizePrice(Bid),3,0,NormalizePrice(TP_Level),"Sample EA",MagicNumber,0,Red);

I am using this part for open orders. One of broker ECN account always give error 130 when EA trying to open orders. But when i try it with DEMO account on the same broker, same account type, it never give error 130. It working well with DEMO account and all of other broker accounts that i tested.

So how to solve this problem?  

Thank you.

 

Some ECN brokers do not allow sending order with SL/TP.

You need to send it and then modify order for settings them.

 
Fabio Cavalloni:

Some ECN brokers do not allow sending order with SL/TP.

You need to send it and then modify order for settings them.

But in this code you can see Stoploss=0 or empty. But why it given invalid stop loss error(130)? 

 

I see

NormalizePrice(TP_Level)

Not 0

 
you need to strip out take and stop and set these to zero when first sending the order and then modify the order with take and stop
 

here's an example 

void BuyOrder(double vol,double stop,double take)
  {
      Ticket = OrderSend(Symbol(), OP_BUY, vol, Ask, Slippage, 0, 0, "", MagicNumber, 0, Blue);
   if(OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES))
     {
      SL = Bid - stop * Point;
      TP = Ask + take * Point
      if(!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0))
     {     
      Print("OrderModify BUY error - code : ", GetLastError());
      Print("WARNING: ORDER #", Ticket, " Failed to set TP/SL");
      return;
     }
  }
 
Ok i will try with zero. Thank you, everyone!
 
      SL = Bid - stop * Point;
      TP = Ask + take * Point
You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)