counting open orders

To add comments, please log in or register
qjol
3200
qjol  

hi everyone

if someone cal help me

how do i count how many symbols i have

for example

if i have 2 orders buy on "EURUSD" & 3 sell on "GBPUSD" & 4 sell's on "AUDUSD"

how to receive the result 3

thanks

qjol
3200
qjol  

anyone ?

Ubzen
5299
Ubzen  
int start(){
//#################################################################
//#################################################################
int EURUSD_Orders=0;
int GBPUSD_Orders=0;
int AUDUSD_Orders=0;
int Total_Symbols=0;
//#################################################################
//#################################################################
if(OrdersTotal()>0){
   for(int a=OrdersTotal()-1;a>=0;a--){
      if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==true){
         if(OrderSymbol()=="EURUSD"){EURUSD_Orders=1;}
         if(OrderSymbol()=="GBPUSD"){GBPUSD_Orders=1;}
         if(OrderSymbol()=="AUDUSD"){AUDUSD_Orders=1;}
      }
   }
}
//#################################################################
//#################################################################
Total_Symbols=EURUSD_Orders+GBPUSD_Orders+AUDUSD_Orders;
Alert("Total_Symbols=",Total_Symbols);
//#################################################################
//#################################################################
return(0);}
qjol
3200
qjol  

it's he ony way i need to write a list of all the symbol ?

Ubzen
5299
Ubzen  

I recommend you take some time and understand programming instead of just code hunting.

Here's a good starting place https://book.mql4.com// 

qjol
3200
qjol  

thanks anyway

qjol
3200
qjol  

On second thought,

I think there should be another way, for example if I want to continue the separate sale & buy

then I will have to make an even bigger list, like this

Anyway, I do not think it's legality programming
again This is my opinion

I may be wrong

int start(){
//#################################################################
//#################################################################
int EURUSD_Buy_Orders=0;
int EURUSD_Sell_Orders=0;
int GBPUSD_Buy_Orders=0;
int GBPUSD_Sell_Orders=0;
int AUDUSD_Buy_Orders=0;
int AUDUSD_SellOrders=0;
int ....... Buy_Orders=0;
int ....... Sell_Orders=0;
int ....... Buy_Orders=0;
int ....... Sell_Orders=0;
int ....... Buy_Orders=0;
int ....... Sell_Orders=0;


int Total_Symbols=0;
//#################################################################
//#################################################################
if(OrdersTotal()>0){
   for(int a=OrdersTotal()-1;a>=0;a--){
      if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==true){
         if(OrderSymbol()=="EURUSD" && OrderType() == OP_BUY){EURUSD_Buy_Orders=1;}
         if(OrderSymbol()=="EURUSD" && OrderType() == OP_SELL){EURUSD_Sell_Orders=1;}
         if(OrderSymbol()=="GBPUSD" && OrderType() == OP_BUY){GBPUSD_Buy_Orders=1;}
         if(OrderSymbol()=="GBPUSD" && OrderType() == OP_SELL){GBPUSD_Buy_Sell_Orders=1;}
         if(OrderSymbol()=="AUDUSD" && OrderType() == OP_BUY){AUDUSD_Buy_Buy_Orders=1;}
         if(OrderSymbol()=="AUDUSD" && OrderType() == OP_SELL){AUDUSD_Buy_Sell_Orders=1;}
      }
   }
}
//#################################################################
//#################################################################

Total_Symbols=EURUSD_Buy_Orders=0 + EURUSD_Sell_Orders=0 + GBPUSD_Buy_Orders=0 + GBPUSD_Sell_Orders=0 + AUDUSD_Buy_Orders=0 + AUDUSD_SellOrders=0;
Alert("Total_Symbols=",Total_Symbols);
//#################################################################
//#################################################################
return(0);}

qjol
3200
qjol  
ubzen:

I recommend you take some time and understand programming instead of just code hunting.

Here's a good starting place https://book.mql4.com//


what is wrong about hunting

#include <SymbolsLib.mqh>
https://www.mql5.com/en/code/9102

int CntOPenOrders()
   {
   int OOB = 0;
   int OOS = 0;
   int B   = 0;
   int S   = 0;
   int CNTB = 0;
   int CNTS = 0;
   string SymbolsList[];
   
     if(SymbolsList(SymbolsList, true) > 0)
        {
        for (int SYM = 0; SYM < 200; SYM++)
           {
           if(OrdersTotal()>0)
              {
              for(int a=OrdersTotal()-1;a>=0;a--)
                 {
                 if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==true)
                    {
                    if (OrderSymbol() == SymbolsList[SYM] && OrderMagicNumber() == 1)// && OrderType() == OP_BUY)
                       {
                       OOB++;
                       }
                    if (OrderSymbol() == SymbolsList[SYM] && OrderMagicNumber() == 2)// && OrderType() == OP_SELL)
                       {
                       OOS++;
                       }
                    }
                 }
              }
              if (CNTB != OOB)
                 {
                 B += 1;
                 CNTB = OOB;
                 }
              if (CNTS != OOS)
                 {
                 S += 1;
                 CNTS = OOS;
                 }
                 TotalOrders = B + S;
           }
        }
   }
To add comments, please log in or register