Download MetaTrader 5

get last closed order lot size

To add comments, please log in or register
Ahmed Tawfik
348
Ahmed Tawfik  

Hello  every one 

the Below Function is to get the Last order lot size and multiply it by 2 it is is lose trade but it is not working properly , can you help 

double fLotSize()

{

double fnewlot=Lot_size;

int i =OrdersHistoryTotal();

for (i;i>=0;i--)

{

    if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false){GetLastError();} 

    {

    if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic_no)

    {

    if (OrderType()==OP_BUY||OrderType()==OP_SELL)

    {

    if (OrderProfit()<0){(fnewlot=(OrderLots()*2));}

    }    

    else if ( OrderProfit()>0){(fnewlot=Lot_size);}

    }

    else (fnewlot=Lot_size);

    }

    }

    return(fnewlot);

    }

nicholishen
1090
nicholishen  
Ahmed Tawfik:

Hello  every one 

the Below Function is to get the Last order lot size and multiply it by 2 it is is lose trade but it is not working properly , can you help 


double fLotSize()

{

double fnewlot=Lot_size;

int i =OrdersHistoryTotal();

for (i;i>=0;i--)

{

    if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false){GetLastError();} 

    {

    if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic_no)

    {

    if (OrderType()==OP_BUY||OrderType()==OP_SELL)

    {

    if (OrderProfit()<0){(fnewlot=(OrderLots()*2));}

    }    

    else if ( OrderProfit()>0){(fnewlot=Lot_size);}

    }

    else (fnewlot=Lot_size);

    }

    }

    return(fnewlot);

    }



First off, what does the last order mean? The last opened order? The last closed order? Next you need to sort them programmatically in order to work with them. So for example if you said, "my criteria for 'last order' really means the most recently opened order", then you would need to sort the history pool by OrderOpenTime. Below is an example using the MQL4OrderPool class. BTW, next time you post code, please use the SRC button.

int LotSize(int magic,double start_lot_size)
{
   MQL4OrderPool pool;
   pool.Init(Symbol(),magic,MODE_HISTORY,ORDERS_FILLED,SORT_OPEN_TIME_DESCENDING);
   int losing = 0;
   if(pool.Total()==0)
      return start_lot_size;
   return NormalizeDouble(pool[0].OrderLots() * 2, 2);
}
Files:
Ahmed Tawfik
348
Ahmed Tawfik  

first of all thanks ,

2nd this is my first post ever here , i will use the SRC next Time

It took me long time to find My post again :)

Yes , what I meant my last order , is the most recent closed order

as for the code can you explain how it works , thanks

To add comments, please log in or register