Need to Add TP, SL and TS to this EA Pls

[Deleted]  

Someone pls help add code for Take Profit, Stop loss and Trailing Stop to this EA.

It should place only one trade in a SAR direction

I got it free and found it seems helpful



//---- input parameters

extern double Lot_Size=0.1;
extern double SAR_Step=0.03;
extern double SAR_Maximum=0.2;

//---global variables
int magic_number=19081846;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int total_trade=OrdersTotal();

if (total_trade<=0)
{
PlaceTrades();
return(0);
}

int my_orders=0;

for (int i=0;i<total_trade;i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderMagicNumber()==magic_number)&&(OrderSymbol()==Symbol()))
{
ManageTrades(OrderTicket(),OrderType(),OrderLots());
my_orders++;
}
}
if (my_orders==0) PlaceTrades();
//----
return(0);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| ManageTrades function |
//+------------------------------------------------------------------+
int ManageTrades(int iticket, int itype, double dlots)
{
//----
RefreshRates();
//parabolic SAR calculations
double sar0=iSAR(Symbol(),0,SAR_Step, SAR_Maximum,0);
double sar1=iSAR(Symbol(),0,SAR_Step, SAR_Maximum,1);

//closing orders
if (iticket>=0)
{
if ((itype==OP_BUY)&&(High[0]<sar0)&&(High[1]<sar1))
OrderClose(iticket, dlots, Bid, 3, Black);
if ((itype==OP_SELL)&&(Low[0]>sar0)&&(Low[1]>sar1))
OrderClose(iticket, dlots, Ask, 3, Black);
}//end of closing orders

return(0);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| PlaceTrades function |
//+------------------------------------------------------------------+
void PlaceTrades()
{
//----
RefreshRates();
//parabolic SAR calculations
double sar0=iSAR(Symbol(),0,SAR_Step, SAR_Maximum,0);
double sar1=iSAR(Symbol(),0,SAR_Step, SAR_Maximum,1);
double sar2=iSAR(Symbol(),0,SAR_Step, SAR_Maximum,2);

//trade direction
int trade_direction=0;

if ((High[2]<sar2)&&(Low[1]>sar1)&&(Low[0]>sar0)) trade_direction=1; //condition for long/buy trades
if ((Low[2]>sar2)&&(High[1]<sar1)&&(High[0]<sar0)) trade_direction=-1; //condition for short/sell trades

//place long trade
if (trade_direction==1)
OrderSend(Symbol(),OP_BUY, Lot_Size, Ask, 3, 0, 0, "SAR Long Orders", magic_number, 0, Green);

//place short trade
if (trade_direction==-1)
OrderSend(Symbol(),OP_SELL, Lot_Size, Bid, 3, 0, 0, "SAR Short Orders", magic_number, 0, Red);


return;
}
//+------------------------------------------------------------------+

Files:
ksacpsar.mq4  5 kb
 
bayofx:

Someone pls help add code for Take Profit, Stop loss and Trailing Stop to this EA.


TP & SL based on what method of calculation ? what I mean is what SL and TP do you want to set ?

You need this . . . https://docs.mql4.com/trading/OrderModify