Questions from Beginners MQL5 MT5 MetaTrader 5 - page 934

 
Duck is in the article about signals. That's not it.
 
void ClosePositions()
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current orders
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==Magic)
            m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
  }
Can you tell me how to change this function to find andclose a position that has an AAA comment?
Совершение сделок - Торговые операции - MetaTrader 5
Совершение сделок - Торговые операции - MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
EgorKim:
Can you tell me how to change this function to find andclose a position that has an AAA comment?

Help:CPositionInfo

Access to text properties ...
 

Thank you.

Also, could you please tell me why the implicit conversion from 'number' to 'string' is being swore at compilation

if(m_trade.Buy(InpLots,m_symbol.Name(),m_symbol.Ask(),sl,tp, "AAA")

What should the correct buy command look like?

 
EgorKim:

Thank you.

Also, could you please tell me why the implicit conversion from 'number' to 'string' is being swore at compilation

if(m_trade.Buy(InpLots,m_symbol.Name(),m_symbol.Ask(),sl,tp, "AAA")

What should the correct buy command look like?

Reference:Buy.

Help:Conditional if-else statement

 

That's not how you wrote the code.

Here is the code

long     chislo       =5;
if(m_trade.Buy(InpLots,m_symbol.Name(),m_symbol.Ask(),sl,tp,"AAA"+chislo))

The compiler complains about"AAA "+chislo

 
EgorKim:

That's not how you wrote the code.

Here is the code

The compiler complains about"AAA "+chislo

Reference:IntegerToString


Added: That's all for today. I'm already asleep.

 
EgorKim:

That's not how you wrote the code.

Here is the code

The compiler complains about"AAA "+chislo

long     chislo       =5;
if(m_trade.Buy(InpLots,m_symbol.Name(),m_symbol.Ask(),sl,tp,"AAA"+(string) chislo))
 

Vladimir Karputov, Alexey Viktorov

Thank you

 

Please advise on the code.

At the moment there are 4 bays open with 1 lot each and 4cells with 1 lot each. The symbol is the same.

Only 1 buy and 1 sell is closed in this position.

void CloseBy()
  {
   ulong ticket_buy=ULONG_MAX;
   ulong ticket_sell=ULONG_MAX;
   for(int i=0;i<PositionsTotal();i++) // ATTENTION! Here, specially began a detour with "0"
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         {
         if(m_position.PositionType()==POSITION_TYPE_BUY && ticket_buy==ULONG_MAX)
            ticket_buy=m_position.Ticket();

         if(m_position.PositionType()==POSITION_TYPE_SELL && ticket_sell==ULONG_MAX)
            ticket_sell=m_position.Ticket();
        }
   if(ticket_buy!=ULONG_MAX && ticket_sell!=ULONG_MAX)
      m_trade.PositionCloseBy(ticket_buy,ticket_sell);
//---
   return;
  }

Nothing is closed at all in this position

void CloseBy()
  {
   ulong ticket_buy=ULONG_MAX;
   ulong ticket_sell=ULONG_MAX;
   for(int i=0;i<PositionsTotal();i++) // ATTENTION! Here, specially began a detour with "0"
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         if(m_position.PositionType()==POSITION_TYPE_BUY && ticket_buy==ULONG_MAX)
            ticket_buy=m_position.Ticket();

         if(m_position.PositionType()==POSITION_TYPE_SELL && ticket_sell==ULONG_MAX)
            ticket_sell=m_position.Ticket();
        }
   if(ticket_buy!=ULONG_MAX && ticket_sell!=ULONG_MAX)
      m_trade.PositionCloseBy(ticket_buy,ticket_sell);
//---
   //return;
  }

What should I do to close all 4 buys and 4 sells counterclosed?

Reason: