Download MetaTrader 5
To add comments, please log in or register
All articles are available from MetaTrader 5. Contribute your own one!
amando
392
amando 2014.03.06 18:04 

Hello,

i'm looking for a method in my EA to check if the last orders was in profit or loss


if the last order was in loss, i will check if the order before was in loss

so in general to say, how many loss trades in a row

does anyone have an idea about his?

i use OrderMagicNumber() and OrderComment()

qjol
3243
qjol 2014.03.06 18:09  
amando
392
amando 2014.03.10 09:59  

and how i see, how many order in a row are with loss

means, i want only to count, how many orders away is the last profit order

Keith Watford
Moderator
7906
Keith Watford 2014.03.10 10:44  
amando:

and how i see, how many order in a row are with loss

means, i want only to count, how many orders away is the last profit order


How do you want to order them, by open time or close time?
amando
392
amando 2014.03.10 11:54  
GumRai:

How do you want to order them, by open time or close time?

My opionion was to order it at ticket number, this means open time if i'm right

Keith Watford
Moderator
7906
Keith Watford 2014.03.11 03:40  
amando:

My opionion was to order it at ticket number, this means open time if i'm right


I've adapted one of my functions to do what you want.

//-------Function to count closed cosecutive losing trades counting from last 

int ConsecutiveLosses()
{
  int consecutive_loss;         //The variable that holds the number of consecutive losses counting from the latest
                                //order open time (closed trades)
  int counter = 0;
  datetime opentime[];
  double profit[];
  for(int index=0;index<OrdersHistoryTotal();index++)
     {
     if(!OrderSelect(index,SELECT_BY_POS,MODE_HISTORY) )
        continue;
     else
        if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol() )
        {
        counter++ ;
        ArrayResize( opentime, counter);
        ArrayResize( profit, counter);
        opentime[counter -1]=OrderOpenTime();  //If you change OrderOpenTime() to OrderCloseTime() it will calculate using 
        profit[counter -1]=OrderProfit();      // close time instead of open time
        }
     }   
  int orderarray [];
  ArrayResize( orderarray, counter);
  datetime copyopentime[];
  ArrayResize( copyopentime, counter);
  ArrayCopy(copyopentime,opentime);
  
  for(int x=counter-1;x>=0;x--)
     {
     int latest = ArrayMaximum(copyopentime,WHOLE_ARRAY,0) ;
     orderarray[x]=latest;      
     copyopentime[latest] = 0;
     }
  
  for(int x=counter-1;x>=0;x--)
     {
     int pos = orderarray[x];
     if(profit[pos]<0)
        consecutive_loss++;
     else
        break;
     //Print(" Profit = ",profit[pos]) ;
     }
   return(consecutive_loss);
}
amando
392
amando 2014.03.11 07:40  
GumRai:


I've adapted one of my functions to do what you want.


Thanks a lot,

how do you use it?

as indicator or as function (void) in an EA?

Keith Watford
Moderator
7906
Keith Watford 2014.03.11 08:45  
amando:


Thanks a lot,

how do you use it?

as indicator or as function (void) in an EA?


I actually said that it is a function

It's an integer function as it returns an integer

/
To add comments, please log in or register