problem with random stop loss values

 

I have this code before. The StopLoss is set at 30 points at the moment, but when a trade is placed, the stop loss on the trade is anything between 60 and 70 points. Seems very random and I cant work out what is causing this.

Can anyone help me with this please ?

if (SignalBUY=="true")
      {
         if(HideSL == false && StopLoss > 0)
            {SL = Ask-StopLoss*Point ;}
         else 
            {SL = 0;}
         
         if(SL > 0 && SL > (Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point))
            {SL=Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
         
         if(HideTP == false && TakeProfit > 0)
            {TP = Ask+TakeProfit*Point;}
         else 
            {TP = 0;}
         
         Ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,EAName,Magic,0,Blue);
         PlaySound("BEEP_FM.WAV");
         Alert(GetLastError()) ;
                  
         if(Hedge)
         {TicketH=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,TP,SL,EAName,Magic,0,Red);}
         }
         
      if (SignalSELL=="true")
      {
         if(HideSL == false && StopLoss > 0)
            {SL = Bid+StopLoss*Point;}
         else 
            {SL = 0;}
         
         if(SL > 0 && SL < (Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point))
            {SL=Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
         
         if(HideTP == false && TakeProfit>0)
            {TP = Bid-TakeProfit*Point;}
         else 
            {TP = 0;/*TPP=0;*/}
         
         Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,EAName,Magic,0,Red);
         PlaySound("BEEP_FM.WAV");
         Alert(GetLastError()) ;
        
         if(Hedge)
         {TicketH=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,TP,SL,EAName,Magic,0,Blue);}
         
      }
 
Are you factoring in the Spread ?
 
  1. if (SignalBUY=="true")
          {
             if(HideSL == false && StopLoss > 0)
                {SL = Ask-StopLoss*Point ;}

    You Buy at the Ask and Sell at the Bid.

    So for a Buy, SL it is below the Bid (the Sell price)

    if (SignalSELL=="true")
          {
             if(HideSL == false && StopLoss > 0)
                {SL = Bid+StopLoss*Point;}
    So for a Sell, sL is above the Ask (the Buy price)
  2. EA's should adjust for 4/5 digit brokers, TP, SL, AND slippage.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
         */
    

 
WHRoeder:
  1. You Buy at the Ask and Sell at the Bid.

    So for a Buy, SL it is below the Bid (the Sell price)

    So for a Sell, sL is above the Ask (the Buy price)
  2. EA's should adjust for 4/5 digit brokers, TP, SL, AND slippage.

thankyou
Reason: