Automatic SL & TP

 
hi

i am serching for script or ea to set an automatic sl and tp

example :

i opened trade on eur/usd on : 1.20000

i want the script to set sl on 1.19950

and tp on 1.20050

without any move from me and in few seconds to avoid price change

.

can any one help me please ?

 
I created a free ea that does that long time ago. Its free so just search for a ea called Autostop in mql4 search box. I cant post the link now as im posting from mobile.
 
tonny:
I created a free ea that does that long time ago. Its free so just search for a ea called Autostop in mql4 search box. I cant post the link now as im posting from mobile.

magdymego97:
hi

i am serching for script or ea to set an automatic sl and tp

example :

i opened trade on eur/usd on : 1.20000

i want the script to set sl on 1.19950

and tp on 1.20050

without any move from me and in few seconds to avoid price change

.

can any one help me please ?

your EA is not doing in few seconds the modify
 
magdymego97:
hi

i am serching for script or ea to set an automatic sl and tp

example :

i opened trade on eur/usd on : 1.20000

i want the script to set sl on 1.19950

and tp on 1.20050

without any move from me and in few seconds to avoid price change

.

can any one help me please ?


Here is the link https://www.mql5.com/en/code/10829
 
Crap coding yours
tonny:

Here is the link https://www.mql5.com/en/code/10829
//+------------------------------------------------------------------+
//|                                              Autostop.mq4 |
//|                            Copyright © 2012, www.FxAutomated.com |
//|                                       http://www.FxAutomated.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, www.FxAutomated.com"
#property link      "http://www.FxAutomated.com"
 
extern string    Product="Autostop v2";
extern string    AboutAutostop="Automatically sets take profit and stop loss.";
extern bool      MonitorTakeProfit=true;
extern bool      MonitorStopLoss=true;
extern double    TakeProfit=30;
extern double    StopLoss=30;
 
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
   int StopMultd=10;
   double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
   double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
   
 //-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
  for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {
          if((MonitorTakeProfit==true)&&(TakeProfit>0)&&(OrderMagicNumber()==0)){ // monitor tp
          
                // Calculate take profit
                double tpb=NormalizeDouble(OrderOpenPrice()+TP*Point,Digits);
                double tps=NormalizeDouble(OrderOpenPrice()-TP*Point,Digits);
                    
                Comment("Modifying take profit");
                if((OrderType()==OP_BUY)&&(OrderTakeProfit()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,OrderStopLoss(),tpb,0,CLR_NONE); }
                if((OrderType()==OP_SELL)&&(OrderTakeProfit()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,OrderStopLoss(),tps,0,CLR_NONE); }
 
          } // monitor tp
          
          if((MonitorStopLoss==true)&&(StopLoss>0)&&(OrderMagicNumber()==0)){ // monitor sl
          
                   // Calculate stop loss
                   double slb=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);
                   double sls=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits);
 
                   Comment("Modifying stop loss");
                   if((OrderType()==OP_BUY)&&(OrderStopLoss()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,slb,OrderTakeProfit(),0,CLR_NONE); }
                   if((OrderType()==OP_SELL)&&(OrderStopLoss()==0)&&(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,sls,OrderTakeProfit(),0,CLR_NONE); }
 
          }// monitor sl
          Comment("");
        }
     }
}
//----
int Error=GetLastError();
  if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
  if(Error==133){Alert("Trading prohibited.");}
  if(Error==2){Alert("Common error.");}
  if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}
 
//----------
   return(0);
  }
//----------
 
//+-----------------------------------END-------------------------------+
//+---------------------------------------------------------------------+
 
int init()
  {
//----
   //Alert("Visit www.XXXXXXXXXXXXXXXXXXXXX.com for more goodies!");   //wasted time
//----
   return(0);
  }

how often do you need to modify one trade for placing a Stoploss and TakeProfitLevel

what help do you get from

int Error=GetLastError();
  if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
  if(Error==133){Alert("Trading prohibited.");}
  if(Error==2){Alert("Common error.");}
  if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}
 
tonny:

johnytrader:

Hello,

I tried this EA but I see that it takes a long time to place the SL and TP. It took it at least 1 minute after I took a trade. On another case it placed the stop pretty fast but it took 30 sec to place the TP. Is there anything I can do on my end to make it work instantly?

Thanks


It depends on the speed of your computer, internet, and broker's server to modify trades.

do you really think your coding is made well ....

 
tonny:

Here is the link https://www.mql5.com/en/code/10829


i saw a lot of pepole say its slow to modfiy the orders and i work on 5 digits system

thats mean price can make a big change in few seconds

 
Download and test it on your side let dog bark because his work only gets a thousand downloads while mine gets more than ten thousand. Pssst. DONT FEED THE TROLL AS THEY WILL GET STRONGER AND DO MORE TROLLING.
 

its worked with me its little bit slow but its fine

but i have problem

when i open it its make the tp ok but the sl its giive me alert "wrong stops, retrying" and its still repat

 
magdymego97:

its worked with me its little bit slow but its fine

but i have problem

when i open it its make the tp ok but the sl its giive me alert "wrong stops, retrying" and its still repat

Yep, find better code that tests trading function return values and reports errors correctly and also checks that the desired modification meets these requirements: Requirements and Limitations in Making Trades

It's not rocket science but it's beyond most people . . .
 

It is sad you get allert

refreshrates get done for nothing

and start again with new tick

 
magdymego97:

its worked with me its little bit slow but its fine

but i have problem

when i open it its make the tp ok but the sl its giive me alert "wrong stops, retrying" and its still repat


Wrong stops could mean you set stop loss lower than your broker requirements. Iv'e never said I'm the best coder in mql4/5 but i do my best to share my knowledge and stuff with those who don't know how to code. If you look at the publish date its in 2012 and im a lot better a coder now than then and iv'e been trying to update them but many times it takes several months before admin publishes them to the public its like they no longer give a damn about codebase. Iv'e been a little busy nowadays but ill look for time to update my old codes in codebase and hopefully moderator or admin wont take 4-6 months to publish them. To all those who've been supporting me all this time thanks again and ill continue doing my best to share with you my knowledge in mql.
Reason: