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

 

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

 
  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++)
                {
                OrderSelect(cnt,SELECT_BY_POS);
    
    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
    

 
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;
                if(OrderType()==OP_BUY)
                SLp = OrderOpenPrice()-StopLossPips*Point;
                else if(OrderType()==OP_SELL)
                SLp = OrderOpenPrice()+StopLossPips*Point;
                SLp = NormalizeDouble(SLp, Digits); 
        }
        
        OrderModify(OrderTicket(),OrderOpenPrice(),SLp,TPp,0);
}
 
Excellent works very well. For those with problems modifying open orders, well this is the script. It can be easily incorporated into any EA
 

Hi,

I could not make it to work...

Can anyone help?

Thanks

 
Hi, where i can put the file to make it work?
 
Work Good For Me ..
Thanks..
 
Please guide me how can i run this indicator ??????????
 
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.
 

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: linfx3333@gmail.com

Thanks.

 

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.

Reason: