Getting history deals got bug

 

I'm trying to count my last few deal losing action with this code. It is returning 0 always.

Is there anything wrong with the code?

DTB and DTS are global variable. 

void LastChainActions()
  {
//---

   long   EntryType;
   ulong  Ticket;
   string DealSym;

   HistorySelect(0, TimeCurrent());

   if(HistoryDealsTotal() >= DCA)
   {
      for(int i = DCA - 1; i >= 0; i--)
      {
         Ticket    = HistoryDealGetTicket(i);
         DealSym   = HistoryDealGetString(Ticket, DEAL_SYMBOL);
         EntryType = HistoryDealGetInteger(Ticket, DEAL_ENTRY);

         if(DealSym == _Symbol && EntryType == DEAL_ENTRY_OUT)
         {
               if(HistoryDealGetInteger(Ticket, DEAL_TYPE) == DEAL_TYPE_BUY)
               {
                  if(HistoryDealGetDouble(Ticket, DEAL_PROFIT) < 0.0)
                  {
                     DTB += 1;
                  }
               }

               if(HistoryDealGetInteger(Ticket, DEAL_TYPE) == DEAL_TYPE_SELL)
               {
                  if(HistoryDealGetDouble(Ticket, DEAL_PROFIT) < 0.0)
                  {
                     DTS += 1;
                  }
               }
         }
      }
   }

//---
   }
 
Dua Yong Rew:

I'm trying to count my last few deal losing action with this code. It is returning 0 always.

Is there anything wrong with the code?

DTB and DTS are global variable. 

What is the value of DCA ?

This function doesn't return a value, what is always returning 0 ? DTB and DTS ?

 
Alain Verleyen:

What is the value of DCA ?

This function doesn't return a value, what is always returning 0 ? DTB and DTS ?

:)

I solved the problem already. Working through history is slightly difficult. 

 
Dua Yong Rew:

:)

I solved the problem already. Working through history is slightly difficult. 

So, can't you share your solution when you are expecting help from the community ?
 
Alain Verleyen:
So, can't you share your solution when you are expecting help from the community ?

alright, here goes.

The code is to check last few close trades. if there are consecutive losing buys or sells, what should your system be heading for???

//+------------------------------------------------------------------+
//| Last Chain Actions                                               |
//+------------------------------------------------------------------+
void LastChainActions()
  {
//---

   long   EntryType;
   ulong  Ticket;
   string DealSym;

   HistorySelect(0, TimeCurrent());

   for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
   {
      Ticket    = HistoryDealGetTicket(i);
      DealSym   = HistoryDealGetString(Ticket, DEAL_SYMBOL);
      EntryType = HistoryDealGetInteger(Ticket, DEAL_ENTRY);

      if(DealSym == _Symbol && EntryType == DEAL_ENTRY_OUT)
      {
         if(HistoryDealGetInteger(Ticket, DEAL_TYPE) == DEAL_TYPE_BUY)
         {
            if(HistoryDealGetDouble(Ticket, DEAL_PROFIT) < 0.0)
            {
               if(DTS > 0) break;

               DTB += 1;
            }
         }

         if(HistoryDealGetInteger(Ticket, DEAL_TYPE) == DEAL_TYPE_SELL)
         {
            if(HistoryDealGetDouble(Ticket, DEAL_PROFIT) < 0.0)
            {
               if(DTB > 0) break;

               DTS += 1;
            }
         }
      }

      if(DTB == DCA || DTS == DCA) break;
   }

//---
   }

 DCA is a input

 
Dua Yong Rew:

alright, here goes.

The code is to check last few close trades. if there are consecutive losing buys or sells, what should your system be heading for???

 DCA is a input

Thanks for sharing.
 
Alain Verleyen:
Thanks for sharing.
no problem :)
Reason: