Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Questions/Q 5774
Next
In Process
master-mql4
master-mql4

master-mql4

  • 1 Question
  • 1 Answer
  • 0 Best Answers
  • 20 Points
View Profile
  • 0
master-mql4
Asked: December 29, 20202020-12-29T10:06:23+00:00 2020-12-29T10:06:23+00:00In: Forex Expert Advisors

Tell me PLIZ how to close an order on mql5?????

  • 0

Good afternoon!!! Please tell me on the example code how to close an order in mql5???
 For example, we have 7 open orders. Of these, 3 are for sale.
 How to select from the total mass of these 3 orders and close them?
It is strange, but there is little information on this topic in the Internet… sooo little…
Thank you very much for your help!!! 

  • 12 12 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    12 Answers

    • Voted
    • Oldest
    • Recent
    1. -aleks-

      -aleks-

      • 2 Questions
      • 35 Answers
      • 0 Best Answers
      • 72 Points
      View Profile
      -aleks-
      2020-12-29T10:07:47+00:00Added an answer on December 29, 2020 at 10:07 am

      fxsaber:

      Try the method of trial and error. I learned 99% of the information this way.

      Good advice. I just got used to discretion, so I asked if anyone had already dealt with these “rakes”.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. fxsaber

      fxsaber

      • 1 Question
      • 54 Answers
      • 0 Best Answers
      • 134 Points
      View Profile
      fxsaber
      2020-12-29T10:07:39+00:00Added an answer on December 29, 2020 at 10:07 am

      Aleksey Vyazmikin:

      That is, by the ID “DEAL_POSITION_ID” – right?

      And then how to enter a comment after the order is triggered and the transaction appears?

      Try the method of trial and error. I learned 99% of the information this way.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. -aleks-

      -aleks-

      • 2 Questions
      • 35 Answers
      • 0 Best Answers
      • 72 Points
      View Profile
      -aleks-
      2020-12-29T10:07:30+00:00Added an answer on December 29, 2020 at 10:07 am

      Vladimir Karputov:

      What’s the comment? What is it for? Do you want to catch a Stop loss or Take profit trigger?

      I conceived a system for changing the lot size depending on the growing fin result – not a certain number of traded positions is taken into account, it is necessary to identify the beginning of the calculation cycle – this requires a label, I can’t think of anything better than a comment.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    4. fxsaber

      fxsaber

      • 1 Question
      • 54 Answers
      • 0 Best Answers
      • 134 Points
      View Profile
      fxsaber
      2020-12-29T10:07:24+00:00Added an answer on December 29, 2020 at 10:07 am

      Aleksey Vyazmikin:

      Thanks! But, here’s how to understand that the transaction was related to a certain position?

      comments from the order go to the deal?

      No.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    5. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-29T10:07:17+00:00Added an answer on December 29, 2020 at 10:07 am

      Aleksey Vyazmikin:

      Thanks for the answer!

      That’s right, there can be many trades in a position that are opened with orders. I just need to find which position the order with a certain commentbelongs to , and count the fin result for transactions from this position inclusive, how can this be implemented?

      What’s the comment? What is it for? Do you want to catch a Stop loss or Take profit trigger?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    6. -aleks-

      -aleks-

      • 2 Questions
      • 35 Answers
      • 0 Best Answers
      • 72 Points
      View Profile
      -aleks-
      2020-12-29T10:07:10+00:00Added an answer on December 29, 2020 at 10:07 am

      fxsaber:

      Thanks! But, here’s how to understand that the transaction was related to a certain position?

      By the way, do comments from the order go to the deal?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    7. fxsaber

      fxsaber

      • 1 Question
      • 54 Answers
      • 0 Best Answers
      • 134 Points
      View Profile
      fxsaber
      2020-12-29T10:07:01+00:00Added an answer on December 29, 2020 at 10:07 am

      Aleksey Vyazmikin:

      Please help! How to sort out the financial result of closed positions?

      Forum on trading, automated trading systems and testing trading strategies

      History Profit in MQL5 ?

      fxsaber, 2017.08.26 19:16

      1. MQL5double Profit( void )
        {
        double Res = 0;

        if (HistorySelect(0, INT_MAX))
           for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
           {
             const ulong Ticket = HistoryDealGetTicket(i);
            
             if((HistoryDealGetInteger(Ticket, DEAL_MAGIC) == MagicNumber) && (HistoryDealGetString(Ticket, DEAL_SYMBOL) == Symbol()))
               Res += HistoryDealGetDouble(Ticket, DEAL_PROFIT);
           }
            
          return(Res);
        }

      2. MQL5 + MQL4#include //

        double Profit( void )
        {
        double Res = 0;

        for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
           if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderMagicNumber() == MagicNumber) && (OrderSymbol() == Symbol()))
             Res += OrderProfit();
            
          return(Res);
        }

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    8. -aleks-

      -aleks-

      • 2 Questions
      • 35 Answers
      • 0 Best Answers
      • 72 Points
      View Profile
      -aleks-
      2020-12-29T10:06:54+00:00Added an answer on December 29, 2020 at 10:06 am

      Please help! How to sort out the financial result of closed positions?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    9. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-29T10:06:48+00:00Added an answer on December 29, 2020 at 10:06 am

      alexhabba:

      please tell me how to close all open positions

      Example from the Autotrade Expert Advisor:

      Connecting standard library trade classes and declaring objects of these trade classes

      //+------------------------------------------------------------------+
      //|                           Autotrade(barabashkakvn's edition).mq5 |
      //|                      Copyright © 2006, MetaQuotes Software Corp. |
      //|                                         |
      //+------------------------------------------------------------------+
      #property copyright "Copyright © 2006, national :-)"
      #property link      "[email protected]"
      #include
      #include
      #include   
      #include
      CPositionInfo  m_position;                   // trade position object
      CTrade         m_trade;                      // trading object

      CSymbolInfo    m_symbol;                     // symbol info object
      COrderInfo     m_order;                      // pending orders object

      A function that implements the closing of all POSITIONS (not orders, but positions) 

      //+------------------------------------------------------------------+
      / / / Closing all positions by the current symbol and with the current Magic |
      //+------------------------------------------------------------------+
      void CloseAllPositions()
        {
         Print(__FUNCTION__);
         for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of open positions
            if(m_position.SelectByIndex(i))
               if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
                  m_trade.PositionClose(m_position.Ticket());
         return;
        }

      ds

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    10. alexhabba

      alexhabba

      • 0 Questions
      • 1 Answer
      • 0 Best Answers
      • 22 Points
      View Profile
      alexhabba
      2020-12-29T10:06:42+00:00Added an answer on December 29, 2020 at 10:06 am

      please tell me how to close all open positions

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    11. master-mql4

      master-mql4

      • 1 Question
      • 1 Answer
      • 0 Best Answers
      • 20 Points
      View Profile
      master-mql4
      2020-12-29T10:06:33+00:00Added an answer on December 29, 2020 at 10:06 am

      Karputov Vladimir:

       Not an order, but a POSITION. The list of positions in the terminal can be obtained: PositionsTotal

      And then go through the entire list of POSITIONS and, depending on the indicators, do anything with them. Getting position data can be seen in the positiongetinteger example:

       

      You can close a position using the CTrade class: PositionClose.

      And how to sort through all the positions? In mql4 it would be something like:

      for(int i=0;i

      {

        OrderSelect(i,SELECT_BY_POS);

         

      } 

       

      And in mql5 in the loop than to replace the function OrderSelect () …? Or positionselect is it?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    12. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-29T10:06:28+00:00Added an answer on December 29, 2020 at 10:06 am

      Andrey Kozak:

      Good afternoon!!! Please tell me on the example code how to close an order in mql5???

       For example, we have 7 open orders. Of these, 3 are for sale.

       How to select from the total mass of these 3 orders and close them?

      It is strange, but there is little information on this topic in the Internet… sooo little…

      Thank you very much for your help!!! 

       Not an order, but a POSITION. The list of positions in the terminal can be obtained: PositionsTotal

      And then go through the entire list of POSITIONS and, depending on the indicators, do anything with them. Getting position data can be seen in the positiongetinteger example:

      //+------------------------------------------------------------------+
      //| Trade function                                                   |
      //+------------------------------------------------------------------+
      void OnTrade()
        {
      / / - - - check the position and print the time of its change
      if(positionselect(_Symbol))
           {      
      / / - - - get the position ID for further work with it
            ulong position_ID=PositionGetInteger(POSITION_IDENTIFIER);
            Print(_Symbol," postion #",position_ID);
      / / - - - get the time of position formation in milliseconds from 01.01.1970
            long create_time_msc=PositionGetInteger(POSITION_TIME_MSC);
            PrintFormat("Position #%d  POSITION_TIME_MSC = %i64 milliseconds => %s",position_ID,
                        create_time_msc,TimeToString(create_time_msc/1000));
      / / - - - get the time of the last position change in seconds from 01.01.1970
            long update_time_sec=PositionGetInteger(POSITION_TIME_UPDATE);
            PrintFormat("Position #%d  POSITION_TIME_UPDATE = %i64 seconds => %s",
                        position_ID,update_time_sec,TimeToString(update_time_sec));
      / / - - - get the time of the last position change in milliseconds from 01.01.1970
            long update_time_msc=PositionGetInteger(POSITION_TIME_UPDATE_MSC);
            PrintFormat("Position #%d  POSITION_TIME_UPDATE_MSC = %i64 milliseconds => %s",
                        position_ID,update_time_msc,TimeToString(update_time_msc/1000));
           }
      //---
        }

       

      You can close a position using the CTrade class: PositionClose.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 504
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 681
    • Popular
    • Comments
    • Tags
    • forexcommunity

      Highlighting what’s important about questions & Answers on Discy Community!

      • 0 Comments
    • forexcommunity

      Introducing Keyboard Shortcuts, our first Labs feature

      • 0 Comments
    • forexcommunity

      Defining quality on Discy Engine — what a helpful answer ...

      • 0 Comments
    • forexcommunity

      Organizational and company accounts on Discy Engine the next step

      • 0 Comments
    • forexcommunity

      Hello world!

      • 0 Comments

    Related Questions

    • Brus Agell

      Правельный выбор

      • 0 Answers
    • pinupcasinoo

      Pin Up Casino

      • 0 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 2 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 0 Answers
    • c00l777

      Optimization results differ on different accounts

      • 3 Answers

    Users

    Leonardcig

    Leonardcig

    • 0 Questions
    • 0 Answers
    DennisByday

    DennisByday

    • 0 Questions
    • 0 Answers
    Haroldmeary

    Haroldmeary

    • 0 Questions
    • 0 Answers

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved