Add trailing stop in EA

To add comments, please log in or register
jonathan75
39
jonathan75  

Hi everyone, 


I have already been helped by members of mql5, so I try again with an other problem. 

I want to add Trailing stop in my EA but I don't know where I can put the modification without break my code. 

For exemple, this is my part of 'Order Close - Buy' : 


   double SL_Buy = NormalizeDouble(Bid- StopLoss * Point, Digits);
   double TP_Buy = NormalizeDouble(Bid+ TakeProfit * Point, Digits);

------------------------ 
for (i = OrdersTotal(); i >= 0; i--) {
                
// ------------------ Order Buy Close 
// if the candle 0 (Close ) is lower than the candle 2 (Close)
// if the RSI [0] is lower than 48   

if (OrderSelect(OrderTicket(), SELECT_BY_TICKET, MODE_TRADES) == true) 
{
        if (OrdersTotal() >= 1 && OrderType() == OP_BUY && RSI1 <= 45) 
                {
        int OrderBuyClose = OrderClose(OrderTicket(), LotSize, Ask, slipage, Red);
                }
} 

And I want to add this type of trailing stop (activate for breakeven) : 

int trailing_stop = 20;
double ts;

for (int i = OrdersTotal()-1; i >= 0; i --)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
{
if (OrderType() == OP_BUY)
{
ts = Bid-(Point*trailing_stop);
if (OrderStopLoss()=(Point*trailing_stop))
OrderModify(OrderTicket(),OrderOpenPrice(),ts,OrderTakeProfit(),0,White);


If someone can help me :) 

Thanks in advance

To add comments, please log in or register