Download MetaTrader 5

Experts: Tool to auto-Insert Take-Profit & Stop-Loss limits.

To add comments, please log in or register
Having troubles understanding the code? Articles can help you!
MetaQuotes Software Corp.
MetaQuotes Software Corp. 2010.12.24 08:51 

Tool to auto-Insert Take-Profit & Stop-Loss limits.:

A tool to auto insert preset Take-Profit and Stop-Loss limits when an order is executed. Specially when doing scalping manually where you need quick setting of stop limits.

Author: Imran Latif

whroeder1 2010.12.24 18:51  
  1. if(Close[0]>10)  {Faktor=1000; Digt=3;}  else
    if(Close[0]<10)  {Faktor=100000; Digt=5;}
    EA's should auto adjust for tp, sl, and slippage
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl

  2. if(OrdersTotal()!=0)
             for(cnt=0; cnt<OrdersTotal(); cnt++)
    Always count down, check return codes. The IF is redundant.
    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)             // Only my orders w/
    //&&  OrderMagicNumber() == Magic.Number          // my magic number
    &&  OrderSymbol()      == Symbol() ){           // and period and symbol

karceWZROKIEM 2010.12.27 23:38  
insted of
if(Close[0]>10)  {Faktor=1000; Digt=3;}  else
if(Close[0]<10)  {Faktor=100000; Digt=5;}

You could do sth like this:

//---------------Modify Order--------------------------
if ( (OrderType()==OP_BUY || OrderType()==OP_SELL) && (OrderStopLoss()==0 || OrderTakeProfit()==0) && OrderSymbol()==Symbol() )   
        if( OrderTakeProfit()==0 && TakeProfitPips !=0 )
                TPp = 0;
                if(OrderType()==OP_BUY )
                TPp = OrderOpenPrice()+TakeProfitPips*Point;
                else if(OrderType()==OP_SELL)                     
                TPp = OrderOpenPrice()-TakeProfitPips*Point;
                TPp = NormalizeDouble(TPp, Digits);
        if(OrderStopLoss()==0 && StopLossPips !=0)
                SLp = 0;
                SLp = OrderOpenPrice()-StopLossPips*Point;
                else if(OrderType()==OP_SELL)
                SLp = OrderOpenPrice()+StopLossPips*Point;
                SLp = NormalizeDouble(SLp, Digits); 
MQL4 Comments
MQL4 Comments 2011.01.14 03:14  
Excellent works very well. For those with problems modifying open orders, well this is the script. It can be easily incorporated into any EA
ilan bernhard
ilan bernhard 2011.06.24 16:43  


I could not make it to work...

Can anyone help?


Eng How Tan
Eng How Tan 2012.03.30 11:15  
Hi, where i can put the file to make it work?
Alonedevils 2013.11.12 09:09  
Work Good For Me ..
karimfayazi 2013.12.18 13:45  
Please guide me how can i run this indicator ??????????
sgsummers 2015.08.09 20:16  
Loads up and installs fine on New MT4 version. Haven't tried it live yet but for those asking how to install... File>open data folder>MQL4>Experts. Place the file in here. On your chart you need to open the navigator, then go to the experts and drag it to your charts. The option for the EA will pop up and you can enter your stop loss and take profit values. All I know so far.
lin z
lin z 2015.11.11 07:02  

Hi All,

I did put the indicator into my MT4. But it's not working when I execute the order. Can anyone help me, please?

If you have the working indicator, could you please send it to my email:


Taufiq 2016.05.13 14:57  

I tried to replace the scripts with the suggestions of whroeder and karce but still not working. There were a lot of error messages when compiling.

Could anyone show the entire final script please?

Thank you.

To add comments, please log in or register