Download MetaTrader 5

Problems with orders, take profit and stop loss: Error 130

To add comments, please log in or register
No time to learn MQL5? The source code library is at your service!
Iason Solomos
382
Iason Solomos 2016.03.28 23:06 

I have a simple price action EA. I think the "business logic" works fine, from what I've seen in the tester, but I think there is a problem with the creation and modification of orders. This is for example the Buy function:

 

void Buy(string comm)

  {

      double op=0,sl=0,tp=0; 

      op = NormalizeDouble(Ask,Digits);  

      //CalcLot();            

      if (AccountFreeMarginCheck(Symbol(),OP_BUY,Lots)<=0 || GetLastError()==134) 

      {

        Print("Νε δξρςΰςξχνξ ρβξαξδνϋυ ρπεδρςβ δλ ξςκπϋςθ ξπδεπΰ BUY ξαϊεμξμ: " + DoubleToStr(Lots,2));

        return;

      }        

      Print("Βϋρςΰβλεμ ξπδεπ BUY (v=" + DoubleToStr(Lots, 2) +"), ρ οΰπΰμεςπΰμθ: OP=" + DoubleToStr(op,Digits) +"; SL=" + DoubleToStr(sl,Digits) + "; TP=" + DoubleToStr(tp,Digits));

      int Ticket = OrderSend(Symbol(), OP_BUY, Lots, op, Slippage, 0, 0, comm, Magic, 0 ,Blue); 

      if (PrintError(357)==0)

      {        

        if (OrderSelect( Ticket, SELECT_BY_TICKET)==false) return;

        op = NormalizeDouble(OrderOpenPrice(),Digits);          

        tp = NormalizeDouble(op + (TakeProfit)*Point,Digits);      

        if (TakeProfit==0) tp=0;

        sl = NormalizeDouble(op - (StopLoss)*Point,Digits);   

        if (StopLoss==0) sl=0;

        if (sl!=0 || tp!=0) 

        {

          Print("Μξδθτθφθπσεμ βϋρςΰβλεννϋι ξπδεπ BUY #" + IntegerToString(Ticket));

          if (OrderModify( Ticket, op, sl, tp, 0, Yellow)==false)    

            PrintError(369);                                               

        }  

      }        

  } 

 

This is with the following default tp and sl:

 

extern int       TakeProfit=30;       

extern int       StopLoss=15;  

 

A little information, I am using this EA with Pepperstone, who say they are an ECN broker, with 5 digits. I think the way this code is written it caters for the ECN part, meaning I think that everything up to the Ordersend call which sets stop loss and take profit to 0, works.  So the EA is able to initiate orders. My problem is that, from what it seems, the OrderModify doesn't work. This means that any order that is made, there is no stop loss or take profit (I think OrderModify is responsible for this). Unfortunately I don't remember whether I saw the error 369 on the Experts tab, so something else might be the problem too. I am setting stop loss to 8 pips and take profit to 2.5, but it doesn't work. By the way, Pepperstone has stop_level 0 so I think that I can set this stop loss and tp with them. Anyone have any idea what might be wrong?

 

 

Update: It seems I am getting the Error 130: Invalid stops. Can someone please help with this? 

To add comments, please log in or register