Discussion of article "Using limit orders instead of Take Profit without changing the EA's original code"
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.
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);
}
}
@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!
Hello Dmitry,
Thank you for your interesting article!
Please, would you explain error "paramter passed as reference, variable expected" related of each of the following lines (line 54, 55, 56)?
CSymbolInfo CLimitTakeProfit::c_Symbol = new CSymbolInfo();
CArrayLong CLimitTakeProfit::i_TakeProfit = new CArrayLong();
CArrayDouble CLimitTakeProfit::d_TakeProfit = new CArrayDouble();
Thanks!
Hello Dmitry,
Thank you for your interesting article!
Please, would you explain error "paramter passed as reference, variable expected" related of each of the following lines (line 54, 55, 56)?
CSymbolInfo CLimitTakeProfit::c_Symbol = new CSymbolInfo();
CArrayLong CLimitTakeProfit::i_TakeProfit = new CArrayLong();
CArrayDouble CLimitTakeProfit::d_TakeProfit = new CArrayDouble();
Thanks!
Hi, do you use?
#include <Arrays\ArrayDouble.mqh> #include <Arrays\ArrayLong.mqh> #include <Trade\SymbolInfo.mqh>
Hi Dmitry,
The following lines are exactly written on your "LimitTakeProfit.mqh":
#include <Arrays\ArrayDouble.mqh> #include <Arrays\ArrayLong.mqh> #include <Trade\SymbolInfo.mqh>
More precisely, such error "paramter passed as reference, variable expected" come from compilation of your EA "MACD Sample LImitTP.mq5".
Thank you for answering!
Hi Dmitry,
The following lines are exactly written on your "LimitTakeProfit.mqh":
More precisely, such error "paramter passed as reference, variable expected" come from compilation of your EA "MACD Sample LImitTP.mq5".
Thank you for answering!
Hi, you must add * before paprameter
CSymbolInfo *CLimitTakeProfit::c_Symbol = new CSymbolInfo(); CArrayLong *CLimitTakeProfit::i_TakeProfit = new CArrayLong(); CArrayDouble *CLimitTakeProfit::d_TakeProfit = new CArrayDouble();

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.
Author: Dmitriy Gizlyk