trailing stop not working

 

can some help me with this trialling stop

it does not trail

void start()

{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol

Print(TrailingStop);
int cnt, ticket, total;

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == MAGICMA)

if(OrderType()==OP_BUY) // long position is opened
{
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}

}

 
Replace
int cnt, ticket, total;

for(cnt=0;cnt<total;cnt++)
 <total =";CNT++) PRE
to
int cnt, ticket, total;
total=OrdersTotal();
for(cnt=0;cnt<total;cnt++)
 
 
 
Roger:
Replace

thanks i have tried it work well

can you just show me why it dont send email notification


res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"My order comment",MAGICMA,0,Blue);

// send buy email
//if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
if (EmailON) SendMail(AccountNumber()+" BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());

return;


email on is true

extern bool EmailON =true;
 
Did you try to push the button "Test" after adjusting Send email on your terminal? What did you see in journal logs?
P.S. SendMail doesn't work in the tester mode.
 
Roger:
Did you try to push the button "Test" after adjusting Send email on your terminal? What did you see in journal logs?
P.S. SendMail doesn't work in the tester mode.

it said message queued

and in the journal it say mail: test message has been sent

 
bewise:

it said message queued

and in the journal it say mail: test message has been sent

thanks it is working now

 
bewise:

thanks it is working now




hi

it is sending me the emails but it does not send the AccountNumber()

Reason: