ArrayMinimum

 

Array created to grab all details for open and pending orders. Can call up array to display order information on the chart via the Comments function. However ArrayMinimum refuses to grab the index for OrderProfit to display the single order with the greatest floating loss. Please have a look? Here is the code...

   AllOrdersInit(); //CALL FUNCTION
   int minValueIndex;
   if ( _ExpertOrdersTotal > 0 )
   {
      string OrdersList = StringConcatenate(Symbol(), " DIAGNOSTICS HUD:\n\n");
      for ( int n = 0; n < _ExpertOrdersTotal; n++ ) //ORIGINAL ARRAY CODE SAYS TO LOOP THIS WAY
         {
         if (_OrderType[n] == 0 || _OrderType[n] == 1)
            {
               minValueIndex = ArrayMinimum ( _OrderProfit[n] ); //NOT WORKING
               OrdersList = StringConcatenate( OrdersList, "Order Ticket: ", _OrderTicket[n],
               " | Order Open Time: ", TimeToStr( _OrderOpenTime[n], 0),
               " | Order Type: ", DoubleToStr( _OrderType[n], 2),
               " | Profit/Loss: ", DoubleToStr( _OrderProfit[n], 2), //THIS WORKS FINE - shows floating loss for all open orders however ArrayMinimum no go.
               " | Minimum Profit/Loss = ", DoubleToStr( _OrderProfit[minValueIndex], 2), //NOT WORKING
               "\n" );
            }
         }

What I'm trying to achieve is to close the single open order with the highest floating loss when Max Orders are reached. All this done by calling the AllOrdersInit() funtion. Thanks!

 

minValueIndex = ArrayMinimum( _OrderProfit ,0,0);

 

phy now I owe you a 1/2 dozen beers, works a treat. Cheers!

in ( _OrderProfit ,0 ,0) what do the 0's represent as I thought the last 0 was decimal point values?

 

Documentation is part of the editor

Select ArrayMinimum and hit F1 key

int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)
Searches for the element with minimum value. The function returns position of this minimum element in the array.

Parameters:

array[] - The numeric array to search in.
count - The amount of elements to search in.
start - Initial search index.

Sample:
double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
int    minValueidx=ArrayMinimum(num_array);
Print("Min value = ", num_array[minValueIdx]);
 

I was using the documentaion on this site and didn't know it was built into the editor. However I did use this information but interpreted it incorrectly.

Yes I am a rookie...

 

Your editor should have tool box (bottom) and navigator(right), accessible from View menu.

They are detachable, if you like.

Check out all the tabs

Reason: