how to partially close an 'open order' automatically on a specified profit target and how to open multiple positions simultaneously at same price, same stop loss but different profit taking targets.?

 

Hi guys,  

    I am looking for two answers here. First to partially close an open order automatically on a specified profit target. I know that i can do that manually at market value by right clicking on the 'order', going to 'close order' and change the 'volume' as desired and close the partial position at the market value. But that is not what i want. For example, i have opened a long position of 3 lots on eurusd at a price of 1.3010 and my stop lose is 10 pips away at 1.3000. Now i want to close down my position part by part such as the 1st lot at a profit target of 1.3020, 2nd at 1.3040 and the last lot at 1.3080 automatically by modifying the order. So... how can i do this..

My second question is  that is there any option in metatrader to open multiple positions simultaneously at same price and same stop lose but different profit targets?. suppose i want to place 3 different buy orders on a currency pair simultaneously at 1.2500 on  a stop lose 10 pips away from my entry price, but the profit targets to be 1.2510, 1.2530, 1.2560 accordingly.

 Even though i am a newbie to trading , i am ready to take any hard work to get this done, such as writing scripts or EA. But i dont know to write any codes or something, but if somebody is kind enough to give me a start, i will do it.

Thanks in advance. 

 
raicemongeorge:

Hi guys,  

    I am looking for two answers here. First to partially close an open order automatically on a specified profit target. I know that i can do that manually at market value by right clicking on the 'order', going to 'close order' and change the 'volume' as desired and close the partial position at the market value. But that is not what i want. For example, i have opened a long position of 3 lots on eurusd at a price of 1.3010 and my stop lose is 10 pips away at 1.3000. Now i want to close down my position part by part such as the 1st lot at a profit target of 1.3020, 2nd at 1.3040 and the last lot at 1.3080 automatically by modifying the order. So... how can i do this..

My second question is  that is there any option in metatrader to open multiple positions simultaneously at same price and same stop lose but different profit targets?. suppose i want to place 3 different buy orders on a currency pair simultaneously at 1.2500 on  a stop lose 10 pips away from my entry price, but the profit targets to be 1.2510, 1.2530, 1.2560 accordingly.

 Even though i am a newbie to trading , i am ready to take any hard work to get this done, such as writing scripts or EA. But i dont know to write any codes or something, but if somebody is kind enough to give me a start, i will do it.

Thanks in advance. 

You should consider to start with the book and look at the EAs and scripts in the codebase.

1. Question: You need an EA what controls your open positions and close them according to the logic in the code. 
2. Question: Can be done by use of pending orders or again with an EA.

What you are looking for can be done of course, but you have to write many lines of code. I doubt someone will do it for you. If you start with your code and have specific question post it here and the forum users will help you.

 

If you prefer simple solution as a beginner and your broker allows hedging, then do not set TP to your open order, but instead place multiple limit orders in place of partial targets. After any gets filled, you may close the hedge manually or by a very simple EA like that:

int start() {
   closeHedge();
}

void closeHedge() {
   int sellNo = getSell();
   int buyNo = getBuy();
   if (sellNo > 0 && buyNo > 0) {
      if (OrderCloseBy(buyNo, sellNo)) {
         Print ("Hedge closed");
         closeHedge();
      } else {
         Print("Error closing hedge: " + GetLastError());
      }      
   }
}

/** returns order number */
int getBuy() {
   for (int i = OrdersTotal() - 1; i>=0;i--) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_BUY) {
               return (OrderTicket());
            }
         }
      }
   }   
   return(0);
}


/** returns order number */
int getSell() {
   for (int i = OrdersTotal() - 1; i>=0;i--) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderType() == OP_SELL) {
               return (OrderTicket());
            }
         }
      }
   }   
   return(0);
} 
 
raicemongeorge:

Hi guys,  

    I am looking for two answers here. First to partially close an open order automatically on a specified profit target. I know that i can do that manually at market value by right clicking on the 'order', going to 'close order' and change the 'volume' as desired and close the partial position at the market value. But that is not what i want. For example, i have opened a long position of 3 lots on eurusd at a price of 1.3010 and my stop lose is 10 pips away at 1.3000. Now i want to close down my position part by part such as the 1st lot at a profit target of 1.3020, 2nd at 1.3040 and the last lot at 1.3080 automatically by modifying the order. So... how can i do this..

My second question is  that is there any option in metatrader to open multiple positions simultaneously at same price and same stop lose but different profit targets?. suppose i want to place 3 different buy orders on a currency pair simultaneously at 1.2500 on  a stop lose 10 pips away from my entry price, but the profit targets to be 1.2510, 1.2530, 1.2560 accordingly.

 Even though i am a newbie to trading , i am ready to take any hard work to get this done, such as writing scripts or EA. But i dont know to write any codes or something, but if somebody is kind enough to give me a start, i will do it.

Thanks in advance. 

As to question 1: Yes, you can do that in an EA.  Use OrderClose().  Simply specify the number of lots you wish to liquidate.  Remember to error check (see What are Function return values ? How do I use them ?).

As to question 2: Yes, you can do that too, so long as your broker doesn't enforce FIFO rules (see discussion here). 

If you are serious about learning to code, read the Book and study the Documentation.  Use those two resources (along with the discussions here in the forum) to educate yourself about syntax and operations.  But don't expect someone to just give you the answers.  There are many people here who reward honest learning with honest teaching, so if you make the honest effort to learn to code, this forum will help you with answers and guidance.   

 
Thirteen:

As to question 1: Yes, you can do that in an EA.  Use OrderClose().  Simply specify the number of lots you wish to liquidate.  Remember to error check (see What are Function return values ? How do I use them ?).

As to question 2: Yes, you can do that too, so long as your broker doesn't enforce FIFO rules (see discussion here). 

If you are serious about learning to code, read the Book and study the Documentation.  Use those two resources (along with the discussions here in the forum) to educate yourself about syntax and operations.  But don't expect someone to just give you the answers.  There are many people here who reward honest learning with honest teaching, so if you make the honest effort to learn to code, this forum will help you with answers and guidance.   

Thirteen:

As to question 1: Yes, you can do that in an EA.  Use OrderClose().  Simply specify the number of lots you wish to liquidate.  Remember to error check (see What are Function return values ? How do I use them ?).

As to question 2: Yes, you can do that too, so long as your broker doesn't enforce FIFO rules (see discussion here). 

If you are serious about learning to code, read the Book and study the Documentation.  Use those two resources (along with the discussions here in the forum) to educate yourself about syntax and operations.  But don't expect someone to just give you the answers.  There are many people here who reward honest learning with honest teaching, so if you make the honest effort to learn to code, this forum will help you with answers and guidance.   


Thank you so much for your effort to answer my question. I will keep in mind your advise. And i will definitely go through the book and try my level best to write some scripts of my need.

 
Ovo:

If you prefer simple solution as a beginner and your broker allows hedging, then do not set TP to your open order, but instead place multiple limit orders in place of partial targets. After any gets filled, you may close the hedge manually or by a very simple EA like that:



Thank you Ovo for your help.. But i dont think your idea will work out for me. I try to trade the market by price action with less indicators. So when ever i see a price action signal bar, i want to open a stop or limit order at a price which i think is the right price , and scalp out half of my open trade at a 1:1 or 1:2 ratio and swing the rest for a measured move target or something. Now what happens is that, when i open 2 lots of eurusd (it is my favorite pair), long or short at the'right price' with a SL and PT of my choice, i can modify anything after executing the order except 'volume traded'. This is what i hate and because of this i have found myself sitting on sidelines after forced out of a good trade with only a small scalp. 

 
kronin:

You should consider to start with the book and look at the EAs and scripts in the codebase.

1. Question: You need an EA what controls your open positions and close them according to the logic in the code. 
2. Question: Can be done by use of pending orders or again with an EA.

What you are looking for can be done of course, but you have to write many lines of code. I doubt someone will do it for you. If you start with your code and have specific question post it here and the forum users will help you.

Thank you very much for your links Kronin.. I try to trade the market by price action with less indicators. So when ever i see a price action signal bar, i want to open a stop or limit order at a price which i think is the right price , and scalp out half of my open trade at a 1:1 or 1:2 ratio and swing the rest for a measured move target or something. Now what happens is that, when i open 2 lots of eurusd (it is my favorite pair), long or short at the'right price' with a SL and PT of my choice, i can modify anything after executing the order except 'volume traded'. This is what i hate and because of this i have found myself sitting on sidelines after forced out of a good trade with only a small scalp. 

Yes...  i can  open multiple positions simultaneously at the same price and same stop lose but different profit targets with pending orders, but only if i trade using higher time frame charts and signals. But i try to trade off a 5 min chart where price movements are fast and most of the time i cannot open two pending orders of the same price using a same signal bar because of the price movements are very fast . Excuse me if i am a fool..

 
hi i need add code for trailing stop with target for example i open 25 order when i profit 2 dollar trailing stop start or close all ordrs in profit 2 dollar
22:00
in this expert thank you
 
Mohammed Attou #: i need add code for trailing stop with target for example i open 25 order when i profit 2 dollar trailing stop start or close all ordrs in profit 2 dollar
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Do you really expect that people are still watching this thread after ten (10) years?
    Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. (2014)

  3. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
              No free help (2017)

 
William Roeder #:
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Do you really expect that people are still watching this thread after ten (10) years?
    Don't resurrect old threads without a very good reason. A lot has changed since Build 600 and Higher. (2014)

  3. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
              No free help (2017)

thank you i fixet 

Reason: