Trailling StopLoss

 
Hello,

I would like to have a line of code to have a Trailling Stoploss on my robot.

Explanation:


I open my position at 0 My StopLoss is -40 and my TakeProfit is 100 .. If my position is 60 then I would like my StopLoss to be 40 (- 20 Pips) And if my price increases by 20 Pips then my StopLoss will increase by 10 Pips.


Thanks you of France ! :)

Thomas

 
ThomasBrd51: I would like to have a line of code
  1. Not going to be “a line of code.”
  2. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help 2017.04.21

 

William Roeder:

  1. Not going to be “a line of code.”
  2. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).

    extern int TakeProfit = 80;
    extern int StopLoss = 45;
    extern double LotSize = 0.01;
    extern int MMI = 55;
    extern int MMS = 290;
    extern int MagicNumber = 1234;
    double Pips ;
    
    
    int OnInit()
      {
    //---
    double TickSize = MarketInfo (Symbol (),MODE_TICKSIZE);
    if (TickSize == 0.00001 || TickSize == 0.001);
    else Pips = TickSize ;
    Pips = TickSize * 10 ;
       dt = Time[0];
    //---
       return(INIT_SUCCEEDED);
      }
    //+------------------------------------------------------------------+
    //| Expert deinitialization function                                 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
      {
    //---
       
      }
    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+--------------
          double prev_ma10 = iMA(NULL,0, MMS, 0, MODE_EMA, PRICE_CLOSE, 2);
          double prev_ma5 = iMA(NULL,0, MMI, 0, MODE_EMA, PRICE_CLOSE, 2);
          double ma10 = iMA(NULL,0, MMS, 0, MODE_EMA, PRICE_CLOSE, 1);
          double ma5 = iMA(NULL,0, MMI, 0, MODE_EMA, PRICE_CLOSE, 1);
          
    
    
          
          if(prev_ma10>prev_ma5 && ma10<ma5){
             if(OrdersTotal() !=0) closeexisting();
             
             OrderSend(Symbol (),OP_BUY,LotSize,Ask,3,Ask - (StopLoss * Pips), Ask + (TakeProfit * Pips),NULL,MagicNumber,0,Green);
          }
          else if( prev_ma10 < prev_ma5 && ma10>ma5){
            if(OrdersTotal() !=0) closeexisting();
            
            OrderSend(Symbol (),OP_SELL,LotSize,Bid,3,Bid + (StopLoss * Pips), Bid - (TakeProfit * Pips),NULL,MagicNumber,0,Red);
          }
          
       }----------------------------------------------------+
    void OnTick()
      {
    //--- 200 euros avec levier 30 (6k) soit 0.06 lot
       if(isnewbar()){
      }
    void closeexisting() {
     OrderSelect(0,SELECT_BY_POS);
     OrderClose(OrderTicket(), OrderLots(), MarketInfo(_Symbol, MODE_BID+OrderType()), 10);
     
     
     
    }
      
    bool isnewbar(){
       if(Time[0] !=dt){
         dt = Time[0];
         return true;
       }
       return false;
       
       
       
    }
    //+------------------------------------------------------------------+

    Hello, here is my code


    So I would like to be able to add a follower StopLoss program in this .. (I'm new to MQL4 programming so I don't know where to start ..)


    I should be able to choose as an external variable the number of pips from the moment my StopLoss is triggered as well as the number of pips where it will place .. And the number of pips it uses from the moment or the previous condition will be fulfilled.


    Explanation:


    I open my position at 0 pips


    1. My initial StopLoss is -45 Pips
    2. My TakeProfit is 80 pips
    3. If the position goes from 0 to 40 pips then my StopLoss is placed at 20 pips
    4. Then from that moment if the position takes 10 pips then the Stoploss takes +5 pips until the position closes.

    Constraint:

    Step 3 and 4 should be modifiable (extern int)


    I am ready to listen to your proposals regarding your prices


    Thank you..


    Thomas

     
    Topics concerning MT4 and MQL4 have their own section.
    In future please post in the correct section.
    I will move your topic to the MQL4 and Metatrader 4 section.
     
    ThomasBrd51: Hello, here is my code

    Do not post that will not even compile.