Get the maximum value

 

Hi there. I am trying to obtain in a variable the maximum value of entry to the market of all the open positions. I've tried it with a for loop, going around it several times, but nothing. I can't get it to work. Could anyone help me? I pass you the code that was finally left ... Thank you all. Greetings.

 double ordenSup()
  {     
   for ( uint i= 0 ;i<totalOp;i++)
     {
       if ((ticket= OrderGetTicket (i))> 0 )
        {
         
         openPrice    = OrderGetDouble ( ORDER_PRICE_OPEN );
         if (openPrice>=precioSup)
         {
          precioSup=openPrice;
         }
        }
     } 
   return (precioSup);
  }
 
David Gancedo: I can't get it to work.

Initialize your precioSup before the loop.

 
William Roeder #:

Initialize your precioSup before the loop.

It's done.  I forgot to tell you.  Both priceSub and totalOp are generally started at the beginning of the code.
 

Okay. Well, I have rewritten the function. I can already get the opening price of an open position. But when there is more than one open position, the value is not updated, the first one that takes is kept. I put the code. Please someone help me. Sure it is silly, but being a newbie in programming I can not solve it. This is the code. Thanks

 

have you tried to update the totalOp = OrderTotal() and initialized precioSup variable immediately before the loop inside the "ordenSup" function ?


What did you mean by the value is not updated ? Where is the "ordenSup" function located in your code ?

 
Amine Abed #:

have you tried to update the totalOp = OrderTotal() and initialized precioSup variable immediately before the loop inside the "ordenSup" function ?


What did you mean by the value is not updated ? Where is the "ordenSup" function located in your code ?

Hi there. yes i start it before the for loop. anyway I commented that I rewrote the code. I don't know why it didn't appear in the post. As for what it means that it does not update the value, well that. When opening a position it shows me the opening price perfectly. but as I am opening new positions, the value does not refresh me, that is, it continues to return the value of the first open position