Download MetaTrader 5
To add comments, please log in or register
Write articles and earn money. We pay 200 USD for them!
Gerardo Bustos
747
Gerardo Bustos 2015.03.04 02:05 

Hello forum, good day.

I started learning MQL5 before MQL4 and I'm having a bit of trouble translating an EA to MQL4. Here is where I'm stuck:


MQL5 code: 

void OnTick()
  {
    int total = 0;
    
    for( int i = 0; i < PositionsTotal(); i++ )
      {
        if ( Symbol() == PositionGetSymbol(i) ) {
          total = 1;
          if ( NewBar() ) Trail();
        }
      }

    //...
  }

 

What I need to change is PositionsTotal() and PositionGetSymbol() because they don't exist in MQL4. I've looked at the MQL4 Docs and know that PositionsTotal() is OrdersTotal(), but I haven't found the equivalent of PositionGetSymbol(). Could someone with more experience help me please? Your help will be much appreciated.

 

Best regards and thank you in advance,

codeMolecules 

Keith Watford
Moderator
7990
Keith Watford 2015.03.04 03:25  

"but I haven't found the equivalent of PositionGetSymbol()"

Try OrderSymbol() 

Keith Watford
Moderator
7990
Keith Watford 2015.03.04 03:31  

This is a basic check

 

   for(int x=OrdersTotal()-1;x>=0;x--)
     {
      if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES) 
         && OrderSymbol()==Symbol()
         && OrderMagicNumber()==MagicNumber)
           {
           // Do whatever
           }
     }
Gerardo Bustos
747
Gerardo Bustos 2015.03.04 05:48  
GumRai:

This is a basic check

 

Thank you very much GumRai, I will give it a try.

Best regards,

codeMolecules 

whroeder1
13641
whroeder1 2015.03.04 13:35  
codeMolecules: I've looked at the MQL4 Docs and know that PositionsTotal() is OrdersTotal(), but I haven't found the equivalent of PositionGetSymbol(). Could someone with more experience help me please? Your help will be much appreciated.
If you really did look at OrderSelect - MQL4 Documentation then you would have seen it in the list


Gerardo Bustos
747
Gerardo Bustos 2015.03.04 15:44  
WHRoeder:
codeMolecules: I've looked at the MQL4 Docs and know that PositionsTotal() is OrdersTotal(), but I haven't found the equivalent of PositionGetSymbol(). Could someone with more experience help me please? Your help will be much appreciated.
If you really did look at OrderSelect - MQL4 Documentation then you would have seen it in the list


Hello, 

I ended up using the following and it worked:


for ( i = 0; i < OrdersTotal(); i++ ) {
    if ( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) ) {
        if ( Symbol() == OrderSymbol() ) {
            //...
        }
    }
}

 

 

Best regards and thank you,

codeMolecules 

/
To add comments, please log in or register