Experts: Auto Stop And TakeProfit

 

Auto Stop And TakeProfit:

This is a simple EA that automatically places Stops and TakeProfit on opened orders .

Author: Catalin Zachiu 

Auto Stop And TakeProfit
Auto Stop And TakeProfit
  • www.mql5.com
Cycle Lines With "Cycle Lines" EA you can draw Cycle Lines on the chart and trade with price breakthrough,has 3 buttons for manual trading and allows to predetermine trailing stoploss & take profit, open and close all trades at once. Pan PrizMA Sin leverage 72...
 

Can I add it to one chart and apply for all pairs I open it

can you add Trailing Stop to it 

 
Hussein Kadhim:

Can I add it to one chart and apply for all pairs I open it

can you add Trailing Stop to it 

The Symbol selection must be canceled and trailstop may be added , I may be able to do it tomorrow .
 
Hussein Kadhim:

Can I add it to one chart and apply for all pairs I open it

can you add Trailing Stop to it 

for work on all symbol just remove highlighted code

//+------------------------------------------------------------------+
//|                                         Auto Stop&TakeProfit.mq4 |
//|                                   Copyright 2019, Catalin Zachiu |
//|                      https://www.mql5.com/en/users/catalinzachiu |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Catalin Zachiu"
#property link      "https://www.mql5.com/en/users/catalinzachiu"
#property version   "1.00"
#property strict

input double StopLoss =500;
input double TakeProfit =500;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   for(int j=0;j<OrdersTotal();j++)
     {
      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()!=Symbol() || OrderCloseTime()!=0) continue;
        
        {
         //--- long position is opened
        
            if(OrderType()==OP_BUY && OrderStopLoss()==0)
            //--- check for trailing stop
           { if(OrderStopLoss()==OrderOpenPrice()-StopLoss*Point) break;
              else
            
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point,OrderTakeProfit(),0,Green))
                        Print("OrderModify error ",GetLastError());
                    // return;
                    }
            }    
            
             if(OrderType()==OP_BUY && OrderTakeProfit()==0)
            //--- check for trailing stop
           { if(OrderTakeProfit()==OrderOpenPrice()+TakeProfit*Point) break;
              else
            
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+TakeProfit*Point,0,Green))
                        Print("OrderModify error ",GetLastError());
                    // return;
                    }
            }    
              
              
      
         if(OrderType()==OP_SELL && OrderStopLoss()==0)  
            //--- check for trailing stop
          {  if(OrderStopLoss()==OrderOpenPrice()+StopLoss*Point) break;
            else
            
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point,OrderTakeProfit(),0,Red))
                        Print("OrderModify error ",GetLastError());
                     //return;
                    }
           }        
          
            if(OrderType()==OP_SELL && OrderTakeProfit()==0)  
            //--- check for trailing stop
          {  if(OrderTakeProfit()==OrderOpenPrice()-TakeProfit*Point) break;
            else
            
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-TakeProfit*Point,0,Red))
                        Print("OrderModify error ",GetLastError());
                    // return;
                    }
           }      
                    
        }
        
     }
     Sleep(1000);
  }

//+------------------------------------------------------------------+
 
Koros Jafarzadeh:

for work on all symbol just remove highlighted code

thanks a lot for this help

I will try it and update it

 
Catalin Zachiu:
The Symbol selection must be canceled and trailstop may be added , I may be able to do it tomorrow .

thanks a lot waiting you

can you add magic number to orders

 
Koros Jafarzadeh:

for work on all symbol just remove highlighted code

does it virtual Stop lose and take profit

cause when I add it to chart I can't see take profit change 

 
Catalin Zachiu:
The Symbol selection must be canceled and trailstop may be added , I may be able to do it tomorrow .

I still waiting you my friend 

 
Hussein Kadhim:

does it virtual Stop lose and take profit

cause when I add it to chart I can't see take profit change 

it's not virtual, this expert works if positions SL & TP not placed on server, it means SL & TP equal to 0

 
Thank you so much for this code. From the depth of my heart i appreciate.
Reason: