String compare problem with order type

 

Hi,

I'm making an EA to work with fratcal and I have a problem with string comparison with type of order. On a uptrend, when an Upper Fractal (new high) appears it should send an modify order but when I call the function the string comparison doesn´t work. Let's see:

When there is an order Sell running and it appear a breakout of last High:

                  if (CountOrders("OP_SELL") == 1) ModifyOrders("OP_SELL");

 Then on the function "ModifyOrders" this "ifs" aren't working:

void ModifyOrders(string sTypeOrder)
  {
   int CountOrders = 0, IndexSave = 0, OrderTypeNum = 0;
   //Converte o tipo de ordem   
   if(sTypeOrder == "OP_BUY") OrderTypeNum = 0;
   if(sTypeOrder == "OP_SELL") OrderTypeNum = 1;
   if(sTypeOrder == "OP_BUYLIMIT") OrderTypeNum = 2;
   if(sTypeOrder == "OP_SELLLIMIT")  OrderTypeNum = 3;  
   if(sTypeOrder == "OP_BUYSTOP") OrderTypeNum = 4;
   if(sTypeOrder == "OP_SELLSTOP")  OrderTypeNum = 5;  
   else OrderTypeNum = -1;
   
   Print("*** Função Modificação de ordens ***: Order Number = ", OrderTypeNum, " TypeOrder: ", sTypeOrder);
    
   for(PositionIndex = OrdersTotal()-1; PositionIndex >= 0; PositionIndex --) //  <-- for loop to loop through all Orders . .   COUNT DOWN TO ZERO !
     {
      if(!OrderSelect(PositionIndex,SELECT_BY_POS,MODE_TRADES)) continue;   // <-- if the OrderSelect fails advance the loop to the next PositionIndex
         {
         if( OrderMagicNumber() == iMagicNum && OrderSymbol() == Symbol() && (OrderType() == OrderTypeNum))
            {
            CountOrders = CountOrders + 1;
            IndexSave = PositionIndex;
            Print("Posição do índice de ordens: ", IndexSave);
            }
         }
     }
.......
 

I have already tried the 

!StringCompare(sTypeOrder, "OP_BUY",false)

 and the result is always the same:

  2006.03.22 00:00  teste2 EURUSD,Daily: *** Função Modificação de ordens ***: Order Number = -1 TypeOrder: OP_BUY

 

 I think string are alright and even with case sensitive it seems diferent!

 

Case function doesn't work, so can you help me? 

 
Duarte Silva:

I have already tried the 

 and the result is always the same:

  2006.03.22 00:00  teste2 EURUSD,Daily: *** Função Modificação de ordens ***: Order Number = -1 TypeOrder: OP_BUY

 

 I think string are alright and even with case sensitive it seems diferent!

 

Case function doesn't work, so can you help me? 

OP_BUY

And those others are Trade operation enumerations, not strings.

EnumToString()
EnumToString(OrderType())

Or can use a switch in stead:

switch(OrderType())
  {
   case OP_BUY:
     //Do something...
      break;

   case OP_SELL:
     //Do something else...
      break;

   case OP_BUYLIMIT:
     //Etc...
      break;

   case OP_SELLLIMIT:

      break;

   case OP_BUYSTOP:

      break;

   case OP_SELLSTOP:

      break;
  }


Those values already have integer values.

ID

Value

Description

OP_BUY

0

Buy operation

OP_SELL

1

Sell operation

OP_BUYLIMIT

2

Buy limit pending order

OP_SELLLIMIT

3

Sell limit pending order

OP_BUYSTOP

4

Buy stop pending order

OP_SELLSTOP

5

Sell stop pending order

 

Have to use else if.

if(sTypeOrder == "OP_BUY") OrderTypeNum = 0;
else if(sTypeOrder == "OP_SELL") OrderTypeNum = 1;
else if(sTypeOrder == "OP_BUYLIMIT") OrderTypeNum = 2;
else if(sTypeOrder == "OP_SELLLIMIT")  OrderTypeNum = 3;  
else if(sTypeOrder == "OP_BUYSTOP") OrderTypeNum = 4;
else if(sTypeOrder == "OP_SELLSTOP")  OrderTypeNum = 5;  
else OrderTypeNum = -1;
 
Marco vd Heijden:

And those others are Trade operation enumerations, not strings.

Or can use a switch in stead:


Those values already have integer values.

ID

Value

Description

OP_BUY

0

Buy operation

OP_SELL

1

Sell operation

OP_BUYLIMIT

2

Buy limit pending order

OP_SELLLIMIT

3

Sell limit pending order

OP_BUYSTOP

4

Buy stop pending order

OP_SELLSTOP

5

Sell stop pending order

Hi Marco,

I understand that OP_BUY is an integer but i woul d like to use the string to be more explicit in the code when calling for modifyOrders Function. But Case it seems a good option and I didn't remenber how to use the integer because it isn't explicit ate firts view.

 

Thanks for you help. 

 
Ernst Van Der Merwe:

Have to use else if.

Thanks for the help Ernst. Best regards.