Warning Message: possible use of uninitialized variable 'ordticket'

 

I get the follwing warning message. how to resolve the issue?

Warning Message: possible use of uninitialized variable 'ordticket'

void ClosePctPartial()
{
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];
    double lots = 0;
    for (int i = 0; i < orderstotal; i++)
    {
        bool BuyVar=OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 9)
        {
            continue;
        }
        ordticket[orders][0] = (int)OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    if (orders > 1)
    {
        ArrayResize(ordticket,orders);
        ArraySort(ordticket);
    }
    for (int i = 0; i < orders; i++)
    {
        if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
        {
            lots = OrderLots()*LockFirstProfitPercent/100;
            lots=NormalizeDouble(lots, NDigits);
            bool ret = OrderClose(OrderTicket(), lots, OrderClosePrice(), 4, Red);
            if (ret == false)
            Print("OrderClose() error - ", ErrorDescription(GetLastError()));
           
        }
    }
    func1();
    func2();

   

}


Support is appreciated...

 

I have never had that warning for an array.

Maybe it is because you are not using a dynamic array which means that the ArrayResize() will not work.

    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[][2];
    ArrayResize(ordticket,orderstotal);
    double lots = 0;
    for (int i = 0; i < orderstotal; i++)
    {
        bool BuyVar=OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 9)
        {
            continue;
        }
        ordticket[orders][0] = (int)OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    ArrayResize(ordticket,orders);

would possibly not give you the warning 

EDIT: changed a typo after reading the following post 

 
GumRai:

I have never had that warning for an array.

Maybe it is because you are not using a dynamic array which means that the ArrayResize() will not work.

would possibly not give you the warning 


    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];                         //NOTHING CHANGED
    ArrayResize(ordticket,orderstotal);          //INSERTED
    double lots = 0;
    for (int i = 0; i < orderstotal; i++)
    {
        bool BuyVar=OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 9)
        {
            continue;
        }
        ordticket[orders][0] = (int)OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    ArrayResize(ordticket,orders);               //INSERTED
No Warnings. But as you said i have not changed int ordticket[0][2]; instead of ordticket[30][2];
 
sheriffonline:

changing int ordticket[0][2];

says error as '[' - invalid index value

Sorry, my typing finger must have slipped

int ordticket[][2];

 of course the [] should be empty

 
sheriffonline:

No Warnings. But as you said i have not changed int ordticket[0][2]; instead of ordticket[30][2];

Well, learn something new every day

    int ordticket[30][2];                  
    Print(ArrayRange(ordticket,0));
    ArrayResize(ordticket,5);         
    Print(ArrayRange(ordticket,0));
    ArrayResize(ordticket,40);         
    Print(ArrayRange(ordticket,0)); 

 I thought that static arrays could not be resized, but after your post I tried this bit of code and it seems that they can.

In the documentation for ArrayResize()

The function can be applied only to dynamic arrays 

 
sheriffonline:

I get the follwing warning message. how to resolve the issue?

Warning Message: possible use of uninitialized variable 'ordticket'



Support is appreciated...

int ordticket[30][2]={0};
Or dynamic array as point by GumRai.
 
GumRai:

Well, learn something new every day

 I thought that static arrays could not be resized, but after your post I tried this bit of code and it seems that they can.

In the documentation for ArrayResize()


Good catch, you should report this bug to Metaquotes. (With mql5 you get a warning and the array is not resized).
Reason: