Replace
int counted_bars = IndicatorCounted();
to
static int counted_bars;
if( counted_bars== IndicatorCounted())return(0);
counted_bars = IndicatorCounted();

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
Hello,
I have tried to create an indicator that sends an e-mail when last complete bar has closed over or aunder the 48 moving average. Although it works, I receive mails at every tick. How do we design the code so that you get an e-mail only on the first tick of the new bar that has satisfied the above condition. In addition to this, if I get an e-mail of a close above the ma48, I do not want another e-mail until the last complete bar is below the ma48. My code to date is as follows:
Thanks for your help
*****************
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Orange
extern int MA_Type = MODE_SMA;
extern int Period_MA_1 = 12; //p.203
extern int Period_MA_2 = 24;
extern int Period_MA_3 = 48;
double ma12,
ma24,
ma48;
double Bull[];
double Bear[];
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 225);
SetIndexBuffer(0, Bull);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 226);
SetIndexBuffer(1, Bear);
return(0);
}
int start()
{
int counted_bars = IndicatorCounted();
int i;
int limit;
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
for(i=0; i<=limit; i++)
{
ma12 = iMA(Symbol(),0,Period_MA_1,0,MA_Type,Close[i+1],i);
ma24 = iMA(Symbol(),0,Period_MA_2,0,MA_Type,Close[i+1],i);
ma48 = iMA(Symbol(),0,Period_MA_3,0,MA_Type,Close[i+1],i);
if ( Close[i+1] > ma48 )
{
Bull[i] = Low[i] - 0.0005;
SendMail("EUR up", "test");
}
if (Close[i+1] < ma48 )
{
Bear[i] = High[i] + 0.0005;
SendMail("EUR down", "test");
}
}
return(0);
}