Can't find the problem: Error: invalid stops

 

Hey there guys,

I'm getting this problem and dunno what is the reason. Following is an excerpt from my log;

2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: ==-----ORDER SENDING PERIMETERS-----==
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: SYMBOL IS = EURUSD
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: ORDER TYPE = OP_SELL
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: VOLUME IS = 0.01000000
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: PRICE IS = 1.35573000
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: STOP LOSS IS  = 1.35603000
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: TAKE PROFIT IS = 1.35513000
2011.11.15 18:41:27 Alpha1_20111114 EURUSD,M1: [placeOrder:SELL] Error: invalid stops

Here's my order placing function;

void placeOrder(string oType)
  {
      double price, TP, SL;
      if(oType == "BUY")
      {
         price = NormalizeDouble(Ask , Digits);
         SL = Ask - StopLossPips * Point;
         TP = Ask + TakeProfitPips * Point;
         Print("==-----ORDER SENDING PERIMETERS-----==");
         Print("SYMBOL IS = " + Symbol());
         Print("ORDER TYPE = OP_BUY");
         Print("VOLUME IS = " + Lots);
         Print("PRICE IS = " + price);
         Print("STOP LOSS IS  = " + SL);
         Print("TAKE PROFIT IS = " + TP);
         if(OrderSend(Symbol(), OP_BUY, Lots, price, 0, SL, TP) == -1)
         {
            Print("[placeOrder:BUY] Error: " + ErrorDescription(GetLastError()));
         }
      }
      else if(oType == "SELL")
      {
         price = NormalizeDouble(Bid , Digits);
         SL = Bid + StopLossPips * Point;
         TP = Bid - TakeProfitPips * Point;
         Print("==-----ORDER SENDING PERIMETERS-----==");
         Print("SYMBOL IS = " + Symbol());
         Print("ORDER TYPE = OP_SELL");
         Print("VOLUME IS = " + Lots);
         Print("PRICE IS = " + price);
         Print("STOP LOSS IS  = " + SL);
         Print("TAKE PROFIT IS = " + TP);
         if(OrderSend(Symbol(), OP_SELL, Lots, price, 0, SL, TP) == -1)
         {
            Print("[placeOrder:SELL] Error: " + ErrorDescription(GetLastError()));
         }
      }
      else
      {
         Print("[PlaceOrder] Nothing done");
      }
  }

Can any1 please help me out by pointing out what i am doing wrong here.

Regards,

Master

 
What was the Spread, what was the MODE_STOPLEVEL ?
 
RaptorUK:
What was the Spread, what was the MODE_STOPLEVEL ?

Thanx for your reply

SPREAD = 26.00000000

STOPLEVEL = 0.00000000

BTW the TP and SL value i have set are more than the spread

Regards,

Master

 
Master.Aurora:

Thanx for your reply

STOPLEVEL = 0.00000000

Probably an ECN Broker . . you have to send the order with TP & SL = 0 the do an OrderModify to add the TP and SL to the order . . .

http://crum.be/ecn

 
  1. SL = Ask - StopLossPips * Point;
             TP = Ask + TakeProfitPips * Point;
             Print("==-----ORDER SENDING PERIMETERS-----==");
             Print("SYMBOL IS = " + Symbol());
             Print("ORDER TYPE = OP_BUY");
    On a buy you OPEN at the ask, your stops are relative to the BID (likewise the sell code)

    Do you really want your SL=3 pips - spread and TP=6 pips + spread.?


  2. Adjust for 4/5 digit brokers, TP, SL, AND slippage. On ECN brokers you must open first and THEN set stops.

    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(..., 0,0,...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
           Alert("OrderModify failed: ", GetLastError());
         */
    
 
With this kind of SL and TP levels it can be also the Freezelevel the TP and SL can't be placed
 

Thanx for all your kind replies guys.

What i am doing now is that i am sending base order with SL & TP set to 0 and then i try to modify it afterwards. I have tried it on FXCM as well as OANDA MT4. It works flawlessly on OANDA but there's this same error in FXCM when i try to modify; i.e

2011.11.16 13:08:58 '2089354627': modification of order #61408632 sell 0.01 EURUSD at 1.34610 sl: 0.00000 tp: 0.00000 -> sl: 1.34636 tp: 1.34546 failed [Invalid S/L or T/P]

So any idea why this is happening?

I'd appreciate any help.

Thanx & Regards,

Master

 
Your Spread is 2.6 pips, you sold at the Bid of 1.3461, to close at SL it will be at Ask . . . your SL is at 1.34636 which is 2.6 pips away from your entry price . . so you are trying to set a SL which has just been hit . . it is too close.