function to count loss trades in trading session

 
Can one of you skilled programmers clue me in on a good way to keep a running total of the loosing trades over a trading session?

I would like my EA to count the loosing trades from my trade history based on magic number and date. I can then have the EA stop trading for the remainder of the session when some number of loosing trades is reached.

Basically if someone can show me a code snippet that would return a aggregate count of the loosing trades based on magic number and date I would be elated.

Thanks
Will
 

Try this. Apologies - for some reason SRC button seems not to be working for me just now.


int myLosingOrders = 0;


int fnLosingOrdersCheck()

{

iOrders = OrdersHistoryTotal()-1;

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

{

OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

if (OrderSymbol() == Symbol()

&& OrderMagicNumber() == myMagicNumber

&& TimeDayOfYear(OrderOpenTime()) == DayOfYear()

&& TimeYear(OrderOpenTime()) == Year()

&& OrderProfit() < 0)

{

myLosingOrders++;

}

}

return(myLosingOrders);

}


CB

 
cloudbreaker wrote >>

Try this. Apologies - for some reason SRC button seems not to be working for me just now.

int myLosingOrders = 0;

int fnLosingOrdersCheck()

{

iOrders = OrdersHistoryTotal()-1;

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

{

OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

if (OrderSymbol() == Symbol()

&& OrderMagicNumber() == myMagicNumber

&& TimeDayOfYear(OrderOpenTime()) == DayOfYear()

&& TimeYear(OrderOpenTime()) == Year()

&& OrderProfit() < 0)

{

myLosingOrders++;

}

}

return(myLosingOrders);

}

CB

Thanks

Works perfectly!!

Reason: