avatar
Martingale-CountConsecutivetrade

hellboys06 11 24th Jun, 2020

CPP 3.53 KB
                                           
                         //+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//----------------------

 int ProfitHistoryOrdersCount(){
    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
    &&  OrderProfit()       > 0
    )   
    ProfitHistoryOrdersCount = (ProfitHistoryOrdersCount+1) % 6;
    return (ProfitHistoryOrdersCount);
}

//--------https://www.mql5.com/en/forum/136606
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);
      }
}


//-------------------https://www.mql5.com/en/forum/94367

int OrdersTotalProfitable()
  {
   int count=0,
   total=OrdersHistoryTotal();
   for(int i=total-1;i>=0;i--)
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==_Symbol)
        {
         if(OrderProfit()<0.0)
            count++;
         else
            break;
        }
   return(count);
     printf("Total consecutive profitable orders: %d",OrdersTotalProfitable());
  }
  
 //------------------------------------------------------------------------------------
void checkforlosses(int &losses, double &lot) // << Value could change outside this fuction
{                                             
    losses=0;

    for(int i=0; i<OrdersHistoryTotal(); i++)
    {                                        
        if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
        if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;                     
        if (OrderCloseTime() < 1) continue; // redundant check :D
        if(OrderProfit()<=0) losses++;       
        else                losses=0;        

        lot=OrderLots();                    
    }
    return;
}
   
//-------------------------------------------------------https://www.mql5.com/en/forum/120697
int LosCount()
{
int LosCount=0; //ProfCout=0, 
   int OrdHistory=OrdersHistoryTotal();
    for(int cnnt=0;cnnt>=1;cnnt--)
      {   
         if(OrdHistory>0 && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
         if(OrderSelect(OrdHistory-cnnt,SELECT_BY_POS,MODE_HISTORY) && OrderProfit()>=0){LosCount=0;}//ProfCout++;
         else if(OrderSelect(OrdHistory-cnnt,SELECT_BY_POS,MODE_HISTORY) && OrderProfit()<0){LosCount++;}
            Comment(LosCount);
      }
      }
}
   
  //-------------------------------------------
  //+-------https://www.forexfactory.com/showthread.php?t=230203
int Losses()
{
    int Count = 0;
    for(int i=OrdersHistoryTotal()-1; i>=0; i--)
    {
      OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      if(OrderProfit()>0) break;
      Count++;
    }
    return(Count);     
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data

Comments

Authentication required

You must log in to post a comment.

Log in
    There are no comments yet.