Calculating TrailingStop With Spread

 

Hi All,

I have a Trailing Stop function which trail negative instead of positive, i don't think it is trailing right, what am i doing wrong?

Thanks...

ld_76 = stoplevel * 1.0 * Point + Spread * 0.0 * Point + Trailing * Point;
//MarketInfo(Symbol(),MODE_STOPLEVEL) * 1.0 * Point + Ask-Bid * 0.0 * Point + TrailingStop(10) * Point
if (OrderType() == OP_BUY) {
                  //profit = NormalizeDouble((Bid - openpryce) / Point, 0);
                  //if(profit < Trailing) continue;
                  //modif = false;
                  ld_60 = NormalizeInt(MathMin(Bid - ld_76, Bid - stopslevel * pints));
                  if (ld_60 > trailsl || trailsl == 0.0) modif = TRUE;
               } else {
                  if (OrderType() == OP_SELL) {
                     //profit = NormalizeDouble((openpryce - Ask) / Point, 0);
                     //if(profit < Trailing) continue;
                     //modif = false;
                     ld_60 = NormalizeInt(MathMax(Ask + ld_76, Ask + stopslevel * pints));
                     if (ld_60 < trailsl || trailsl == 0.0) modif = TRUE;
                  }
               }
               if (modif) {
                      OrderModify(Trailtick, OrderOpenPrice(), ld_60, ld_44, 0);
                     }

 What am i doing wrong?

Should i include Openprice to somewhere in the code? 

 
  1. Variables like ld_60 tell me you are using decompiled code.

    Ask the owner of the indicator to give source code to you.

    Decompiled code is stolen code. Either you are a thief, a fence, or the receiver of stolen (intellectual) property. Either way we will not be an accomplice after the fact to theft. See also https://www.mql5.com/en/forum/134317

    Don't tell us you found it on the 'net: if someone stole your bank details and uploaded them on to the internet, is it OK for everyone to use them because "someone uploaded it, I don't know why I can't use that"?

  2. Check your return codes. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. ld_76 = stoplevel * 1.0 * Point + Spread * 0.0 * Point + Trailing * Point;
    Zero times anything is zero.
  4. Don't double post
Reason: