Filter orders from the pool by Symbol

 

Hi there, need to filter open positions from the pool by its symbol to properly calc its breakeven.

Through this code, I can get just values from the chart symbol:

If(PositionGetString(POSITION_SYMBOL)==_Symbol){

Also tried this way but makes no sense:

if(PositionGetSymbol(i)==PositionGetString(POSITION_SYMBOL)){

And this one:

            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){
               if(PositionGetSymbol(i)==true){
                  VT+=Volume;Alert(PS," volume total is ",VT);
                  BE+=(OP*Volume)/VT;Alert(PS," breakeven is ",BE);
                  }
               Alert(PS," breakeven at ",OP+(PartialClose1*10)*SPoint);
               }
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){
               if(PositionGetSymbol(i)==true){
                  VT+=Volume;Alert(PS," volume total is ",VT);
                  BE+=(OP*Volume)/VT;Alert(PS," breakeven is ",BE);
                  }
               Alert(PS," breakeven at ",OP-(PartialClose1*10)*SPoint);
               }
Any idea? Thanks in advance.
 
David Diez:

Hi there, need to filter open positions from the pool by its symbol to properly calc its breakeven.

Through this code, I can get just values from the chart symbol:

Also tried this way but makes no sense:

And this one:

Any idea? Thanks in advance.
string FindSymbol;
FindSymbol="EURUSD";//as example


if(OrderSymbol()==FindSymbol) //calculate.....

Try this....


 
David Diez:

Hi there, need to filter open positions from the pool by its symbol to properly calc its breakeven.

Through this code, I can get just values from the chart symbol:

Also tried this way but makes no sense:

And this one:

Any idea? Thanks in advance.

Result of PositionGetSymbol() is not boolean but a string

 
Nikolaos Pantzos:

Try this....


That way I'll have to make at least 30 lines of code, I think must be a better way.

 
Mladen Rakic:

Result of PositionGetSymbol() is not boolean but a string

Yes but this isn't also working properly:

if(PositionGetSymbol(i)==PositionGetString(POSITION_SYMBOL)){

Have any idea to solve the issue? It's for managing deals automated from a single chart.

 
David Diez:

Yes but this isn't also working properly:

Have any idea to solve the issue? It's for managing deals automated from a single chart.

if(PositionGetSymbol(i)==_Symbol) ...
 
Mladen Rakic:
Just doesn't work as expected for this purpose, need to work all the symbol from a single chart.
 
Nikolaos Pantzos:

Try this....


Mladen Rakic:

Hi all, got a solution clean and simple:

void OnStart(){
   double Long=0,Short=0;
   for(int s=0;s<SymbolsTotal(false);s++){ // Define a counter loop for all broker symbols.
      string CurrentS=SymbolName(s,false); // Declare current working symbol from the loop.
      for(int i=0;i<PositionsTotal();i++){ // Here it goes the main loop for the advisor tool.
         ulong Ticket=PositionGetTicket(i);      
         if(PositionSelectByTicket(Ticket)){
            string PS=PositionGetString(POSITION_SYMBOL);       // Declare position symbol value.
            if(PositionGetString(POSITION_SYMBOL)==CurrentS){   // Check if position symbol is current working symbol.
               int SD=(int)SymbolInfoInteger(PS,SYMBOL_DIGITS); // Declare symbol digits to get its value.
               Alert(PS," symbol digits are ",SD);              // Print symbol digits value for each symbol.
               if(PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_BUY){
                  Long++;if(Long>0){Alert(PS," buy orders are ",Long);}       // Count long orders from each symbol and print its value.
                  }
               if(PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_SELL){
                  Short++;if(Short>0){Alert(PS," sell orders are ",Short++);} // Count short orders from each symbol and print its value.
                  }
               }
            }
         }
      }
   }
Now I got another problem by trying to get breakeven price explained in this new topic: https://www.mql5.com/en/forum/323198
 
David Diez:
Now I got another problem by trying to get breakeven price explained in this new topic: https://www.mql5.com/en/forum/323198

Why open a new topic when it is related to this??

Continue posting here.

I have deleted the new topic.

 
David Diez:

This topic is outdated, Keith. I'm posting elsewhere.

How can it be outdated?

The code that you have just posted is obviously connected.