wemersonrv

Contador de Ordens MQL4

Aug 14th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. int CountOpenOrders(string filter="", string magic="", bool onlyactive=true )
  2. {
  3.     int count=0;
  4.  
  5.     for( int i=OrdersTotal()-1; i>=0; i--)
  6.     {
  7.         // Se OrderSelect a ordem falhar, vai para próxima iteração do loop ( continue )
  8.         if( !OrderSelect(i, SELECT_BY_POS ) ){ continue; }
  9.        
  10.         // Se está contando somente ordens ativas, pula ordens pendentes
  11.         if( onlyactive ){
  12.             if(
  13.                 OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP ||
  14.                 OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP
  15.             )
  16.             {
  17.                 continue; // Pula para próxima pois não é ordem ativa
  18.             }
  19.         }
  20.  
  21.         // Analizar as opções de filtro, caso exista
  22.         if( filter != "" )
  23.         {
  24.             // Se o Simbolo do par não for o presente no filtro,
  25.             // Pular para a próxima iteração do loop ( continue )
  26.             if( OrderSymbol() != filter ){ continue; }
  27.  
  28.             // Se estiver usando MagicNumber
  29.             // pular para o próximo se o magicnumber não for o desejado
  30.             if( magic!="" )
  31.             {
  32.                 if( OrderMagicNumber() != magic ){ continue; }
  33.             }
  34.         }
  35.  
  36.         // Se chegou até aqui é porque todas as condições foram satisfeitas
  37.         // Ou as condições não satisfeitas foram descartadas, pulando para a próxima iteração do loop ( continue )
  38.         // Está pronto para incrementar o contador de ordens abertas
  39.  
  40.         // Incrementa contador de ordens
  41.         count++;
  42.     }
  43.  
  44.     return count; // Retorna o resultado
  45. }
  46.  
  47.  
  48.  
  49. if( CountOpenOrders( _Symbol, inpMagicNumber ) > 2 )
  50. {
  51.     // Do it... faça sua mágica
  52. }
  53.  
  54. // Outras Opções
  55.  
  56. // Retornará total de ordens ATIVAS abertas
  57. CountOpenOrders( );
  58.  
  59. // Retornará total de ordens ATIVAS abertas para o PAR atual
  60. CountOpenOrders( _Symbol );
  61.  
  62. // Retornará total de ordens ATIVAS abertas para o PAR atual que tiverem o MagicNumber 123456
  63. CountOpenOrders( _Symbol, 123456 );
  64.  
  65. // Retornará total de ordens ATIVAS e PENDENTES abertas para o PAR atual que tiverem o MagicNumber 123456
  66. CountOpenOrders( _Symbol, 123456, false );
Advertisement
Add Comment
Please, Sign In to add comment