Tralling Stop

Back to topics list To post a new topic, please log in or register
avatar
41
KeepMarcos 2016.03.13 23:53
 

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. 

 

avatar
Moderator
3404
GumRai 2016.03.14 01:13 #
 

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()


avatar
41
KeepMarcos 2016.03.14 02:06 #
 

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);

 

avatar
Moderator
3404
GumRai 2016.03.14 02:53 #
 

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)
avatar
41
KeepMarcos 2016.03.15 00:29 #
 

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. 

Back to topics list  

To add comments, please log in or register