Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int CountOpenOrders(string filter="", string magic="", bool onlyactive=true )
- {
- int count=0;
- for( int i=OrdersTotal()-1; i>=0; i--)
- {
- // Se OrderSelect a ordem falhar, vai para próxima iteração do loop ( continue )
- if( !OrderSelect(i, SELECT_BY_POS ) ){ continue; }
- // Se está contando somente ordens ativas, pula ordens pendentes
- if( onlyactive ){
- if(
- OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP ||
- OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP
- )
- {
- continue; // Pula para próxima pois não é ordem ativa
- }
- }
- // Analizar as opções de filtro, caso exista
- if( filter != "" )
- {
- // Se o Simbolo do par não for o presente no filtro,
- // Pular para a próxima iteração do loop ( continue )
- if( OrderSymbol() != filter ){ continue; }
- // Se estiver usando MagicNumber
- // pular para o próximo se o magicnumber não for o desejado
- if( magic!="" )
- {
- if( OrderMagicNumber() != magic ){ continue; }
- }
- }
- // Se chegou até aqui é porque todas as condições foram satisfeitas
- // Ou as condições não satisfeitas foram descartadas, pulando para a próxima iteração do loop ( continue )
- // Está pronto para incrementar o contador de ordens abertas
- // Incrementa contador de ordens
- count++;
- }
- return count; // Retorna o resultado
- }
- if( CountOpenOrders( _Symbol, inpMagicNumber ) > 2 )
- {
- // Do it... faça sua mágica
- }
- // Outras Opções
- // Retornará total de ordens ATIVAS abertas
- CountOpenOrders( );
- // Retornará total de ordens ATIVAS abertas para o PAR atual
- CountOpenOrders( _Symbol );
- // Retornará total de ordens ATIVAS abertas para o PAR atual que tiverem o MagicNumber 123456
- CountOpenOrders( _Symbol, 123456 );
- // Retornará total de ordens ATIVAS e PENDENTES abertas para o PAR atual que tiverem o MagicNumber 123456
- CountOpenOrders( _Symbol, 123456, false );
Advertisement
Add Comment
Please, Sign In to add comment