counting last consecutive gains /or losses

 

Hello forum,

So far I have this, below, but it counts ALL trades in history. How do I break the cycle so only the LAST CONSECUTIVE trades of same sign are counted - I have some (complicated) ideas but I feel there might be a a quick way? 

Many thanks in advance,

Dan.

int GainCount = 0; int LossCount = 0;
   for(int GainLossCnt = OrdersHistoryTotal()-1; GainLossCnt >=0; GainLossCnt--){
      if(OrderSelect(GainLossCnt,SELECT_BY_POS,MODE_HISTORY) && 
         OrderMagicNumber() == magic &&
         OrderSymbol() == symbol &&
         OrderProfit()>=0)
         GainCount++;
         
      if(OrderSelect(GainLossCnt,SELECT_BY_POS,MODE_HISTORY) && 
         OrderMagicNumber() == magic &&
         OrderSymbol() == symbol &&
         OrderProfit()< 0)
         LossCount++;
         
      }
 
Dannoo007:

Hello forum,

So far I have this, below, but it counts ALL trades in history. How do I break the cycle so only the LAST CONSECUTIVE trades of same sign are counted - I have some (complicated) ideas but I feel there might be a a quick way? 

Many thanks in advance,

Dan.


First step is to define what you mean by consecutive. Consecutive by open time or by close time
 
GumRai:
First step is to define what you mean by consecutive. Consecutive by open time or by close time
  Consecutive closed orders, of same sign. There is only one EA, opening 1 order at a time.
Reason: