# Order History

481

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()

3245

481

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

Moderator
8293

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?
481

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

Moderator
8293

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
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);
}
```
481

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?

Moderator
8293

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