MQL5 orderclose

 

Why mql5 don't have and ORDERCLOSE function like mql4 and have a library for that?

is there is a reason?

 
Abdelrahman Shehata :

Why mql5 don't have and ORDERCLOSE function like mql4 and have a library for that?

is there is a reason?

To get started, read the help: Basic Principles

Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position.

  • An order is an instruction given to a broker to buy or sell a financial instrument. There are two main  types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels.
  • A deal is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the supply price (Bid). A deal can be opened as a result of market order execution or pending order triggering. Note that in some cases, execution of an order can result in several deals.
  • A position is a trade obligation, i.e. the number of bought or sold contracts of a financial instrument. A long position is financial security bought expecting the security price go higher. A short position is an obligation to supply a security expecting the price will fall in future.

And to open and close positions you need to use the standard library and trading class  CTrade

Operations with positions

 

PositionOpen

Opens a position with specified parameters

PositionModify

Modifies position parameters by the specified symbol or position ticket

PositionClose

Closes a position for the specified symbol

PositionClosePartial

Partially closes a position on a specified symbol or having a specified ticket

PositionCloseBy

Closes a position with the specified ticket by an opposite position


Example script: it opens a BUY position. In this case, you can set Stop loss and Take profit.
Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
Abdelrahman Shehata:

Why mql5 don't have and ORDERCLOSE function like mql4 and have a library for that?

#property script_show_inputs

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

input TICKET_TYPE TicketToClose = 0;

void OnStart()
{
  if (OrderSelect(TicketToClose, SELECT_BY_TICKET) && (OrderType() <= OP_SELL))
    OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);  
}
 
fxsaber #:

Hi @fxsaber thanks a lot for providing that library, awesome! 👏👏👏

Do you think you could publish it on GitHub or any other Git provider? This way we could always have automated access to the last revision via version control.

It may even get contributions :o)

What do you think?

 
fxsaber #:

Amazing! Exactly what I was looking for. Thanks a lot!

Reason: