Experts: Yesterday Today - page 2

 
pokrovsky-my #:
I didn't mean a pending order, but the ability to close a market order on time, even if it is losing.

Code:

//+------------------------------------------------------------------+
//| Close positions|
//+------------------------------------------------------------------+
void ClosePosition(const ENUM_POSITION_TYPE pos_type)
  {
     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.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
          if(m_position.PositionType()==pos_type) // gets the position type
            if(Hour()>TimeClose)
               m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
  }


Добавил условие if(Hour()>TimeClose), в переменных прописал input double   TimeClose         = 21; вставил int Hour()
{
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.hour);
}
int Minute()
{
   MqlDateTime tm;
   TimeCurrent(tm);
   return(tm.min);
}



The Expert Advisor compiles without errors, but the order is not closed at the specified time

 

Just in case: ( General Principles - Trading Operations )

Before starting to study the trading functions of the platform, it is necessary to create a clear understanding of the basic terms: order, transaction and position.

  • An order is an instruction to a brokerage company to buy or sell a financial instrument. There are two maintypes of orders: market and pending. Besides them, there are special ordersTake Profit and Stop Loss.
  • Transaction is the fact of buying or selling a financial instrument. Buying (Buy) takes place at the bid price (Ask), and selling (Sell) - at the offer price (Bid). A deal can be made as a result of execution of a market order or triggering of a pending order. It should be taken into account that in some cases the result of order execution may be several transactions at once.
  • Position is a market commitment, the number of bought or sold contracts on a financial instrument. A long position (Long) is a financial instrument bought in the expectation of price increase, a short position (Short) is a commitment to deliver it in the expectation of price decrease in the future.

In other words, an order is an order, a command to open a Deal (a Deal generates a POSITION) or to place a Pending Order.


To work with time, I recommend to read the article Almost a constructor for creating an Expert Advisor and look in the file'Trading engine 4.mq5' the group of input parameters'Time control':

input group             "Time control"
input bool                 InpTimeControl          = true;           // Use time control
input uchar                InpStartHour            = 10;             // Start Hour
input uchar                InpStartMinute          = 01;             // Start Minute
input uchar                InpEndHour              = 15;             // End Hour
input uchar                InpEndMinute            = 02;             // End Minute
Общие принципы - Торговые операции - Справка по MetaTrader 5
Общие принципы - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Перед тем как приступить к изучению торговых функций платформы, необходимо создать четкое представление об основных терминах: ордер, сделка и...
 
Vladimir Karputov #:

Just in case: ( General Principles - Trading Operations )

Before starting to study the trading functions of the platform, it is necessary to create a clear understanding of the basic terms: order, transaction and position.

  • An order is an instruction to a brokerage company to buy or sell a financial instrument. There are two maintypes of orders: market and pending. Besides them, there are special ordersTake Profit and Stop Loss.
  • Transaction is the fact of buying or selling a financial instrument. Buying (Buy) takes place at the bid price (Ask), and selling (Sell) - at the offer price (Bid). A deal can be made as a result of execution of a market order or triggering of a pending order. It should be taken into account that in some cases the result of order execution may be several transactions at once.
  • Position is a market commitment, the number of bought or sold contracts on a financial instrument. Long position (Long) is a financial instrument purchased in the expectation of price increase, Short position (Short) is a commitment to deliver it in the expectation of price decrease in the future.

i.e. an order is an order, a command to open a Deal (a Deal generates a POSITION) or to place a Pending Order.


To work with time, I recommend to read the article Almost a constructor for creating an Expert Advisor and look in the file'Trading engine 4.mq5' the group of input parameters'Time control':

It is necessary that an open position is forced to close at a certain time

 
pokrovsky-my #:

It is necessary that an open position is forcibly closed at a certain time

Have you read the article? Can you modify the code?

 
Vladimir Karputov #:

Did you read the article? Can you modify the code?

I've read the article, but it's a dark forest for me.

 
pokrovsky-my #:

Watched the article, but it's a dark forest for me.

Okay, I'll put it on my agenda for tomorrow.

 
pokrovsky-my #:


New version of Yesterday Today New

Yesterday Today New
Yesterday Today New
  • www.mql5.com
Торговля основана на анализе OHLC вчерашнего дня и текущего.
 
Vladimir Karputov #:

New version of Yesterday Today New

Vladimir, thank you for your labour. It is good when there are such experts who help users.