Download MetaTrader 5

Stop loss modify not working for sells

To add comments, please log in or register
xanderhinds
100
xanderhinds  

Hi, I've been woring on an ea with a SL function that is set after a period of time has elapsed AND an amount of pips profit it cleared.. it works for OrderModify OP=BUY but not for OP=SELL, I think I'm just missing something simple but cant seem to grasp what it is.. anyhow, here's the code;

 

else if((Bid - OrderOpenPrice())> (BESLPROFIT*Point) && (TimeCurrent()- OrderOpenTime()) > SLDuration)
                  {  
                   if (OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+(BESL*Point)),OrderTakeProfit(),0,Green)== true)
                     {
                     OMNB5--;
                     continue;
                     }
                   else
                     {
                     Alert ("Problem whilst moving SL to BE");
                     return(0);
                     }
                  }  
                 else
                {
                 Alert ("Insufficent time elapsed to move SL B5");
                 continue;
               }


// above is the order modify for BUY

// below is for SELL 




if ((Ask - OrderOpenPrice())> (BESLPROFIT*Point) && (TimeCurrent()- OrderOpenTime()) > SLDuration)
                 {
                   if (OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()-(BESL*Point)),OrderTakeProfit(),0,Blue)== true)
                    {
                     OMNS5--;
                     continue;
                    }
                   else
                    {
                     Alert ("Problem whilst moving SL to BE");
                     return(0);
                    }
                 }  
                 else
                  {
                   Alert ("Insufficent time elapsed to move SL");
                   continue;
                  }

whroeder1
16086
whroeder1  
xanderhinds: . it works for OrderModify OP=BUY but not for OP=SELL, I think I'm just missing something simple but cant seem to grasp what it is..

 

if ((Ask - OrderOpenPrice())> (BESLPROFIT*Point) && (TimeCurrent()- OrderOpenTime()) > SLDuration)
If your sell order is in profit, the Ask will be below the OOP.
xanderhinds
100
xanderhinds  
whroeder1:
If your sell order is in profit, the Ask will be below the OOP.

Thanks Whroeder1, you're a legend. 

To add comments, please log in or register