"Trade is disabled" message

 

Hello!

Here it is simple programm and it works sometimes not correct:

#property copyright "Copyright © 2012"
#property link      "vitalyaxxi@yahoo.com"
#include "include/stdlib.mqh"

extern double INDENT = 0.0001;   //indent for pending order
extern double STOP = 0.001;   //indent for setting stop-loss level

/*
This is a simple programm:
if there is no order on this symbol, we send 1 pending buy-stop order without stoploss and takeprofit levels (they are equal 0.0);
when pending order starts to work we are trying to set stoploss.

THE PROBLEM:
Stoploss level is been set not from the first attempt. In some cases we see in the logs notes like this:

modification of order #58570069 buy 0.10 GBPUSD at 1.61839 sl: 0.00000 tp: 0.00000 -> sl: 1.61739 tp: 0.00000 failed [Trade is disabled]

But trading for this EA is enabled, the button is pushed
*/

int init()
  {
   return(0);
  }

int deinit()
  {
   return(0);
  }

int start()
  {
   int i;
   bool is_orders_this_symbol = false;
   for (i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i, SELECT_BY_POS);
      if (OrderSymbol() == Symbol())
      {
         is_orders_this_symbol = true;
         break;
      }
   }
   if (!is_orders_this_symbol)
      OrderSend(Symbol(), OP_BUYSTOP, 0.1, Ask + INDENT, 5, 0.0, 0.0);
   else
   {
      if ((Ask >= OrderOpenPrice()) && (CompareDoubles(OrderStopLoss(), 0.0)))
         OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - STOP, 0.0, 0);
   }
   return(0);
  }
What could you say about it?
Files:
aaa.ex4  3 kb
 
_beast_:
Here it is simple programm and it works sometimes not correct:

What could you say about it?
  1. Attaching a ex4 is useless for us humans.
  2. INDENT is one pip. You can not put a pending order closer to market than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point which is typically 3 pips.
  3. You don't test return codes to find out why it wasn't working. If the orderSelect fails, then the OrderSymbol is meaningless. If the OrderSend fails you don't notify.
  4. You don't have wait for the market to get above the open prices. In fact if you wait, you have no stop at all.
   for (i = 0; i < OrdersTotal(); i++) if (
      OrderSelect(i, SELECT_BY_POS)
   && OrderSymbol() == Symbol()
// && magic number?
   ){
         is_orders_this_symbol = true;
         break;
   }
   if (!is_orders_this_symbol){
      int ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, Ask + INDENT, 5, 0.0, 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(), OrderOpenPrice() - STOP, 0.0, 0))
          Alert("OrderModify failed: ", GetLastError());
   }
 

Well, I initially disliked this code

   for (i = 0; i < OrdersTotal(); i++) if (
      OrderSelect(i, SELECT_BY_POS)
   && OrderSymbol() == Symbol()
// && magic number?
   ){
         is_orders_this_symbol = true;
         break;
   }
   if (!is_orders_this_symbol){
      int ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, Ask + INDENT, 5, 0.0, 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(), OrderOpenPrice() - STOP, 0.0, 0))
          Alert("OrderModify failed: ", GetLastError());
   }

Then I thought, perhaps it is a bit clever and neat, and I was just being a misery guts.

+ + + + +

but now I have changed my mind again and don't like it. If the OrderSelect (by ticket) fails the error is reported but there is no way to fix it. ( I don't think there is any mechanism by which that one can actually fail though.) If the OrderModify fails, a highly likely situation, again there is no remedy. I understand you are not writing the code for him, and it is not complete code, but it would require a repeated block of code to select by the ticket that we no longer know. Therefore the code is actually less efficient than it might at first appear. Which is not to say it is bad code, but it is not as good as it could be.

 

OK, I added testing return codes, increased INDENT value, but the problem still takes place - sometimes in log error 133 appears, trade is disabled.

I don't understand, why is it disabled, when it's enabled? This is what I want to hear from you, guys.

 
Always search before asking, thats how the rest of us get by. Link Here. And Documentations Here. Provided the Doc as your reference after you Print-Errors when testing.
 
_beast_:

OK, I added testing return codes, increased INDENT value, but the problem still takes place - sometimes in log error 133 appears, trade is disabled.

I don't understand, why is it disabled, when it's enabled? This is what I want to hear from you, guys.

Your Broker is not allowing you to trade . . . talk to your Broker.
 
ubzen:
Always search before asking, thats how the rest of us get by. Link Here. And Documentations Here. Provided the Doc as your reference after you Print-Errors when testing.

Of course, I searched before asking!

As I understood, 133 error means that trade is fully disabled. But with my account I can to trade manually, OrderSend() always works, but SOMETIMES OrderModify() returns this error.

Or do you want to say that it is anyway because of Broker, not MT4 terminal?

 
Or do you want to say that it is anyway because of Broker, not MT4 terminal? Yes.
Reason: