Position vs. Deal vs. Order

To add comments, please log in or register
samjesse
749
samjesse  

Hi

Reading the docs, and applying the info to the functions I find it confusing.

Under the heading "Position Properties" https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties

In the second line, It states: "For each financial security (symbol) only one open position is possible."

So the below code should not print out all the "deals" but only the "position", which does not make any sense, because it actually prints all the "deals" and not the positions according to the docs description.

      for(int i = 0; i < PositionsTotal(); i++) {
        if(_Symbol == PositionGetSymbol(i)){ 
          ulong ticketNo = PositionGetTicket(i);
          if(PositionSelectByTicket(ticketNo)){
            Print("TicketNo: ", ticketNo, " Symbol: ", PositionGetString(POSITION_SYMBOL), " P/L: ", PositionGetDouble(POSITION_PROFIT));
          } else {
            Print("couldn't select the position");
          }
        }
      }

considering that the "Deal Properties"  https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties

the first line states "A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request."


The reason for this question is that the code below failed to close a profitable "deal" with a market order but rather placed a limit order, Why is that? and your comments on the subject title as well. 

Many thanks.


      for(int i = 0; i < PositionsTotal(); i++) {
        if(_Symbol == PositionGetSymbol(i)){
          ulong ticketNo = PositionGetTicket(i);
          if(PositionSelectByTicket(ticketNo)){
            if(PositionGetDouble(POSITION_PROFIT) > 0) {
              mTrade.PositionClose(ticketNo);   // <<<<<<<<<<<<<<<<<<<<<< opened a limit order in the opposite direction to the only one open "deal"
              mRequestResult = mTrade.ResultRetcode();
              if (mRequestResult != TRADE_RETCODE_DONE) {
                StringConcatenate(mNote, mNote, " fail code: ", mRequestResult);
              }
            }
          } else {
            Print("couldn't select the position");
          }
        }
      }
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position ticket. Unique number assigned to each newly opened position. It usually matches the ticket of an order used to open the position except when the ticket is changed as a result of service operations on the server, for example, when charging swaps with position re-opening. To find an order used to open a position, apply the...
Alain Verleyen
38255
Alain Verleyen  
samjesse:

Hi

Reading the docs, and applying the info to the functions I find it confusing.

Under the heading "Position Properties" https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties

In the second line, It states: "For each financial security (symbol) only one open position is possible."

That's outdated information. Years ago MT5 had only netting account, where only 1 position can be open.

The documentation need to be updated.

So the below code should not print out all the "deals" but only the "position", which does not make any sense, because it actually prints all the "deals" and not the positions according to the docs description.

considering that the "Deal Properties"  https://www.mql5.com/en/docs/constants/tradingconstants/dealproperties

the first line states "A deal is the reflection of the fact of a trade operation execution based on an order that contains a trade request."

This code prints the position information,can be several operations on an hedging account. It has nothing to do with deals.

The reason for this question is that the code below failed to close a profitable "deal" with a market order but rather placed a limit order, Why is that? and your comments on the subject title as well. 

Many thanks.


A deal can't be closed, a deal is never "open". You are confusing positions, deals and orders.

This code CAN'T placed a limit order, that's just not possible. It can eventually send a market order, which will result in an opposite direction position on a netting account.

        if(_Symbol == PositionGetSymbol(i)){
          ulong ticketNo = PositionGetTicket(i);
          if(PositionSelectByTicket(ticketNo)){

These 3 statements are redundant and should never be used together.

  • Use PositionGetSymbol() only on a netting account.
  • Use PositionGetTicket() on an hedging account, then PositionGetString(PositionGetString(POSITION_SYMBOL) to check it's the symbol you want.
  • If you have a recorded ticket, you can use PositionSelectByTicket(), usable on netting and hedging account.

Please do some researches on the forum, code to close an open position (on netting or hedging) has been posted several times.

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • www.mql5.com
The ultimate goal of a trader is to extract profits through the means of trading operations on the financial markets. This article describes the terms and processes of the MetaTrader 5 trading platform, the knowledge of which is necessary for a proper understanding of the work of trade functions of the MQL5 language. Orders — are the trade...
To add comments, please log in or register