need help with coding Trailing Stop.

 
I cannot have the trailing stop triggered. I don't know why. Here is the code:

extern int ticket;
extern double SL; // -> Stop Loss

void Trailing ()
{
int TrailingStop=MarketInfo(Symbol(),MODE_STOPLEVEL);

if((OrderSelect(ticket,SELECT_BY_TICKET)==true) && (Bid-OrderOpenPrice()>TrailingStop*Point) && (OrderStopLoss()<Bid-TrailingStop*Point))
{
SL=Bid-TrailingStop*Point;
OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Blue);
return(0);

}
}

void Enter_trade()
{
SL=(MarketInfo(Symbol(),MODE_STOPLEVEL))*Point;

ticket=OrderSend(Symbol(),OP_BUY,1,Bid,3,SL,0,"BUY",0,0,Lime);
return(0);
}


int start ()
{
Enter_trade();

while (ticket>0)
Trailing ();

return(0);
}

//NB: I put extern variables to simplify the code for my question, but we can do the same thing with local variables.
 
kiki65:

I cannot have the trailing stop triggered. I don't know why.

int start (){

Enter_trade();

while (ticket>0)
Trailing ();

  1. Because nothing is changing in your while loop. you never sleep, refresh variables, check for the order to close, or check the return codes from orderModify,
  2. Start by studying EA's in the code base that do NOT loop in start, but return after every tick. They use an for loop with orderSelect to determine if there is a open order and if it should be modified.

 
WHRoeder:
  1. Because nothing is changing in your while loop. you never sleep, refresh variables, check for the order to close, or check the return codes from orderModify,
  2. Start by studying EA's in the code base that do NOT loop in start, but return after every tick. They use an for loop with orderSelect to determine if there is a open order and if it should be modified.


Thank you very much for you advice.
Reason: