kiki65:
while (ticket>0)
Trailing ();
I cannot have the trailing stop triggered. I don't know why.
int start (){
while (ticket>0)
Trailing ();
- 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,
- 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:
- 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,
- 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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.