Processing

Algoritmo de processamento principal.

virtual bool  Processing()

Valor de retorno

Verdadeiro se a operação de negociação foi executada, caso contrário falso.

Observação

Ele faz as seguintes etapas:

1. Verificar a presença da posição aberta no símbolo. Se não abrir a posição, pule as etapas №2, №3 e №4.
2. Verificar condições para reversão da posição aberta (método CheckReverse()). Se a posição foi revertida, sair.
3. Condições para verificar o fechamento da posição (método CheckClose()). Se a posição foi fechada, pule a etapa №4.
4. Verificar as condições para modificar os parâmetros da posição (método CheckTrailingStop() ). Se os parâmetros da posição foi modificado, sair.
5. Verificar a presença de ordens pendentes no símbolo. Se não houver qualquer ordem pendente, vá para a etapa №9.
6. Verificar condição para excluir a ordem (CheckDeleteOrderLong() para ordens pendentes de compra ou CheckDeleteOrderShort() para ordens pendentes de venda). Se a ordem foi excluída, vá para a etapa №9.
7. Verificar as condições para modificar parâmetros de ordem pendente (CheckTrailingOrderLong() para ordens de compra ou CheckTrailingOrderShort() para ordens de venda). Se os parâmetros de ordem foram modificados, sair.
8. Sair.
9. Verificar condições para abertura de posição (método CheckOpen()).

Se você quiser implementar seu próprio algoritmo, você precisará substituir o método da classe herdeira Processing() .

Implementação

//+------------------------------------------------------------------+
//| Main function                                                    |
//| INPUT:  no.                                                      |
//| OUTPUT: true-if any trade operation processed, false otherwise.  |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CExpert::Processing()
  {
//--- check if open positions
   if(m_position.Select(m_symbol.Name()))
     {
      //--- open position is available
      //--- check the possibility of reverse the position
      if(CheckReverse()) return(true);
      //--- check the possibility of closing the position/delete pending orders
      if(!CheckClose())
        {
         //--- check the possibility of modifying the position
         if(CheckTrailingStop()) return(true);
         //--- return without operations
         return(false);
        }
     }
//--- check if placed pending orders
   int total=OrdersTotal();
   if(total!=0)
     {
      for(int i=total-1;i>=0;i--)
        {
         m_order.SelectByIndex(i);
         if(m_order.Symbol()!=m_symbol.Name()) continue;
         if(m_order.OrderType()==ORDER_TYPE_BUY_LIMIT || m_order.OrderType()==ORDER_TYPE_BUY_STOP)
           {
            //--- check the ability to delete a pending order to buy
            if(CheckDeleteOrderLong()) return(true);
            //--- check the possibility of modifying a pending order to buy
            if(CheckTrailingOrderLong()) return(true);
           }
         else
           {
            //--- check the ability to delete a pending order to sell
            if(CheckDeleteOrderShort()) return(true);
            //--- check the possibility of modifying a pending order to sell
            if(CheckTrailingOrderShort()) return(true);
           }
         //--- return without operations
         return(false);
        }
     }
//--- check the possibility of opening a position/setting pending order
   if(CheckOpen()) return(true);
//--- return without operations
   return(false);
  }