Order filling type problem. Help?

 

Hey gang, I've been at this one for a couple hours with no success yet.

I've tried 2 brokers so far with the EA I'm porting over from MT4. One works fine, and on OspreyFX I get a retcode error 10030: Invalid order filling type.

Print("ORDER_FILLING_FOK=" + (string)IsFillingTypeAllowed(_Symbol, ORDER_FILLING_FOK) +
      ", ORDER_FILLING_IOC=" + (string)IsFillingTypeAllowed(_Symbol, ORDER_FILLING_IOC) +
      ", ORDER_FILLING_BOC=" + (string)IsFillingTypeAllowed(_Symbol, ORDER_FILLING_BOC) + 
      ", ORDER_FILLING_RETURN=" + (string)IsFillingTypeAllowed(_Symbol, ORDER_FILLING_RETURN) + 
      ", SYMBOL_FILLING_FOK=" + (string)IsFillingTypeAllowed(_Symbol, SYMBOL_FILLING_FOK) + 
      ", SYMBOL_FILLING_FOK=" + (string)IsFillingTypeAllowed(_Symbol, SYMBOL_FILLING_FOK));

returns true for types ORDER_FILLING_FOK and ORDER_FILLING_RETURN.

I've got

int orderFillingType = 0;
      if(IsFillingTypeAllowed(_Symbol, ORDER_FILLING_FOK)) orderFillingType = ORDER_FILLING_FOK;
      else if(IsFillingTypeAllowed(_Symbol, ORDER_FILLING_IOC)) orderFillingType = ORDER_FILLING_IOC;
      else if(IsFillingTypeAllowed(_Symbol, ORDER_FILLING_BOC)) orderFillingType = ORDER_FILLING_BOC;
      else if(IsFillingTypeAllowed(_Symbol, ORDER_FILLING_RETURN)) orderFillingType = ORDER_FILLING_RETURN;
      else if(IsFillingTypeAllowed(_Symbol, SYMBOL_FILLING_FOK)) orderFillingType = SYMBOL_FILLING_FOK;
      else if(IsFillingTypeAllowed(_Symbol, SYMBOL_FILLING_FOK)) orderFillingType = SYMBOL_FILLING_IOC;

passing my order type enum to my trade request

MqlTradeRequest request={};
      MqlTradeResult result={};
      request.action = TRADE_ACTION_DEAL;// Market
      request.magic = MagicNumber;
      request.symbol = _Symbol;
      request.volume = lotSize;
      request.sl = slPrice;
      request.tp = tpPrice;
      request.type = orderType;
      request.price = op;
      request.deviation = slippage;
      request.comment = StringFormat("%.2f", slPrice) + "/" + slSizeText;
      request.type_filling = orderFillingType;
      
      if(OrderSend(request,result));
      else
      {
         Alert(StringFormat("%s error %u: %s. Retcode %u: %s. %u deal=%I64u  order=%I64u",__FUNCTION__, _LastError, errortext(_LastError), result.retcode, retcodeText(result.retcode), result.deal,result.order));
         PlaySound("expert.wav");
         return false;
      }

but I still end up with this error.

Even when I replace my orderFillingType variable with the enum itself I still get this error.

Any ideas what I'm doing wrong or what I should be looking into here?

 

The filling type are bit flags, so you need to isolate the respective bit by masking it.

This a short snippet on how I decide on the filling type ...

ENUM_ORDER_TYPE_FILLING g_eOrderFillType = ORDER_FILLING_FOK; // Order Fill Type

...

// Set Filling Type for Current Symbol
   // Get possible filling policy types
      uint nFilling = (uint) SymbolInfoInteger( _Symbol, SYMBOL_FILLING_MODE );
   // Decide on filling policy type
      if( ( nFilling & SYMBOL_FILLING_FOK ) == SYMBOL_FILLING_FOK )
         g_eOrderFillType = ORDER_FILLING_FOK;
      else
      {
         if( ( nFilling & SYMBOL_FILLING_IOC ) == SYMBOL_FILLING_IOC )
            g_eOrderFillType = ORDER_FILLING_IOC;
      };
 
Fernando Carreiro #:

The filling type are bit flags, so you need to isolate the respective bit by masking it.

This a short snippet on how I decide on the filling type ...

This works, you're amazing, thank you!

I'm doing some reading trying to understand what a bit flag is and what it means to mask it. Not very intuitive for me. I'll have to keep reading.

Followup question: I'm getting an 'implicit enum conversion' warning for this line

request.type_filling = orderFillingType; //(g_eOrderFillType in your code)

orerFillingType, as shown above, has been initialized as int type.

I'd normally address this (hopefully correctly?!) by typecasting it, but I'm not sure how to typecast this particular enum?

 
rrsch #:

This works, you're amazing, thank you!

I'm doing some reading trying to understand what a bit flag is and what it means to mask it. Not very intuitive for me. I'll have to keep reading.

Followup question: I'm getting an 'implicit enum conversion' warning for this line

orerFillingType, as shown above, has been initialized as int type.

I'd normally address this (hopefully correctly?!) by typecasting it, but I'm not sure how to typecast this particular enum?

I have updated my previous post ...

ENUM_ORDER_TYPE_FILLING g_eOrderFillType = ORDER_FILLING_FOK; // Order Fill Type

So, when in doubt, research the documentation ...

struct MqlTradeRequest
  {
   ENUM_TRADE_REQUEST_ACTIONS    action;           // Trade operation type
   ulong                         magic;            // Expert Advisor ID (magic number)
   ulong                         order;            // Order ticket
   string                        symbol;           // Trade symbol
   double                        volume;           // Requested volume for a deal in lots
   double                        price;            // Price
   double                        stoplimit;        // StopLimit level of the order
   double                        sl;               // Stop Loss level of the order
   double                        tp;               // Take Profit level of the order
   ulong                         deviation;        // Maximal possible deviation from the requested price
   ENUM_ORDER_TYPE               type;             // Order type
   ENUM_ORDER_TYPE_FILLING       type_filling;     // Order execution type
   ENUM_ORDER_TYPE_TIME          type_time;        // Order expiration type
   datetime                      expiration;       // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
   string                        comment;          // Order comment
   ulong                         position;         // Position ticket
   ulong                         position_by;      // The ticket of an opposite position
  };
 
Fernando Carreiro #:
So, when in doubt, research the documentation ...

Great, makes perfect sense. Thanks.

" So, when in doubt, research the documentation ..."

Believe me, I try! 🥵

I appreciate the help.