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 4902
Next
In Process
mr_lsv
mr_lsv

mr_lsv

  • 1 Question
  • 2 Answers
  • 0 Best Answers
  • 20 Points
View Profile
  • 0
mr_lsv
Asked: December 27, 20202020-12-27T05:37:57+00:00 2020-12-27T05:37:57+00:00In: Forex Expert Advisors

Partial closing of the order

  • 0

Made a block in which there is a partial closing of the position, when the price reaches a certain level: 
   for (int i=0; i   {
      if (OrderSelect(i, SELECT_BY_POS))
      {
            if (OrderType()==1)
            { 
                     Lot_61_8 = OrderLots()*Lot_Percent_61_8/100;if(Lot_61_8>OrderLots()||Lot_61_8<0.01){Lot_61_8 = OrderLots();if(Lot_61_8>100)Lot_61_8=100;}
                     Lot_61_8 = (NormalizeLot(Lot_61_8, False)); 
                     Ask_Value_61_8=OrderOpenPrice()-(61.8*OrderOpenPrice())/10000;                         
                           if (Lot_61_8>0)
                           error=OrderClose(OrderTicket(), Lot_61_8, MarketInfo(Symbol(), MODE_BID), 20, CLR_NONE);
             }  
}
} 
But the problem is that this piece works out every time the price reaches this level, because this way, in the end, I close the entire volume )) 
How can I make this close happen once and no longer be processed for this order ?  

  • 9 9 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    9 Answers

    • Voted
    • Oldest
    • Recent
    1. 1qefvnhm

      1qefvnhm

      • 0 Questions
      • 1 Answer
      • 0 Best Answers
      • 22 Points
      View Profile
      1qefvnhm
      2020-12-27T05:38:51+00:00Added an answer on December 27, 2020 at 5:38 am

      Vladimir Zubov:

      I wrote such a function, it works on ECN without problems. Use it for your health)

       

      HOW DO I ANIMATE THIS FUNCTION ? Wrote so!

      TimeBar=Time[0];

               ClosePartPosition(tr);

               if(stoploss!=0) SL=NormalizeDouble(Bid-stoploss*Point,Digits); else SL=0;

               LOT=LOT(risk,1);

               if(ORDERS(-1)==1) CLOSEORDER(-1);//Close orders opened for sale

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

      mr_lsv

      • 1 Question
      • 2 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      mr_lsv
      2020-12-27T05:38:42+00:00Added an answer on December 27, 2020 at 5:38 am

      Vladimir Zubov:
      “2” is the close half, rounding according to NormalizeDouble

      it turned out. thanks

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. ya_programmer

      ya_programmer

      • 0 Questions
      • 23 Answers
      • 0 Best Answers
      • 68 Points
      View Profile
      ya_programmer
      2020-12-27T05:38:36+00:00Added an answer on December 27, 2020 at 5:38 am

      Dmitry Fedoseev:

      In the comment of a partially closed order, the ticket of the order from which it was obtained is recorded, you can separate it, select the order in the history, etc.throughout the chain.

      You can not go through the entire chain, but create global variables linked to the ticket and transfer data only from the previous order. 

      I liked Your first idea more with a comment to the order – well, so as not to write it to global variables – analyze only the comment, without doing anything with it, and that’s it.

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

      integer

      • 0 Questions
      • 18 Answers
      • 0 Best Answers
      • 58 Points
      View Profile
      integer
      2020-12-27T05:38:26+00:00Added an answer on December 27, 2020 at 5:38 am

      See the difference between the comment of a fresh order and a partial closed one. A partially closed order can be distinguished by a comment.

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

      dken

      • 4 Questions
      • 12 Answers
      • 0 Best Answers
      • 32 Points
      View Profile
      dken
      2020-12-27T05:38:21+00:00Added an answer on December 27, 2020 at 5:38 am

      with checkboxes, this is a primitive. check in the history by the order comment which part is already closed.

      expert advisors should not depend on variables that can be reset when restarting. I somewhere in a similar topic gave here my code with the search for parts and checking which part is closed. 

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    6. ya_programmer

      ya_programmer

      • 0 Questions
      • 23 Answers
      • 0 Best Answers
      • 68 Points
      View Profile
      ya_programmer
      2020-12-27T05:38:16+00:00Added an answer on December 27, 2020 at 5:38 am

      Sergey Lapshov:

      Made a block in which there is a partial closing of the position, when the price reaches a certain level: 

      But the problem is that this piece works out every time the price reaches this level, because this way, in the end, I close the entire volume )) 

      How can I make this close happen once and no longer be processed for this order ?  

      So… ?

      What is the logic, and the code and will work.

      ….

      Each order has a ticket number. The order ticket will change when partially closed. So you will only need to remember it if you successfully close it partially.

      If error>0, this will be the order number, i.e. the ticket

      error=OrderClose(OrderTicket(), Lot_61_8, MarketInfo(Symbol(), MODE_BID), 20, CLR_NONE);

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

      artmedia70

      • 1 Question
      • 41 Answers
      • 0 Best Answers
      • 102 Points
      View Profile
      artmedia70
      2020-12-27T05:38:11+00:00Added an answer on December 27, 2020 at 5:38 am

      Sergey Lapshov:

      Made a block in which there is a partial closing of the position, when the price reaches a certain level: 

         for (int i=0; i

         {

            if (OrderSelect(i, SELECT_BY_POS))

            {

                  if (OrderType()==1)

                  { 

                           Lot_61_8 = OrderLots()*Lot_Percent_61_8/100;if(Lot_61_8>OrderLots()||Lot_61_8<0.01){Lot_61_8 = OrderLots();if(Lot_61_8>100)Lot_61_8=100;}

                           Lot_61_8 = (NormalizeLot(Lot_61_8, False)); 

                           Ask_Value_61_8=OrderOpenPrice()-(61.8*OrderOpenPrice())/10000;                         

                                 if (Lot_61_8>0)

                                 error=OrderClose(OrderTicket(), Lot_61_8, MarketInfo(Symbol(), MODE_BID), 20, CLR_NONE);

                   }  

      }

      } 

      But the problem is that this piece works out every time the price reaches this level, because this way, in the end, I close the entire volume )) 

      How can I make this close happen once and no longer be processed for this order ?  

      Before closing, check the volume of the order being closed as an option. But this is if the lots are fixed, or if the lots are not fixed, then check the volume of the closed order with the current current lot of the expert Advisor – it must be stored in the variable.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    8. mr_lsv

      mr_lsv

      • 1 Question
      • 2 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      mr_lsv
      2020-12-27T05:38:05+00:00Added an answer on December 27, 2020 at 5:38 am
      Partial closing of the order

      Sergey Gritsay:

      rf as it is, the flag variable must be reset when opening this order

      for some reason, it turns out like this:

       

       

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

      sergey1294

      • 0 Questions
      • 1 Answer
      • 0 Best Answers
      • 26 Points
      View Profile
      sergey1294
      2020-12-27T05:38:01+00:00Added an answer on December 27, 2020 at 5:38 am

      Sergey Lapshov:

      Made a block in which there is a partial closing of the position, when the price reaches a certain level: 

      But the problem is that this piece works out every time the price reaches this level, because this way, in the end, I close the entire volume )) 

      How can I make this close happen once and no longer be processed for this order ?  

      rf as it is, the flag variable must be reset when opening this order

      //+------------------------------------------------------------------+
      / / / test. mq4 |
      //|                        Copyright 2016, MetaQuotes Software Corp. |
      //|                                             |
      //+------------------------------------------------------------------+
      #property copyright "Copyright 2016, MetaQuotes Software Corp."
      #property link      "
      #property version   "1.00"
      #property strict

      bool flag=true;
      //+------------------------------------------------------------------+
      //| Expert initialization function                                   |
      //+------------------------------------------------------------------+
      int OnInit()
        {
      //---

      //---
         return(INIT_SUCCEEDED);
        }
      //+------------------------------------------------------------------+
      //| Expert deinitialization function                                 |
      //+------------------------------------------------------------------+
      void OnDeinit(const int reason)
        {
      //---

        }
      //+------------------------------------------------------------------+
      //| Expert tick function                                             |
      //+------------------------------------------------------------------+
      void OnTick()
        {
      //---
         for(int i=0; i<OrdersTotal(); i++)

           {

            if(OrderSelect(i,SELECT_BY_POS))

              {

               if(OrderType()==1)

                 {

                  Lot_61_8=OrderLots()*Lot_Percent_61_8/100;if(Lot_61_8>OrderLots() || Lot_61_8<0.01){Lot_61_8=OrderLots();if(Lot_61_8>100)Lot_61_8=100;}

                  Lot_61_8=(NormalizeLot(Lot_61_8,False));

                  Ask_Value_61_8=OrderOpenPrice()-(61.8*OrderOpenPrice())/10000;

                  if(Lot_61_8>0 && flag)
                    {
                     error=OrderClose(OrderTicket(),Lot_61_8,MarketInfo(Symbol(),MODE_BID),20,CLR_NONE);
                     if(error)flag=false;
                     else PrintFormat("Error # %d closing the order. Ticket: %d", GetLastError(),OrderTicket());

                    }

                 }

              }

           }
        }
      //+------------------------------------------------------------------+

      • 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 677
    • 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

    HiramJanny

    HiramJanny

    • 0 Questions
    • 0 Answers
    Geraldimaky

    Geraldimaky

    • 0 Questions
    • 0 Answers
    Jeffreytix

    Jeffreytix

    • 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