Discussion of article "Using limit orders instead of Take Profit without changing the EA's original code"

To add comments, please log in or register
MetaQuotes
Moderator
213423
MetaQuotes  

New article Using limit orders instead of Take Profit without changing the EA's original code has been published:

Using limit orders instead of conventional take profits has long been a topic of discussions on the forum. What is the advantage of this approach and how can it be implemented in your trading? In this article, I want to offer you my vision of this topic.

In various forums, users criticize MetaTrader 5 for its market performance of take profit levels. Such posts can be found on this website forum as well. Users write about the negative impact of a slippage on the financial result during take profit execution. As an alternative, some propose using limit orders for replacing a standard take profit.

On the other hand, the use of limit orders, in contrast to the standard take profit, allows traders to build an algorithm for partial and stage-by-stage closing of positions, since in the limit order, you can specify a volume different from the position's one. In this article, I want to offer one of the possible options for implementing such a take profit substitution.

I believe, there is no point in arguing about what is better — the built-in take profit or limit orders replacing it. Every trader should solve this issue on the basis of their strategy principles and requirements. This article simply offers one of possible solutions.

EA operation

Author: Dmitriy Gizlyk

Mayank Jain
45
Mayank Jain  

Hi Dmitriy,


Thanks for writing this post - has been very helpful.

Would you be able to describe how the MACD sample EA works? The entry and exit rules & what they mean?


Cheers!

Dmitriy Gizlyk
22796
Dmitriy Gizlyk  
makuchaku:

Hi Dmitriy,


Thanks for writing this post - has been very helpful.

Would you be able to describe how the MACD sample EA works? The entry and exit rules & what they mean?


Cheers!

Hello,
This EA not for trade on real account, just example. It open deal at MACD line cross signal line and exit by TP1 and TP2 limit orders.

Regards,
Dmitriy.

owneroxxor
46
owneroxxor  
This is all I ever wanted, thank you SO MUCH. Love you.
mehdiparyab
7
mehdiparyab  

Hi dear

i try to find the way to defined the special Take Profit for my expert that i started to write it. your text was useful for me but i could not correct mine, so , if it is possible to you , please guide me. my TP plane is: when set the for example Buy in chart and it go in right way and profit, TP value move to maximum profit point, so when the trend turn change the straight to down way , TP value placed in 70 percent of maximum profit. below cod is the code which i write. please let me know m wrongs and help me to correct them.

 double BuyPipsProfit,SellPipsProfit,BuyProfitLevel,SellProfitLevel;
   double TP_Buy=0;
   double TP_Sell=0;
  
   for(int i=OrdersTotal()-1;i>=0;i--)                                    
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
        BuyPipsProfit= Ask-(double)OrderOpenPrice() ;
        SellPipsProfit= (double)OrderOpenPrice()-Bid;
        BuyProfitLevel= BuyPipsProfit*.7;
        SellProfitLevel= SellPipsProfit*.7;
        TP_Buy = (50*Point)+ ((OrderOpenPrice()+ BuyProfitLevel)*Point);
        TP_Sell= (50*Point)+ ((OrderOpenPrice()+ SellProfitLevel)*Point);
       }
      }

Airton Gomes Finoti
219
Airton Gomes Finoti  

@MetaQuotes, thanks for this code!

I have found a bug  in this function and give my humble solution:

bool CLimitTakeProfit::SetTakeProfits(ulong position_ticket, double new_tp=0)


If we have 2 TP and the first one have been closed, the second one will be WRONG closed here:

if(CheckLimitOrder(tp_request))
  {
   if(tp_request.volume>=0)
     {
      closed+=tp_request.volume;
      closed_perc=closed/position_volume*100;
     }
   else
     {
      fix_closed_per-=tp_request.volume/(position_volume-tp_request.volume)*100;
     }
   continue;
  }


Why? Because when searching for the first TP in this function:

CheckOrderInHistory(PositionGetInteger(POSITION_IDENTIFIER),request.comment, request.type, request.volume);

We change the selected position, so, in the loop:

   for(int i=0;i<total;i++)
     {

      tp_request.comment="TP"+IntegerToString(i)+"_"+IntegerToString(position_ticket);
      
      if(i_TakeProfit.At(i)<tp_int && d_TakeProfit.At(i)>0)

We use the wrong position to evaluate second TP here:

switch((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))


Causing the second TP to be closed! My fix is:

for(int i=0;i<total;i++)
   {
      /****** NEW LINE **************/
      PositionSelectByTicket(position_ticket);
      /****** NEW LINE **************/

      tp_request.comment="TP"+IntegerToString(i)+"_"+IntegerToString(position_ticket);
      
      if(i_TakeProfit.At(i)<tp_int && d_TakeProfit.At(i)>0)


Thanks again!

To add comments, please log in or register