Download MetaTrader 5
To add comments, please log in or register
Post web links to paid signals. Receive the partner's share!
Leon Scheffel
131
Leon Scheffel 2015.02.17 20:12 

Hi Guys,


I have a Expert Advisor with Sendmail function and it's working correctly when I open a new trade.

the problem is: when my Stop Loss or Take Profit is reached, I do not get a Sendmail notification.

Is there anybody who can help me with this problem?


I search all of the internet, but could not find a good solution.


Kind Regards

Alain Verleyen
Moderator
28535
Alain Verleyen 2015.02.17 21:22  
leonscheffel:

Hi Guys,


I have a Expert Advisor with Sendmail function and it's working correctly when I open a new trade.

the problem is: when my Stop Loss or Take Profit is reached, I do not get a Sendmail notification.

Is there anybody who can help me with this problem?


I search all of the internet, but could not find a good solution.


Kind Regards

What is the code returned by Sendmail ?

Your MT4 platform email settings are correctly configured ?

Keith Watford
Moderator
7887
Keith Watford 2015.02.17 21:36  

Does the EA include code to send an alert when TP or SL is hit?

Show the relevant code and somebody may be able to assist 

Leon Scheffel
131
Leon Scheffel 2015.02.23 13:46  

Thanks for the answers!


Here is my complete script:


extern int MagicNumber=10001;
extern double Lots =1.0;
extern double StopLoss=80;
extern double TakeProfit=125;
extern int TrailingStop=0;
extern int Slippage=3;
bool allowbuy = true;
bool allowsell = true;


  
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+

int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;
     if (allowbuy==true)
     {
     if((iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,1)>iMA(NULL,0,58,0,MODE_EMA,PRICE_CLOSE,1))) // Here is your open buy rule
     {
           result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
           if(result>0)
           {
            TheStopLoss=0;
            TheTakeProfit=0;
            if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
            if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
            OrderSelect(result,SELECT_BY_TICKET);
            OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
           string Text   = "buy, 1, Beurs Adviezen Test, 1";
            SendMail("Nieuwe Positie", Text + " " );
            allowbuy = false;
            allowsell = true;
           }
           return(0);
        }
     }
     if(allowsell ==true)
     {
        if((iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,1)<iMA(NULL,0,58,0,MODE_EMA,PRICE_CLOSE,1))) // Here is your open Sell rule
        {
           result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
           if(result>0)
           {
            TheStopLoss=0;
            TheTakeProfit=0;
            if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
            if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
            OrderSelect(result,SELECT_BY_TICKET);
            OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
            string Greeting   = "sell, 1, Beurs Adviezen Test, -1";
           SendMail("Nieuwe Positie", Greeting + " " );
            allowbuy = true;
            allowsell = false;
           }
           return(0);
        }
        }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
              if((iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,1)<iMA(NULL,0,58,0,MODE_EMA,PRICE_CLOSE,1))) //here is your close buy rule
              {
                   allowbuy = false;
                   allowsell = true;
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
                    string Text3   = "buy, 1, Beurs Adviezen Test, 0";
                   SendMail("Sluiten Positie", Text3 + " " );
              }
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     SendMail("Gesloten Order "+Symbol(),Symbol()+" Gesloten op "+ OrderClosePrice());
                     return(0);
                    }
                 }
              }
           }
         else 
           {
                if((iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,1)>iMA(NULL,0,58,0,MODE_EMA,PRICE_CLOSE,1))) // here is your close sell rule
                {
                   allowbuy = true;
                   allowsell = false;
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
                   
                }
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                     string Greeting2   = "sell, 1, Beurs Adviezen Test, 0";
                   SendMail("Sluiten Positie", Greeting2 + " " );
                    }
                 }
              }
           }
        }
     }
   return(0);
}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
   
   
      
   
  return (result);
}



Leon Scheffel
131
Leon Scheffel 2015.02.23 13:47  
GumRai:

Does the EA include code to send an alert when TP or SL is hit?

Show the relevant code and somebody may be able to assist 

I think I am missing that code for TP and SL. I only get a message when a new trade is open!
whroeder1
13600
whroeder1 2015.02.23 14:03  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes (OrderSelect, OrderModify, and OrderClose) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You have no code so you get no message.
Leon Scheffel
131
Leon Scheffel 2015.02.25 06:52  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes (OrderSelect, OrderModify, and OrderClose) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You have no code so you get no message.

I edit it!
Leon Scheffel
131
Leon Scheffel 2015.03.02 13:51  
Anybody a solution for my problem?
whroeder1
13600
whroeder1 2015.03.02 14:20  
leonscheffel: Anybody a solution for my problem?
  1. What problem?
  2. You have no code to send a message when orders close, so you get no message. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
Alain Verleyen
Moderator
28535
Alain Verleyen 2015.03.02 18:46  
leonscheffel:
Anybody a solution for my problem?

There is no code to send a mail when a position is closed in what you posted, so of course you can't receive it.

/
To add comments, please log in or register