Array double

 

Hi 


i would like to select for example all the last short orders and create an array done in this way

order_short[number_by_order][properties];

for properties I mean: ticket, TP and SL, I will get it by OrderSelect and then OrderTicket(), OrderTakeProfit() and OrderStopLoss(); using a cycle "for" and counting the total orders.

I would like to know if it is possibile to resume all in the same array.

for example with order_short[0][3] i will find the SL of the last order.

 

i havent tried if it works yet, but something like this

(conta_ordini is a function already working that tells me how many orders there are, long or short)

double check_orders_short(void){
   
   int count_ord_short = conta_ordini(1);
   
   int prop_short[][3];
   int i;
   int a;
   
   for(i<count_ord_short; i=0; i++){
   
   OrderSelect(i,SELECT_BY_POS){
   
   for(a<3; a=1, a++){
   
   if(a==1){
    prop_short[i][1]= OrderTicket;
  }else if(a==2){
  
  prop_short[i][2]= OrderTakeProfit;
  }else if(a==3){
  
  prop_short[i][3]= OrderStopLoss;
  
  }
      } 
   }
   
   return prop_short[][];
     
   }
 
florenceale: i would like to select for example all the last short orders and create an array done in this way order_short[number_by_order][properties];

for properties I mean: ticket, TP and SL, I will get it by OrderSelect and then OrderTicket(), OrderTakeProfit() and OrderStopLoss(); using a cycle "for" and counting the total orders.

for example with order_short[0][3] i will find the SL of the last order.

  1. There is no "all the last." There is only one last.
  2. Don't create a double array. Create an array of a structure.
    struct Order{
     int ticket;
     double tp, sl;
    }
    Order order_short[]; int nShort=0;
    for(...)
       OrderSelect(
       ArrayResize(order_short...
       order_short[nShort].ticket =
       order_short[nShort].tp     =
       order_short[nShort].sl     =
       ++nShort;
    


 
whroeder1:
  1. There is no "all the last." There is only one last.
  2. Don't create a double array. Create an array of a structure.



thanks i will look to this

 

Or you could use a fully developed library if you know how to work with OOP.  This shows a couple different ways to achieve the same result. 

#include <MQL4OrderPool.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
   MQL4OrderPool history_filled;
   
   history_filled.Init(NULL,0,MODE_HISTORY,ORDERS_FILLED,SORT_CLOSE_TIME_DESCENDING);
 
   
   Print("There are ",history_filled.Total()," orders in the history for ",Symbol());
   
   history_filled.Sort(SORT_PROFIT_DESCENDING);
   Print("top 3 winning and losing trades by net profit.");
   for(int i=0;i<history_filled.Total()&&i<3;i++)
      Print(history_filled[i].OrderCloseTime()," ",(string)history_filled[i].OrderProfitNet());
   
   Print("________________________");
   
   MQL4Order *order = history_filled.GetLastNode();
   for(int i=0;i<3 && order!=NULL;i++,order=order.Prev())
      Print(order.OrderCloseTime()," ",(string)order.OrderProfitNet());
   
}


 

Files:
 

hi in this way the function is working


   double check_orders_try(void){
   
     static int count_ord_short = conta_ordini(1);
     static int total = OrdersTotal();
     static double prop_short[100][5];
     static int x=0;
     static int a=1;
     static int b=0;
     
   
   for(x=0; x < total; x++)
   {
  
   if((OrderSelect(x,SELECT_BY_POS))==TRUE){
  
    if(OrderType() == OP_SELL && b < count_ord_short){
   
    
         for(a=1; a < 4; a++){
  
        if(a==1){
           prop_short[b][1]= OrderTicket();
        }else if(a==2){
  
          prop_short[b][2]= OrderTakeProfit();
       
        }else if(a==3){
  
          prop_short[b][3]= OrderStopLoss();
  
        }}
      
          
    b++; 
   
    }}
   
        return prop_short[x][1];
        return prop_short[x][2];
        return prop_short[x][3];
  
   }
   
    b=0;
    a=1;
    x=0;
    count_ord_short = conta_ordini(1);
   
     
   }


if i make an alert or print inside the function its all right, but if i try to "pull out" the result from the function is not working yet. Maybe some mistakes with "return"


check_orders_try();

Alert(prop_short[0][1]);

^^ this is not working yet. If I do the same inside the function yes.

 

now it works...just 0 is the oldest order not the newest...i'll have to invert something maybe

 double check_orders_try(int array_part_1, int array_part_2){
   
     static int count_ord_short = conta_ordini(1);
     static int total = OrdersTotal();
     static double prop_short[100][5];
     static int x=0;
     static int a=1;
     static int b=0;
     
   
   for(x=0; x < total; x++)
   {
  
   if((OrderSelect(x,SELECT_BY_POS))==TRUE){
  
    if(OrderType() == OP_SELL && b < count_ord_short ){
   
    
         for(a=1; a < 4; a++){
  
        if(a==1){
           prop_short[b][1]= OrderTicket();
        }else if(a==2){
  
          prop_short[b][2]= OrderTakeProfit();
       
        }else if(a==3){
  
          prop_short[b][3]= OrderStopLoss();
  
        }}
     
     
    b++; 
   
    }}
         
   }
    
   
    return(prop_short[array_part_1][array_part_2]); 
 
    b=0;
    a=1;
    x=0;
    count_ord_short = conta_ordini(1);
   
     
   }


and the call


result_try = check_orders_try(2,3);

Print(result_try);
Reason: