# Tralling Stop

120

Hello!!!

I have a problem in the code. I tried everything, but nothing

thanks for help.

```
//=========================POINT
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;   ```
```for (int trade3=OrdersTotal()-1; trade3>=0; trade3--)
{
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==MagicNumber) )
{
{

if(modify<=0) error = GetLastError();
Comment(error);

}//FIM MAGIC
}//FIM SELECT
Moderator
15462

```if(OrderStopLoss()==0 && Ask-10*MyPoint>OrderOpenPrice())
modify= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+10*MyPoint,0,0,clrLightGreen);```

when

` Ask-10*MyPoint>OrderOpenPrice()`

is first true you are trying to modify the SL to what is the current Ask

This will not only likely fail because it is too close to the current price, it will be higher than the current bid and a Buy closes at bid.

120

GumRai:

when

is first true you are trying to modify the SL to what is the current Ask

This will not only likely fail because it is too close to the current price, it will be higher than the current bid and a Buy closes at bid.

GumRai thanks for anwser.

```if(OrderStopLoss()==0 && Ask-10*MyPoint>OrderOpenPrice())
modify= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+7*MyPoint,0,0,clrLightGreen);```

correct ?

Moderator
15462

First you need to decide what you are trying to do.

This is not code for a trailing stop it is more like a move to break-even

As it is a buy, use Bid, not Ask, better to use OrderClosePrice() which is the last price at the time of the OrderSelect

So this is your code set to break-even. You will need to re-think for a trailing stop.

```if(OrderStopLoss()==0 && OrderClosePrice()-10*MyPoint>OrderOpenPrice())
modify= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0,clrLightGreen);```
120

GumRai:

First you need to decide what you are trying to do.

This is not code for a trailing stop it is more like a move to break-even

As it is a buy, use Bid, not Ask, better to use OrderClosePrice() which is the last price at the time of the OrderSelect

So this is your code set to break-even. You will need to re-think for a trailing stop.

I believe that everything is OK.

``` if(OrderStopLoss()==0 && OrderClosePrice()-10*MyPoint>stnewpricebuy) modify = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+5*MyPoint,0,0,clrLightGreen);

if(SL>0 && (OrderStopLoss()>OrderStopLoss()+5*MyPoint))   modify = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+2*MyPoint,0,0,clrLightGreen);```

once again thank you for your help.

before sending my question looked at many forums. however you helped me. as always helps.

thank very much :)

120

correction code:

```if(SL==0 && OrderClosePrice()-10*MyPoint>stnewpricebuy) modify = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+5*MyPoint,0,0,clrLightGreen);

if(SL>0 && (Bid>OrderStopLoss()+10*MyPoint))   modify = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+5*MyPoint,0,0,clrLightGreen);```