# EA take profit and stop loss in percentage

145

Good evening you all,

I have this Expert Advisor in which I can set take profit and stop loss in points. I want to change this parameter with the percentage of the investiment. For example, when the profit is at 25% of the amount invested or when the loss is at -70% of the amount invested the investiment will close. I hope someone will help me. Have a good day.

```//---- input parameters
extern double   Lots=0.1;
extern int      TakeProfit=60;
extern int      StopLoss=150;
extern int      Slip=5;
extern string   TradeSettings="Mt4 time(min-max): hours 0-23, minutes 0-59, seconds 0-59";
extern bool     AllowSell=true;
extern string   MagicNumbers="To be changed in case of conflict with other EAs";
extern int      SellMagicNumber =10002;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert starts                                  |
//+------------------------------------------------------------------+

int start()
{
//----
int StopMultd,Sleeper=1;

int digits=MarketInfo("EURUSD",MODE_DIGITS);
StopMultd=10;
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
int Slippage=Slip*StopMultd;

// Calculate stop loss
double sls=NormalizeDouble(Bid+SL*Point,Digits); //

// Calculate take profit
double tps=NormalizeDouble(Bid-TP*Point,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(OrderMagicNumber()==SellMagicNumber) {int halt2=1;}
}
}
}
//-------------------------------------------------------------------+

{
}

}// halt1

if((halt2!=1)&&(AllowSell==true)){// halt2
RefreshRates();
// Sell criteria
{
int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"time trader sell order ",SellMagicNumber,0,Green);
if(opensell<1){int sellfail=1;}
}

}// halt2

//-----------------------------------------------------------------------------------------------------
if(OrdersTotal()>0){
for(i=1; i<=OrdersTotal(); i++){          // Cycle searching in orders

if (OrderSelect(i-1,SELECT_BY_POS)==true){ // If the next is available

if((OrderMagicNumber()==SellMagicNumber)&&(OrderTakeProfit()==0||OrderStopLoss()==0)) { OrderModify(OrderTicket(),0,sls,tps,0,CLR_NONE); }

}
}
}
//-------------------------------------------------------------------+
// Error processing
//-------------------------------------------------------------------+
int Error=GetLastError();