Quantidade de Operações por período

 

Prezados,

Estou tentando criar um controle de operações baseado na quantidade diária de ordens executadas. Abaixo está os trechos de código que utilizo, pelo que vinha estudando para selecionar o histórico de ordens finalizadas no dia seriam as funções HistoryDeal..., porém não está batendo a contagem no final. Detalhe, estou utilizando saída parcial, talvez seja esse o motivo de não estar fechando pois ele contabiliza a saída parcial e queria que contabilize apenas a operação como um todo.

void BallanceAccountDay()
{
   string com="";

// --- determine the time intervals of the required trading history

   datetime end=TimeCurrent();                 // current server time

   datetime start=end-PeriodSeconds(PERIOD_D1);// set the beginning time to 24 hours ago
   

   TimeToStruct(StringToTime(inicio), horario_inicio);


//--- request in the cache of the program the needed interval of the trading history

   HistorySelect(start,end);

//--- obtain the number of deals in the history

   int deals=HistoryDealsTotal();



   int returns=0;

   double profit=0;

   double loss=0;

//--- scan through all of the deals in the history

   for(int i=0;i<deals;i++)

     {

      //--- obtain the ticket of the deals by its index in the list

      ulong deal_ticket=HistoryDealGetTicket(i);

      if(deal_ticket>0) // obtain into the cache the deal, and work with it

        {

         string symbol             =HistoryDealGetString(deal_ticket,DEAL_SYMBOL);

         datetime time             =HistoryDealGetInteger(deal_ticket,DEAL_TIME);

         ulong order               =HistoryDealGetInteger(deal_ticket,DEAL_ORDER);

         long order_magic          =HistoryDealGetInteger(deal_ticket,DEAL_MAGIC);

         long pos_ID               =HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID);

         ENUM_DEAL_ENTRY entry_type=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(deal_ticket,DEAL_ENTRY);



         //--- process the deals with the indicated DEAL_MAGIC

         if(order_magic==magicNum)

           {

            //... necessary actions

            //--- increase the number of deals 

            returns++;

           }



         //--- calculate the losses and profits with a fixed results

         if(entry_type==DEAL_ENTRY_OUT)

          {

            //--- increase the number of deals 

            //returns++;

            //--- result of fixation

            double result=HistoryDealGetDouble(deal_ticket,DEAL_PROFIT);

            //--- input the positive results into the summarized profit

            if(result>0) profit+=result;

            //--- input the negative results into the summarized losses

            if(result<0) loss+=result;

           }

        }

      else // unsuccessful attempt to obtain a deal

        {

         PrintFormat("We couldn't select a deal, with the index %d. Error %d",

                     i,GetLastError());

        }

     }

   //--- output the results of the calculations

   string format=StringFormat("The total number of %d deals with a financial result. Profit=%.2f , Loss= %.2f",

               returns,profit,loss);

   StringAdd(com,format);

   Comment(com);      

}


 
Karin Klayton Schiochet:

Prezados,

Estou tentando criar um controle de operações baseado na quantidade diária de ordens executadas. Abaixo está os trechos de código que utilizo, pelo que vinha estudando para selecionar o histórico de ordens finalizadas no dia seriam as funções HistoryDeal..., porém não está batendo a contagem no final. Detalhe, estou utilizando saída parcial, talvez seja esse o motivo de não estar fechando pois ele contabiliza a saída parcial e queria que contabilize apenas a operação como um todo.

void BallanceAccountDay()

{

   string com="";

// --- determine the time intervals of the required trading history

   datetime end=TimeCurrent();                 // current server time

   datetime start=end-PeriodSeconds(PERIOD_D1);// set the beginning time to 24 hours ago

   

   TimeToStruct(StringToTime(inicio), horario_inicio);


//--- request in the cache of the program the needed interval of the trading history

   HistorySelect(start,end);

//--- obtain the number of deals in the history

   int deals=HistoryDealsTotal();


   int returns=0;

   double profit=0;

   double loss=0;

//--- scan through all of the deals in the history

   for(int i=0;i<deals;i++)

     {

      //--- obtain the ticket of the deals by its index in the list

      ulong deal_ticket=HistoryDealGetTicket(i);

      if(deal_ticket>0) // obtain into the cache the deal, and work with it

        {

         string symbol             =HistoryDealGetString(deal_ticket,DEAL_SYMBOL);

         datetime time             =HistoryDealGetInteger(deal_ticket,DEAL_TIME);

         ulong order               =HistoryDealGetInteger(deal_ticket,DEAL_ORDER);

         long order_magic          =HistoryDealGetInteger(deal_ticket,DEAL_MAGIC);

         long pos_ID               =HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID);

         ENUM_DEAL_ENTRY entry_type=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(deal_ticket,DEAL_ENTRY);


         //--- process the deals with the indicated DEAL_MAGIC

         if(order_magic==magicNum)

           {

            //... necessary actions

            //--- increase the number of deals 

            returns++;

           }


         //--- calculate the losses and profits with a fixed results

         if(entry_type==DEAL_ENTRY_OUT)

          {

            //--- increase the number of deals 

            //returns++;

            //--- result of fixation

            double result=HistoryDealGetDouble(deal_ticket,DEAL_PROFIT);

            //--- input the positive results into the summarized profit

            if(result>0) profit+=result;

            //--- input the negative results into the summarized losses

            if(result<0) loss+=result;

           }

        }

      else // unsuccessful attempt to obtain a deal

        {

         PrintFormat("We couldn't select a deal, with the index %d. Error %d",

                     i,GetLastError());

        }

     }

   //--- output the results of the calculations

   string format=StringFormat("The total number of %d deals with a financial result. Profit=%.2f , Loss= %.2f",

               returns,profit,loss);

   StringAdd(com,format);

   Comment(com);      

}


O que percebo é que na verdade ele registra na entrada e saída da operação enquanto o correto seria registrar uma unidade para cada operação completa(entrada, parcial, saída)
 
Karin Klayton Schiochet:
O que percebo é que na verdade ele registra na entrada e saída da operação enquanto o correto seria registrar uma unidade para cada operação completa(entrada, parcial, saída)
Opa amigo, estou com o mesmo problema, vc conseguiu resolver? Obrigado
Razão: