Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1227

 
Hello! please explain or point fingers how to programmatically Close Open Positions with Hedge/Hedg account type. how to close hedged positions in mql5? only found this material. https://www.mql5.com/ru/articles/4830
Совершение сделок - Торговые операции - Справка по MetaTrader 5
Совершение сделок - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
BlackCoffee:
Hello! Please explain or point fingers how to programmatically Close Open Positions with Hedge/Hedg account type. how to close hedged positions in mql5? only found this material. https://www. mql5.com/ru/articles/4830

Example from the Close all positions code

When working with positions, it is necessary to loop through all positions to zero:

//+------------------------------------------------------------------+
//| Close all positions                                              |
//+------------------------------------------------------------------+
void CloseAllPositions()
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positions
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
         m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
  }

Close all positions
Close all positions
  • www.mql5.com
Закрытие позиций при достижении уровня прибыли  Close all if Profit . При этом суммируется общая прибыль по всем позициям: вне зависимости от символа и magic number. Подсчёт прибыли происходит только в момент рождения нового бара.
 
Vladimir Karputov:

Example from the Close all positions code

When dealing with positions, it is necessary to loop through all positions to zero:

Thanks for the answer!!! What if you only need to close a sell position? Should I add these lines?
if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
                       {
                         //--- prepare request for close SELL position
                        mrequest.type =ORDER_TYPE_BUY;
                        mrequest.price=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
                       }
 

This is the kind of thing I made. To close the selves for a hedge.


void CloseSellPositions()
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positions
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
         if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
                       {
                            m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
                       }
  }
But sometimes there is one position left open for some reason. If we set condition: Close if there are more than five positions.
 
BlackCoffee:

This is the kind of thing I made. To close the selves for a hedge.


But sometimes there is one position that is not closed for some reason. If we set a condition: close if there are more than five positions.

It's already right then:

void CloseSellPositions()
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positions
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
         if(m_position.PositionType()==POSITION_TYPE_SELL)
            m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
  }

and if it fails to close, look in the log file. There could be a million reasons: redirect, no trade, no price, proximity of stop levels...

 
Hello. Why do I need to delete class objects in deinitialisation? Will they remain in memory after the terminal is closed? Or will they remain in memory while the terminal is running, without an EA? What else needs to be deleted except the class objects?
 
Ivan_Invanov:
Hello. Why do you need to delete the class objects in deinitialization? Will they remain in memory after the terminal is closed? Or they will remain in memory while the terminal is running, without the Expert Advisor? What else needs to be deleted except the class objects?

For example, you delete the Expert Advisor from the chart, but all drawings (objects) remain on the chart. In deinitialisation, delete all unnecessary things to have a clean chart. It goes like this.

 
Nauris Zukas:

For example, you delete the Expert Advisor from the chart, but all drawings (objects) remain on the chart. In deinitialisation, delete all unnecessary things to have a clean chart. It goes like this.

I don't use graphical codes. I've seen in other people's prog that class objects are deleted. Did I understand correctly that if they are not deleted in deinitialization, they will remain in memory until the terminal is closed. What else besides class objects is better to delete? Thank you.
 

Hi !

How do I assign an id to an indicator? I bought an EA, it is oriented to a higher timeframe to trade on a lower one. The developer wrote that I have to put the indicator on the higher chart and assign an id to it. I am new to MT, i dont know how to do it. Please advise me, if someone knows how to do it. (I am using version MT5)

 
secret:

How can I prevent trades from other charts from appearing on the chart?

Only the trades of the robot that is on the given chart.

Am I the only one who is bothered by a jumble of trades from many robots on one chart? No one else has bothered?

Reason: