StopLoss at High or Low Previous Candle

 

candle bear


i want place SL at high or low candlestick, using code below.. but the SL always move after new candle was close. 

How to make it fix and not move again ? Thanks for  help


if (SLPip>0)
 {
 double highcandle   = iHigh(Symbol(),PERIOD_H1,1); 
 double lowcandle    = iLow(Symbol(),PERIOD_H1,1); 
 
 //double sls =0; double slb=0;
 double SLbuy  =  NP(OrderOpenPrice()-  (lowcandle -  SLPip*ptt));
 double SLsell =  NP (OrderOpenPrice()+ (highcandle + SLPip*ptt)); 
 
 
  int total  = OrdersTotal();  
  for (int fnt = total ; fnt >= 0 ; fnt--)
  {
    if (OrderSelect(fnt,SELECT_BY_POS,MODE_TRADES))
    {
    if (OrderSymbol()==Symbol()&& OrderType()==OP_BUY && OrderMagicNumber()==Magic && jenis==0)// &&  ( StringFind(OrderComment(),"Mar",0)>=0 || OrderOpenPrice() >= buyacuan))
    {        
            
      if (OrderStopLoss() != SLbuy )
      {
      tkt =OrderModify(OrderTicket(),OrderOpenPrice(),SLbuy,OrderTakeProfit() ,0,Blue);
      }
    } 
    
    if (  OrderSymbol()==Symbol()&& OrderType()==OP_SELL && OrderMagicNumber()==Magic && jenis==1)// &&  ( StringFind(OrderComment(),"Mar",0)>=0 || OrderOpenPrice() <= sellacuan))
    {          
            
      if (OrderStopLoss() != NP(OrderOpenPrice() +SLPip*ptt))
      {
      tkt =OrderModify(OrderTicket(),OrderOpenPrice(),SLsell,OrderTakeProfit() ,0,Red);
      }
    }       

  }}

 }
 
Abd Rahman Alamsyah: How to make it fix and not move again ? Thanks for  help

Select the order. If it already has a stop loss, don't modify it.

 
Md Amzad Hossain #:

Do not double post!

I have deleted your duplicate topic that was in the wrong section. All questions regarding MQL4 should be placed in the MQL4 section.

 
Keith Watford #:

Do not double post!

I have deleted your duplicate topic that was in the wrong section. All questions regarding MQL4 should be placed in the MQL4 section.

sorry for that, please give me solution this problem. please this issue...

 
Md Amzad Hossain #: please give me solution this problem. please this issue...

You were given the answer in #1

 
William Roeder #:

You were given the answer in #1

i'm new in programming can you add this code  Select the order. If it already has a stop loss, don't modify it.? Please

 
Md Amzad Hossain #:i'm new in programming can you add this code  Select the order. If it already has a stop loss, don't modify it.? Please

The forum is for proving guidance to those that wish to learn, not for coding things for them.

If you are not willing to put in the effort to learn to code it yourself, then please use the Freelance section to place a job request and hire someone to do it for you.