Possible loss of data due to type conversion.

To add comments, please log in or register
Julio Guerra
376
Julio Guerra  

How to remove a warning in MLQ4?

In this code used to close operations, 

void CloseOrderbuyl(){

    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[][2];
    for (int i = 0; i < orderstotal; i++)
   {bool sel = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != OrderId+1)
       {continue;}
       ordticket[orders][0] = OrderOpenTime();
       ordticket[orders][1] = OrderTicket();
        orders++;}if (orders > 1)
    {ArrayResize(ordticket,orders);
     ArraySort(ordticket);}int i = 0;for (i = 0; i < orders; i++)
   {if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
   {bool ret = OrderClose(OrderTicket(),  OrderLots(), OrderClosePrice(), 4, Red);
    if (ret == false)Print("OrderClose() error - ", ErrorDescription(GetLastError()));}}}

appears a warning "possible loss of data due to type conversion" in the line shown below.

   ordticket[orders][0] = OrderOpenTime();

Thanks in advance for any possible help. I will appreciate it.


Francesco Rubeo
3926
Francesco Rubeo  
Julio Guerra:

How to remove a warning in MLQ4?

In this code used to close operations, 

appears a warning "possible loss of data due to type conversion" in the line shown below.


Thanks in advance for any possible help. I will appreciate it.


just put (int) before OrderOpenTime()

So it will looks like: ordticket[orders][0] = (int)OrderOpenTime();

whroeder1
18099
whroeder1  
Francesco Rubeo:

just put (int) before OrderOpenTime()

So it will looks like: ordticket[orders][0] = (int)OrderOpenTime();

  1. You can do that but a long (a datetime) will not fit in an int.

  2.  int ordticket[][2];
    :
           ordticket[orders][0] = OrderOpenTime();
           ordticket[orders][1] = OrderTicket();
    Don't use a 2D array. Use a 1D array of a structure.
    struct Orders{
       int ticket;
       datetime OOT;
    }
    Orders ordticket[];
    :
           ordticket[orders].OOT = OrderOpenTime();
           ordticket[orders].ticket = OrderTicket();

Julio Guerra
376
Julio Guerra  
Francesco Rubeo:

just put (int) before OrderOpenTime()

So it will looks like: ordticket[orders][0] = (int)OrderOpenTime();

Thank you. The (int) addition worked fine. Have a good day.

Julio Guerra
376
Julio Guerra  
whroeder1:
  1. You can do that but a long (a datetime) will not fit in an int.

  2. Don't use a 2D array. Use a 1D array of a structure.

I tried your code and appeared not only several warnings, but many mistakes too. Maybe need to be positioned differently. Thank you for the clarification. Have a good day too.

To add comments, please log in or register