Tralling Stop

 

heeey gus!!!

It is a pleasure to be in this forum. The forum helps me a lot in my studies. =) Thankss!!!
People,I can not place stop when the price reach a value.

Example:

price is 1.50
Stop in 01.30 

 if(Ask+50*MyPoint>OrderOpenPrice()) modify = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+30*MyPoint,0,0,clrLightGreen);

 

 is Result the code:

Price is 1.30
Stop in 1.30.

it's wrong. why it does not work?
Thank you very much for your help. =) 

 

*Sorry for any English error. 

 

price is 1.50

Stop in 01.30

suggests that this is a buy order so

if(Ask+50*MyPoint>OrderOpenPrice())

doesn't make sense, maybe you mean

if(Ask-50*MyPoint>=OrderOpenPrice())

?

You should check if the price has already been modified

you should check if the modify fails and print GetLastError()

 

GumRai. Thank you very much!!!! =)

 exactly!

CODE; 

double stnewprice = OrderOpenPrice();
double st = OrderStopLoss();
if(st<=0 && Ask-20*MyPoint>stnewprice) modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewprice+10*MyPoint,0,0,clrLightGreen);
 

I don't know that there are any advantages of using different variables instead of OrderOpenPrice() etc. Personally, I would  not

 if(OrderStopLoss()<OrderOpenPrice() && Bid-20*MyPoint>OrderOpenPrice())
   if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+10*MyPoint,0,0,clrLightGreen))
     Print("Error modifying ",OrderTicket()," Error code ",GetLastError());

note that as this is a buy order, I have used Bid instead of Ask

Indidentally, the code is not a trailing stop as it will only modify the stoploss once

For a sell, the if condition will need to be slightly different if the stoploss is zero.

 if((OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0) && OrderOpenPrice()-Ask>20*MyPoint)
 

Gumrai. Sorry for the delay!

 

CODE ATT:

double stnewpricebuy = OrderOpenPrice();
                  double stbuy = OrderStopLoss();
                  
                  if(stbuy<=0 && Ask-20*MyPoint>stnewpricebuy)
                  {
                        modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewpricebuy+10*MyPoint,0,0,clrLightGreen);
                  } 
                     
                        else if(stbuy>0 && Ask-20*MyPoint>stbuy)
                        {
                              modify = OrderModify(OrderTicket(),OrderOpenPrice(),stbuy+10*MyPoint,0,0,clrLightGreen);
                        }   

 

 

===]]]]]]]]]]

Thanks. 

Reason: