Modify Stop-loss depending on profit

 

Good day, I want to be safe and make the expert to move the stop loss from negetives [e.g -75 points] to positives [e.g +75 points] as soon as the profit is higher than a certain points [e.g +100 points].

my code is simple at this moment and is incomplete, please dont criticize some functions, would pretty much appreciate is if you helped with the code to modify stop_loss .Thank you


void OnTick() 

  {

   / /Create an Array for several prices

   double mySARArray[];

 

   // define the properties of the SAR

   int SARDefinition = iSAR(NULL,0,0.02,0.20);

   

   // sort the price array from the current candle downwards 

   ArraySetAsSeries(mySARArray, true) ;

   

   // Define EA, current candle, 3 candlea,store results

   CopyBuffer(SARDefinition,0,0,3,mySARArray) ;

   

   // calculate EA for the current  candle

   double SARValue=NormalizeDouble(mySARArray[0],5);

   

   // calculate EA for the previous  candle

   double PrevSARValue=NormalizeDouble(mySARArray[1],5);



MqlTradeRequest request={0};

   MqlTradeResult  result={0};

   

   //--- parameters of request

   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation

   request.magic    =EXPERT_MAGIC1;                          // MagicNumber of the order

   request.symbol   =Symbol();                              // symbol   

   request.volume   =0.10;                                   // volume of 0.1 lot

   request.price    = SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening

   request.tp       = SymbolInfoDouble(Symbol(),SYMBOL_ASK)+0.00100;

   request.sl       =SymbolInfoDouble(Symbol(),SYMBOL_ASK)-0.00070;   

   //request.deviation=0;                                     // allowed deviation from the price

   request.type     =ORDER_TYPE_BUY;                        // order type

if(

     (SARValue>PrevSARValue)

 

     )

     {

    

    Alert("sell");

    Comment("sell");

    OrderSend(request,result); 

}

}
 
8326835:


Do not double post.

I have deleted your duplicate topic.

 
8326835:

Good day, I want to be safe and make the expert to move the stop loss from negetives [e.g -75 points] to positives [e.g +75 points] as soon as the profit is higher than a certain points [e.g +100 points].

   request.tp       = SymbolInfoDouble(Symbol(),SYMBOL_ASK)+0.00100;
   request.sl       =SymbolInfoDouble(Symbol(),SYMBOL_ASK)-0.00070;
  1. Profit will never be higher than 100 points because it will be closed at that point.
  2. You haven't stated a problem, you stated a want. If you have the code, show us your attempt (using the CODE button) and state the nature of your problem.
              No free help
              urgent help.
  3. Using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 programming forum
              Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum