Need help counting consecutive profit orders and then resetting count after (x) amount of trades - page 2

 
RaptorUK:
Sorry but they don't . . . . you need better test data and you will see they don't . . unless you have a different definition of consecutive ?

I know where you are coming from. Because, if there is a losing trade inbetween, the count still continues, so therefore they are not "consecutive". Hence, that is why I asked if anyone can help me to add a few lines of code that will reset the current count if there is a loss trade. Been trying all morning/afternoon but to no avail, cannot get the count to reset after a loss. Can you help?
 
gangsta1:

I know where you are coming from. Because, if there is a losing trade inbetween, the count still continues, so therefore they are not "consecutive". Hence, that is why I asked if anyone can help me to add a few lines of code that will reset the current count if there is a loss trade. Been trying all morning/afternoon but to no avail, cannot get the count to reset after a loss. Can you help?

You could do this . . .

bool ProfitHistoryOrdersCount(int count){
    int ProfitHistoryOrdersCount = 0;
    for (int i = OrdersHistoryTotal()-1; i >=0; i--) if(
        OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)
    &&  OrderSymbol()      == Symbol()
    &&  OrderMagicNumber() == Magic
    &&  OrderType()        <= OP_SELL  
    )   
      {
      if (OrderProfit() > 0) ProfitHistoryOrdersCount++;
      if (ProfitHistoryOrdersCount == count) return(true);
      if(OrderProfit() <= 0) return (false);
      } 
}

call the function and pass the count for the number of consecutive profit trades you want, e.g. for 5 use this . . .

bool = ProfitHistoryOrdersCount(5);
 
RaptorUK:

You could do this . . .

call the function and pass the count for the number of consecutive profit trades you want, e.g. for 5 use this . . .


Works a treat, thank you so much. I had been pulling my hair out over this!
 
gangsta1:

Works a treat, thank you so much. I had been pulling my hair out over this!

You are welcome. It's not the definitive answer yet though . . . .

You may want to reset your starting point . . . imagine you have 5 consecutive profit trades . . . then you have a 6th and a 7th . . . this means you will have 3 sets of 5 consecutive trades, the first 5 in the series then 4 of the first series + the 6th, then 3 of the first series + 6th +7th . . . if this is OK for what you want then you are good to go. If you want unique series of 5 then there is a way to do it also . . .

Reason: