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(constENUM_POSITION_TYPE pos_type)
{
for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of current positionsif(m_position.SelectByIndex(i)) // selects the position by index for further access to its propertiesif(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
if(m_position.PositionType()==pos_type) // gets the position typeif(Hour()>TimeClose)
m_trade.PositionClose(m_position.Ticket()); // close a position by the specified symbol
}
Добавил условие if(Hour()>TimeClose), в переменных прописал inputdouble 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
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.
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.
I didn't mean a pending order, but the ability to close a market order on time, even if it is losing.
Code:
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.
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':
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.
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
It is necessary that an open position is forcibly closed at a certain time
Have you read the article? Can you modify the code?
Did you read the article? Can you modify the code?
I've read the article, but it's a dark forest for me.
Watched the article, but it's a dark forest for me.
Okay, I'll put it on my agenda for tomorrow.
New version of Yesterday Today New
New version of Yesterday Today New
Vladimir, thank you for your labour. It is good when there are such experts who help users.