Trailing Stop Issue

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Trailing Stop Issue

Postby wik_kis » Wed Aug 07, 2019 3:23 am

Hello,
Im trying to make an automated trailing stop, here is what I have so far:
Code: Select all
if(OrdersTotal() == 1){
      if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES) == true) {
         if(OrderType()==OP_BUY)
            {
              if (Bid > OrderOpenPrice()) {
                  double NewLongSL = Bid - Trailing_Stop*Point;
                  if (NewLongSL > OrderStopLoss()) {
                     OrderModify(OrderTicket(),OrderOpenPrice(), NewLongSL,0,0,Blue);
                  }else {
                     Print("nope" + Bid);
                  }
              }     
            }
          if(OrderType()==OP_SELL)
            {
              if (Ask < OrderOpenPrice()) {
                  double NewShortSL = Ask + Trailing_Stop*Point;
                  if (NewShortSL < OrderStopLoss()) {
                     OrderModify(OrderTicket(),OrderOpenPrice(), NewShortSL,0,0,Blue);
                  }else {
                     Print("nope" + Ask);
                  }
              }     
            }
     
      }
   }


it is compiling all right and I can run it in a strategy tester.
The issue is that it behaves strange, when a long or short is opened this function is adjusting SL by moving to up or down by 1, even when the price is not changing. This is what it looks like:
Image

I have no idea what is going on here, so any help would be appreciated.
Thanks in advance guys! :D
wik_kis
 
Posts: 1
Joined: Wed Aug 07, 2019 3:11 am

Re: Trailing Stop Issue

Postby Victor.Tereschenko » Thu Aug 08, 2019 2:24 am

Use NormalizeDouble(Bid - Trailing_Stop*Point, _Digits);
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 144
Joined: Fri Nov 19, 2010 8:55 am


Return to Indicator and Signal Requests

Who is online

Users browsing this forum: No registered users and 34 guests