Code to send email alerts when closed trades... - page 2

 

...

SendMail() call in your code looks OK except you should replace Down with "down" and Up with "up" - SendMail() expects the second argument to be a string)

Did you set up the email in the options too? If no, here is a thread that explains how you have to set up the email for SendMail() function : https://www.mql5.com/en/forum/173821

star821:
Hi

I try to change indictor"DDFX 2 Neuro Trade v3_MTF_alert" to email alert. but does not work.

Please help to verify what I wrote wrong.

Thank you very much!

Original sentence:

if(TrendUp[1] > TrendDown[1] && TrendUp != EMPTY_VALUE && SoundAlert == true && Bars>alertBar) {Alert("MTF_DDFX going Down on the " + Period() + " " + Symbol() + " minute chart");alertBar = Bars;} if(TrendUp[1] alertBar) {Alert("MTF_DDFX going Up on the " + Period() + " " + Symbol() + " minute chart");alertBar = Bars;}

I just change to

if(TrendUp[1] > TrendDown[1] && TrendUp != EMPTY_VALUE && SoundAlert == true && Bars>alertBar) {SendMail(StringConcatenate(Symbol(),"Down "),Down);alertBar = Bars;} if(TrendUp[1] alertBar) {SendMail(StringConcatenate(Symbol(),"Up "),Up);alertBar = Bars;}

Original indictor

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

//| MTF_DXFO.mq4 |

//|------------------------------------------------------------------+

#property indicator_chart_window

#property indicator_buffers 6

#property indicator_color1 CLR_NONE

#property indicator_color2 CLR_NONE

#property indicator_color3 DarkSlateBlue

#property indicator_color4 FireBrick

#property indicator_color5 NavajoWhite

#property indicator_color6 Orange

#property indicator_width3 1

#property indicator_width4 1

#property indicator_width5 4

#property indicator_width6 4

//---- input parameters

/*************************************************************************

PERIOD_M1 1

PERIOD_M5 5

PERIOD_M15 15

PERIOD_M30 30

PERIOD_H1 60

PERIOD_H4 240

PERIOD_D1 1440

PERIOD_W1 10080

PERIOD_MN1 43200

You must use the numeric value of the timeframe that you want to use

when you set the TimeFrame' value with the indicator inputs.

---------------------------------------*/

extern int TimeFrame = 0;

//---- indicator buffers

double Up[];

double Down[];

double CrossUp[];

double CrossDown[];

double TrendUp[];

double TrendDown[];

double alertBar;

extern bool SoundAlert = true;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicator line

SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_DOT);

SetIndexBuffer(0, Up);

SetIndexStyle(1, DRAW_NONE, STYLE_DOT);

SetIndexBuffer(1, Down);

SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_DOT);

SetIndexBuffer(2, CrossUp);

SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_DOT);

SetIndexBuffer(3, CrossDown);

SetIndexBuffer(4, TrendUp);

SetIndexStyle(4, DRAW_ARROW);

SetIndexArrow(4, 221);

SetIndexBuffer(5, TrendDown);

SetIndexStyle(5, DRAW_ARROW);

SetIndexArrow(5, 222);

//---- name for DataWindow and indicator subwindow label

switch(TimeFrame)

{

case 1 : string TimeFrameStr="Period_M1"; break;

case 5 : TimeFrameStr="Period_M5"; break;

case 15 : TimeFrameStr="Period_M15"; break;

case 30 : TimeFrameStr="Period_M30"; break;

case 60 : TimeFrameStr="Period_H1"; break;

case 240 : TimeFrameStr="Period_H4"; break;

case 1440 : TimeFrameStr="Period_D1"; break;

case 10080 : TimeFrameStr="Period_W1"; break;

case 43200 : TimeFrameStr="Period_MN1"; break;

default : TimeFrameStr="Current Timeframe";

}

IndicatorShortName("MTF_DFXO("+TimeFrameStr+")");

}

//----

return(0);

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

//| |

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

int start()

{

datetime TimeArray[];

int i,limit,y=0,counted_bars=IndicatorCounted();

// Plot defined time frame on to current time frame

ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);

limit= Bars-1;

for(i=0,y=0;i<limit;i++)

{

if (Time<TimeArray[y]) y++;

/***********************************************************

Add your main indicator loop below. You can reference an existing

indicator with its iName or iCustom.

Rule 1: Add extern inputs above for all neccesary values

Rule 2: Use 'TimeFrame' for the indicator time frame

Rule 3: Use 'y' for your indicator's shift value

**********************************************************/

Up=iCustom(Symbol(),TimeFrame,"DDFX 2 Neuro Trade v3",0,y);

Down=iCustom(Symbol(),TimeFrame,"DDFX 2 Neuro Trade v3",1,y);

CrossUp=iCustom(Symbol(),TimeFrame,"DDFX 2 Neuro Trade v3",0,y);

CrossDown=iCustom(Symbol(),TimeFrame,"DDFX 2 Neuro Trade v3",1,y);

if (Time==TimeArray[y]) TrendUp=iCustom(Symbol(),TimeFrame,"DDFX 2 Neuro Trade v3",4,y);

if (Time==TimeArray[y]) TrendDown=iCustom(Symbol(),TimeFrame,"DDFX 2 Neuro Trade v3",5,y);

if(TrendUp[1] > TrendDown[1] && TrendUp != EMPTY_VALUE && SoundAlert == true && Bars>alertBar) {Alert("MTF_DDFX going Down on the " + Period() + " " + Symbol() + " minute chart");alertBar = Bars;}

if(TrendUp[1] alertBar) {Alert("MTF_DDFX going Up on the " + Period() + " " + Symbol() + " minute chart");alertBar = Bars;}

}

return(0);

}

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

Need help

Thank you mladen.

But indicator still can't send email. my email setting is ok(i use other indicator send email alert can be received).

 

...

Try the simplest approach : make as simple an indicator as it can be and see if it is going to send an email.

Something like this (this one should send an email on every new bar):

#property indicator_chart_window

int init() { return(0); }

int deinit() { return(0); }

int start()

{

static int bars = 0;

if (bars!=Bars)

{

bars=Bars;

SendMail("testing the mail","test mail text");

}

return(0);

}

If it sends it then you can continue on your code (and conditions for sending email). If not, then you have to review the email settings

star821:
Thank you mladen. But indicator still can't send email. my email setting is ok(i use other indicator send email alert can be received).
 

Fixed

Hi mladen

Thank you for your advice.

Simplest approach is king, I fixed.

mladen:
Try the simplest approach : make as simple an indicator as it can be and see if it is going to send an email.

Something like this (this one should send an email on every new bar):

#property indicator_chart_window

int init() { return(0); }

int deinit() { return(0); }

int start()

{

static int bars = 0;

if (bars!=Bars)

{

bars=Bars;

SendMail("testing the mail","test mail text");

}

return(0);

}

If it sends it then you can continue on your code (and conditions for sending email). If not, then you have to review the email settings
 

...

When in doubt, always simplify the code Keep up the good work ...

star821:
Hi mladen

Thank you for your advice.

Simplest approach is king, I fixed.
 
dimmyr:
Just made final modifications to it.

It alerts upon the close of a trade on a pair to which the EA was attached. I use a commercial EA, and I open up an extra chart to which I attach the alerter.

I would love to have it augmented to alert on trade openings as well, but I am not that smart yet. If anyone can contribute to this code, that would be great!

This is what the email looks like:

Subject: CLOSE pr: 23.59, bal: 5152.57, eq: 5058.81

Symbol:

Comment:

Ticket#:

Size:

OpenTime:

Close Time:

Open:

Close:

Profit:

Pips:

Balance:

Used Margin:

Free Margin:

Equity:

Open Orders:

Broker:

Leverage:

can i modify your MailAlertOnOrderClose.zip that i have to put the ea only in one chart and it works for all pairs or its not possible?

now i have to put it in each chart.

thanks

Reason: