EMA on EMA on EMA...... - page 2

 
I'm sorry, I wasn't on the right mind when giving you that advice.
Although it still can be done using array of ma (ma[]) but this one is easier.
Your code should be like this

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
 
//---- input parameters
extern int       MA1_Period=5;
extern int       MA2_Period=30;
 
//---- buffers
double ExtMapBuffer1[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int i, maxlimit=Bars-counted_bars;
 
   for(i=0; i<maxlimit; i++) 
    {   
      double ma1=iMA(Symbol(),0,MA1_Period,0,0,PRICE_CLOSE,i); // SMA of MA1_Period on Price_close
      double ma2=iMA(Symbol(),0,MA2_Period,0,0,PRICE_CLOSE,i); // SMA of MA2_Period on Price_close
      ExtMapBuffer1[i]=(ma1-ma2)/Point;   
    }   
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
It's very simple, you can do it by yourself after this.
 
Thanks devilian1899,

It works great, I appreciate your help.

Now I would like to add a sendmail( ) function or trigger an alert when this indicator goes above or below a given value.

I don't know where to place it, or how to write the condition for the value filter

Also how do I add a arrow or mark on the chart when it reaches the given value

Thanks
 
Hey guys, I really need to figure this out, and I need help,
I have managed to add levels, but how to I set an alert or sendmail when the level has been crossed.

thanks

If you feel like hinting me instead of helping, just tell me what functions to use, I know it is supposed to look something like this

if ??????????? > 10 ()sendmail blah blah blah

but where do i put it does it need separate brackets and what am i calling on?



thanks for all
 
if (ExtMapBuffer1[i]>10 && ExtMapBuffer1[i+1]<=10)
 {
   sendmail(...);
 }
put that below
ExtMapBuffer1[i]=....;
I've never code any sendmail feature before, so don't ask me about the rest.
Hope this helps.
 
Thanks devilian1899,

This is what I now have,
#property indicator_level1 10.0
#property indicator_level2 -10.0
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Green
#property indicator_levelcolor Blue
 
//---- input parameters
extern int       MA1_Period=5;
extern int       MA2_Period=30;
 
//---- buffers
double ExtMapBuffer1[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int i, maxlimit=Bars-counted_bars;
 
   for(i=0; i<maxlimit; i++) 
    {   
      double ma1=iMA(Symbol(),0,MA1_Period,0,1,PRICE_CLOSE,i); // SMA of MA1_Period on Price_close
      double ma2=iMA(Symbol(),0,MA2_Period,0,1,PRICE_CLOSE,i); // SMA of MA2_Period on Price_close
      ExtMapBuffer1[i]=(ma1-ma2)/Point;
      if (ExtMapBuffer1[i]>10 && ExtMapBuffer1[i+1]<=10)
 {
   SendMail("Spread Changed", "Above 10");
 }   
    }   
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
Considering that I need this indicator for both directions (long/short), I want it to be triggered by a value of > 10 or <-10 because the -10 is the same indicator for a downwards trend,
Does this make any sense?
    if (ExtMapBuffer1[i]<10 && ExtMapBuffer1[i-1]>=10)
    {
    SendMail ("Spread Changed", "Below 10");
    }


My 2nd question is how to reverse it to send an alert when it is back below or above this level,
I also noticed a strange comment in the Journal "Mail: not enough space for 'Spread Changed'" I hope this has nothing to do with the code,
It now appears that the message is being sent repeatedly maybe this is cloging the mail queue, see this link https://www.mql5.com/en/forum/46481
so it will make more sense to only have the message sent one time when it crosses the levels in either direction, and a message when it crosses back.

Thanks for your time.
 
I have restarted the terminal and I can confirm that,
a) It was the MAIL problem mentioned in the above link about an over flooded queue in the outbox.
b) I received 42 messages in 1 minute.

thanks
Reason: