Warning Message: possible use of uninitialized variable 'ordticket'

Back to topics list To post a new topic, please log in or register
avatar
273
sheriffonline 2015.08.29 15:51
 

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...

avatar
Moderator
3418
GumRai 2015.08.29 18:45 #
 

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 

avatar
273
sheriffonline 2015.08.29 19:56 #
 
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];

avatar
Moderator
3418
GumRai 2015.08.29 20:08 #
 
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

avatar
Moderator
3418
GumRai 2015.08.29 20:27 #
 
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 


avatar
125
zirkoner 2015.08.29 20:52 #
 
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.
avatar
125
zirkoner 2015.08.29 21:12 #
 
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).
Back to topics list  

To add comments, please log in or register