What is the equivalent to PositionGetSymbol in MQL4?

 

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 ( IsNewBar() ) 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 

 
codeMolecules:

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: 

 

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 

G'day Molecules

You're nearly there. You'll just need to check out OrderSelect() and OrderSymbol()



Cheers

OrderSelect - MQL4 Documentation
  • docs.mql4.com
OrderSelect - MQL4 Documentation
 

Hi

This is code for MT4

void OnTick()
  {
    int total = 0;
    
    for ( int i = 0; i < OrdersTotal(); i++ )
      {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
        if ( Symbol() == OrderSymbol() ) {
          total = 1;
          if ( IsNewBar() ) Trail();
        }
        }
      }

    //...
  }
 
tuoitrecuoi:

Hi

This is code for MT4

Hello tuoitrecuoi, thanks for your help! I tried the following and it also worked!

 

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

 

Best regards and thank you,

codeMolecules 

Reason: