Order Modify and Order Send Error

 

Hello everyone :) im having some issues with mq4. i try to get my ea validated on mql5 but its always giving me these errors i cannot figure out why:

 2022.05.12 05:17:39  EA__1 EURUSD,H1: OrderModify error 1
 2022.05.17 09:05:29  EA__1 EURUSD,H1: OrderSend error 148
the ea is built to trade Xauusd so maybe it could cause the errors because its trying to test on EurUsd? I hope anyone is able to help me with that thank you very much in advance already for taking your time

  if ((InpManualInitGrid && orders_count == 0) || (!InpOpenOneCandle || (InpOpenOneCandle && vDatetimeUltCandleOpen != iTime(NULL, InpTimeframeBarOpen, 0))))
  {
    vDatetimeUltCandleOpen = iTime(NULL, InpTimeframeBarOpen, 0);
    if (long_condition)
    {
      if (buyer_lots + lots == seller_lots)
        lots = seller_lots + volume_min;
      ticket = OpenTrade(OP_BUY, lots, ask_price, vInpMagic, Grid);
      if (ticket > 0)
      {
        res = OrderSelect(ticket, SELECT_BY_TICKET);
        order_open_price = OrderOpenPrice();
        buyer_sum += order_open_price * lots;
        buyer_lots += lots;
        m_level = NormalizeDouble((buyer_sum - seller_sum) / (buyer_lots - seller_lots), Digits) + m_take;
        if (!m_hedging)
          level = m_level;
        else
          level = m_level + m_take;
        if (buyer_counter == 0)
          m_buyer = order_open_price;
        m_direction = 1;
        was_trade = true;
      }
    }

    if (short_condition)
    {
      if (seller_lots + lots == buyer_lots)
        lots = buyer_lots + volume_min;
      ticket = OpenTrade(OP_SELL, lots, bid_price, vInpMagic, Grid);
      if (ticket > 0)
      {
        res = OrderSelect(ticket, SELECT_BY_TICKET);
        order_open_price = OrderOpenPrice();
        seller_sum += order_open_price * lots;
        seller_lots += lots;
        m_level = NormalizeDouble((seller_sum - buyer_sum) / (seller_lots - buyer_lots), Digits) - m_take;
        if (!m_hedging)
          level = m_level;
        else
          level = m_level - m_take;
        if (seller_counter == 0)
          m_seller = order_open_price;
        m_direction = -1;
        was_trade = true;
      }
    }
  }
  if (InpEnableMinProfit  )
  {
    if (BuyProfit >= MinProfit && buyer_counter >= QtdTradesMinProfit)
      CloseAllTicket(OP_BUY, buy_ticket, vInpMagic);

    if (SellProfit >= MinProfit && seller_counter >= QtdTradesMinProfit)
      CloseAllTicket(OP_SELL, sell_ticket, vInpMagic);
  }

  //--- Setup Global Take Profit
  if (was_trade)
  {
    orders_total = OrdersTotal();
    for (index = orders_total - 1; index >= 0; index--)
    {
      if (!OrderSelect(index, SELECT_BY_POS, MODE_TRADES))
        continue;
      if (OrderMagicNumber() != vInpMagic || OrderSymbol() != m_symbol)
        continue;
      order_type = OrderType();
      if (m_direction > 0)
      {
        if (order_type == OP_BUY)
          res = OrderModify(OrderTicket(), OrderOpenPrice(), 0.0, level, 0);
        if (order_type == OP_SELL)
          res = OrderModify(OrderTicket(), OrderOpenPrice(), level, 0.0, 0);
      }
      if (m_direction < 0)
      {
        if (order_type == OP_BUY)
          res = OrderModify(OrderTicket(), OrderOpenPrice(), level, 0.0, 0);
        if (order_type == OP_SELL)
          res = OrderModify(OrderTicket(), OrderOpenPrice(), 0.0, level, 0);
      }
    }
  }
}
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. MARC ALBRECHT SCHMID: 2022.05.12 05:17:39 EA__1 EURUSD,H1: OrderModify error 1

    If you had used this, you would have found many threads: ERR_NO_RESULT

    You Server
    Change the SL to X It is at X!
    Change the SL to X It is at X!
    Change the SL to X You are insane

    Insanity: doing the same thing over and over again and expecting different results.
              Unknown

    Compute the new value, then check that you are moving the existing value at least a tick (in the currect direction).
              What is a TICK? - MQL4 programming forum (2014)

  3.       if (buyer_lots + lots == seller_lots)
    

    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 (2013)

  4.         if (order_type == OP_BUY)
              res = OrderModify(OrderTicket(), OrderOpenPrice(), 0.0, level, 0);
            if (order_type == OP_SELL)
              res = OrderModify(OrderTicket(), OrderOpenPrice(), level, 0.0, 0);
    
    Why are you setting a TP in one case and a SL in the other?

    Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin or leverage. No SL means you have infinite risk (on leveraged symbols). Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% account total.

    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce, the stop goes below the support. Then you compute your lot size.

    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP, but it takes account of the exchange rates of the pair vs. your account currency.)

    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
                Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

    4. You must normalize lots properly and check against min and max.

    5. You must also check Free Margin to avoid stop out

    6. For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

 
MARC ALBRECHT SCHMID2022.05.17 09:05:29 EA__1 EURUSD,H1: OrderSend error 148

Hello, regarding the second error, I believe that the link generated in your description already points to the solution to the problem: the EA, before trying to place a new order, must go through the checks below:

Reason: