Symbol issues.

 

Hi There;


I have the following on my EA /  OnTick()


void OnTick()
  {

// PositionsTotal() works fine.
// Currently have 20 instruments selected in the market. but shows as 0 always :p

      for(int i=0; i < PositionsTotal(); ++i)
        {

        printf("SymbolName 1 =  %G", m_position.Symbol());
         printf("SymbolName 2 =  %G", Symbol());
         printf("SymbolName 3 =  %G", PositionGetSymbol(i));         
     }
   else
     {
      printf("Waiting for equity to place a position / lot");
     }
  }
 
so what's your issue
 
Pak Hong Poon:
so what's your issue
// Currently have 20 instruments selected in the market. but shows as 0 always :p
Trying to get SymbolName
 
Chris Stols :
Trying to get SymbolName

You forgot about PositionGetTicket

Documentation on MQL5: Trade Functions / PositionGetTicket
Documentation on MQL5: Trade Functions / PositionGetTicket
  • www.mql5.com
PositionGetTicket - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov:

You forgot about PositionGetTicket

Hello Vladimir;


I used %s instead of %G - working fine now.

 

For example like this: position selection via PositionGetSymbol

   int count_positions=PositionsTotal(); // number of open positions
   for(int i=count_positions-1;i>=0;i--)
     {
      ResetLastError();
      //--- returns the symbol of the corresponding open position and automatically selects the position for further work with it
      string name=PositionGetSymbol(i);
      if(name==NULL)
        {
         Print("PositionGetSymbol Error# ",GetLastError());
         return;
        }

      double position_lot=PositionGetDouble(POSITION_VOLUME); // get the position volume
      ***
     }