Error 130 in live trade but not in testing

 

Hello guys,

I have run this in tester and haven't get any error, as soon I go to live trade I get error 130. Could you please give some thoughs to this?

This is the open order code I have in a separate file in the include folder, GetLotSize() is my money mngmt, dTakeProfit is set to 180 pips, dTakeProfit to 270 pips set as global variables.

int Buy(string strExpertName, int nMagicNumber)
{
        int nResult = -1;
        

        dLotSize = GetLotSize();
        
        if(AccountFreeMargin() < dLotSize * AccountBalance() || AccountFreeMargin() < 100)
                return(nResult);


        if(dTakeProfit == 0)
                dTp = 0;
        else
                dTp = NormalizeDouble(Ask,Digits) + NormalizeDouble((dTakeProfit*10*Point),Digits);
                
   if(dStopLoss == 0)
      dSl = 0;
   else
      dSl = NormalizeDouble(Ask,Digits) - NormalizeDouble((dStopLoss*10*Point),Digits);                 

        for(int nTry = 0; nTry < 10; nTry++)
        {
                log(" " + Day() + "." + Month() + "." + Year() + " " + Hour() + ":" + Minute() + ":" + Seconds());
                log(" Trying to open a buy order, attempt " + (nTry + 1));
                log("nAsk: " + Ask + ", StopLoss: " + dStopLoss + ", TakeProfit: " + dTakeProfit);
                log("StopLoss Level: " + dSl + ", TakeProfit Level: " + dTp);
                
                nResult = OrderSend(Symbol(), OP_BUY, dLotSize, NormalizeDouble(Ask,Digits), nSlip, dSl, dTp, strExpertName, nMagicNumber, 0, Blue);

                Sleep(10000);
                if(nResult != -1)
                {
                        log(" successfull !!!, Long Order Opened with Ticket No: "+nResult);
                        break;
                }
                else
                {
                   int nError = GetLastError(); 
                        log(" failed, error " + nError);
                        RefreshRates();
                }
        }       

        if(nResult == -1)
        {
                
                Alert(strExpertName + " after "+nTry+" attempts, buy error: " + nError + "\r\n Ask:" +  Ask + ", Stop Loss=" + dStopLoss + ", Take Profit=" + dTakeProfit);

                log(strExpertName + " after "+nTry+" attempts, buy error: " + nError + "\r\n  Ask: " +  Ask + ", Stop Loss=" + dStopLoss + ", Take Profit=" + dTakeProfit);
        }

        return(nResult);
}

This is the part of the code that calls Buy, ann_wise_long is my trigger signal to open a buy order.

   if (BuySignal && SellOrdersTotal < 1) 
    {
      debug (3, "Buy Signal!");
           if (ann_wise_long () > Delta)                             
            {
             debug (4, "Opening Long Pos!");
                  int LTick = Buy(Xpert, MagicNumber);
            }
           array_push(LongArray, LTick); 
           for (i = 0; i < AnnInputs; i++) 
            {
                   array_push(LongArray,InputVector[i]);      
            } 
    }       

And this is the output to file the first one is from the tester, the second from the live trade:

Buy Signal!
2011.04.05 - 14:05:00 - - - Wise long: 0.85173753
2011.04.05 - 14:05:00 - - -  5.4.2011 14:5:0
2011.04.05 - 14:05:00 - - -  Trying to open a buy order, attempt 1
2011.04.05 - 14:05:00 - - - nAsk: 1.41755000, StopLoss: 180, TakeProfit: 250
2011.04.05 - 14:05:00 - - - StopLoss Level: 1.39955000, TakeProfit Level: 1.44255000
2011.04.05 - 14:05:00 - - -  successfull !!!, Long Order Opened with Ticket No: 3116
2011.04.05 - 14:15:00 - - - Buy Signal!
2011.04.05 - 14:15:00 - - - Wise long: 0.84984159
2011.04.05 - 14:15:00 - - -  5.4.2011 14:15:0
2011.04.05 - 14:15:00 - - -  Trying to open a buy order, attempt 1
2011.04.05 - 14:15:00 - - - nAsk: 1.41814000, StopLoss: 180, TakeProfit: 250
2011.04.05 - 14:15:00 - - - StopLoss Level: 1.40014000, TakeProfit Level: 1.44314000
2011.04.05 - 14:15:00 - - -  successfull !!!, Long Order Opened with Ticket No: 3117
2011.04.05 - 14:30:00 - - - Buy Signal!
2011.04.05 - 14:30:00 - - - Wise long: 0.84644691
2011.04.05 - 14:30:00 - - -  5.4.2011 14:30:0
2011.04.05 - 14:30:00 - - -  Trying to open a buy order, attempt 1
2011.04.05 - 14:30:00 - - - nAsk: 1.41960000, StopLoss: 180, TakeProfit: 250
2011.04.05 - 14:30:00 - - - StopLoss Level: 1.40160000, TakeProfit Level: 1.44460000
2011.04.05 - 14:30:00 - - -  successfull !!!, Long Order Opened with Ticket No: 3118
2011.04.05 - 15:25:00 - - - Buy Signal!
2011.04.05 - 15:25:00 - - - Wise long: 0.77333093
2011.04.05 - 15:25:00 - - -  5.4.2011 15:25:0
2011.04.05 - 15:25:00 - - -  Trying to open a buy order, attempt 1
2011.04.05 - 15:25:00 - - - nAsk: 1.42225000, StopLoss: 180, TakeProfit: 250
2011.04.05 - 15:25:00 - - - StopLoss Level: 1.40425000, TakeProfit Level: 1.44725000
2011.04.05 - 15:25:00 - - -  successfull !!!, Long Order Opened with Ticket No: 3119
2011.04.05 - 15:30:00 - - - Buy Signal!
2011.04.05 - 15:30:00 - - - Wise long: 0.76426666
2011.04.05 - 15:30:00 - - -  5.4.2011 15:30:0
2011.04.05 - 15:30:00 - - -  Trying to open a buy order, attempt 1
2011.04.05 - 15:30:00 - - - nAsk: 1.42135000, StopLoss: 180, TakeProfit: 250
2011.04.05 - 15:30:00 - - - StopLoss Level: 1.40335000, TakeProfit Level: 1.44635000
2011.04.05 - 15:30:00 - - -  successfull !!!, Long Order Opened with Ticket No: 3120

Here the live trade:

2011.05.31 - 19:25:00 - - - Buy Signal!
2011.05.31 - 19:25:00 - - - Wise long: 0.82310605
2011.05.31 - 19:25:00 - - - Opening Long Pos!
2011.05.31 - 19:25:00 - - -  31.5.2011 19:25:0
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 1
2011.05.31 - 19:25:00 - - - nAsk: 1.43849000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:25:12
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 2
2011.05.31 - 19:25:00 - - - nAsk: 1.43851000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:25:23
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 3
2011.05.31 - 19:25:00 - - - nAsk: 1.43846000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:25:34
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 4
2011.05.31 - 19:25:00 - - - nAsk: 1.43853000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:25:44
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 5
2011.05.31 - 19:25:00 - - - nAsk: 1.43855000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:25:56
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 6
2011.05.31 - 19:25:00 - - - nAsk: 1.43847000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:26:6
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 7
2011.05.31 - 19:25:00 - - - nAsk: 1.43849000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:26:18
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 8
2011.05.31 - 19:25:00 - - - nAsk: 1.43851000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:26:29
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 9
2011.05.31 - 19:25:00 - - - nAsk: 1.43841000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - -  31.5.2011 19:26:40
2011.05.31 - 19:25:00 - - -  Trying to open a buy order, attempt 10
2011.05.31 - 19:25:00 - - - nAsk: 1.43842000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 19:25:00 - - - StopLoss Level: 1.42049000, TakeProfit Level: 1.46349000
2011.05.31 - 19:25:00 - - -  failed, error 130
2011.05.31 - 19:25:00 - - - NN_TRAININGafter 10 attempts, buy error: 130

As you can see the Buy order stop loss is 180 pips below the Ask price. Is it there any explanation why I get error 130 in live trade and not in testing withthe same EA?

Thanks.

 

Try sending the order without Sl and Tp.

 
ubzen:

Try sending the order without Sl and Tp.


Hi ubzen, I'll do. I just add a MarketInfo(Symbol(),MODE_STOPLEVEL) and I got this:

2011.05.31 - 21:00:00 - - - Buy Signal!
2011.05.31 - 21:00:00 - - - Wise long: 0.71709490
2011.05.31 - 21:00:00 - - - Opening Long Pos!
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 1
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 2
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 3
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 4
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 5
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 6
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 7
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 8
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:0:32
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 9
2011.05.31 - 21:00:00 - - - nAsk: 1.43989000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - -  31.5.2011 21:2:12
2011.05.31 - 21:00:00 - - -  Trying to open a buy order, attempt 10
2011.05.31 - 21:00:00 - - - nAsk: 1.43979000, StopLoss: 180, TakeProfit: 250
2011.05.31 - 21:00:00 - - - StopLoss Level: 1.42189000, TakeProfit Level: 1.46489000
2011.05.31 - 21:00:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:00:00 - - -  failed, error 130
2011.05.31 - 21:00:00 - - - NN_TRAINING after 10 attempts, buy error: 130

  Ask: 1.43974000, Stop Loss=180, Take Profit=250
 

Without the stop loss there isn't a problem :

2011.05.31 - 21:05:00 - - - Sell Signal!
2011.05.31 - 21:05:00 - - - Wise long: 0.71088575
2011.05.31 - 21:05:00 - - - Opening Short Pos!
2011.05.31 - 21:05:00 - - -  31.5.2011 21:8:11
2011.05.31 - 21:05:00 - - -  Trying to open a sell order, attempt 1
2011.05.31 - 21:05:00 - - - nBid: 1.43919000, StopLoss: 0, TakeProfit: 0
2011.05.31 - 21:05:00 - - - StopLoss Level: 0.00000000, TakeProfit Level: 0.00000000
2011.05.31 - 21:05:00 - - - STOPLEVEL=1.00000000
2011.05.31 - 21:05:00 - - -  successfull !!!!, Short Order Opened with Ticket No: 98305364
 
 
1121048:

Without the stop loss there isn't a problem :


I just figured out the problem, my broker doesn't accept S/L or T/P on OrderSend function, I have to mod the order to add S/L and T/P later.

No biggy but that sucks.

Thank ubzen.

 
There you go. I would have said that but ... I didn't know if your broker did or not. :)
 

Hi I encountered the same problem too. If I do OrderSend in EA for a buy or sell order with SL and TP included, I get the error.

Find it strange this is not allowed when the same can be done manually.

So no choice but to put 0 in SL and TP and use OrderModify.

So is this the way to code it ?

ticket = OrderSend(Symbol(), OP_BUY, LotSize,Ask, 2, 0, 0, "", Magic+2, 0,Green); //Do order send to open order without SL/TP and also get ticket number

OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()-0.0020,OrderOpenPrice()+0.0020,0); //Use the unique ticket number to modify the SL/TP.

Cheers,

hip

 
hip280:

So is this the way to code it ?

Plenty of example code if you search for it: ECN
 
//++++ 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(){                                                     OptParameters();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                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());
     */
Reason: