Navigation:Home > Content >

EMA's.mq4

Time: 2015-07-01 | Download file:EMA's.mq4

//+------------------------------------------------------------------+
//|                                                        EMA's.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window   // Wohin ?
#property indicator_buffers 5      // Wieviele Signallinien?
#property indicator_color1 White   // Welche Farbe fьr welche Signallinie ?
#property indicator_color2 Orange
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Red

extern int ma1 = 8;                // Wieviele Perioden ?
extern int ma2 = 21;
extern int ma3 = 50;
extern int ma4 = 100;
extern int ma5 = 200;

double ma1_buffer [];
double ma2_buffer [];
double ma3_buffer [];
double ma4_buffer [];
double ma5_buffer [];  

int a_begin;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ma1_buffer);
   SetIndexLabel(0,"8 EMA");

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ma2_buffer);
   SetIndexLabel(1,"21 EMA");
   
   SetIndexStyle(2,DRAW_LINE,EMPTY,2);
   SetIndexBuffer(2,ma3_buffer);
   SetIndexLabel(2,"50 EMA");
   
   SetIndexStyle(3,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(3,ma4_buffer);
   SetIndexLabel(3,"100 EMA");
   
   SetIndexStyle(4,DRAW_LINE,EMPTY,3);
   SetIndexBuffer(4,ma5_buffer);
   SetIndexLabel(4,"200 EMA");

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
      ObjectDelete("ma1");
      ObjectDelete("ma2");      
      ObjectDelete("ma3");      
      ObjectDelete("ma4");      
      ObjectDelete("ma5");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   int    counted_bars=IndicatorCounted();
   if (counted_bars < 0) return(-1);
   if (counted_bars >0) counted_bars --;
   int pos=Bars-counted_bars;
   
   while (pos>=0) {
      ma1_buffer[pos]=iMA(NULL,0,ma1,NULL,MODE_EMA,PRICE_WEIGHTED,pos);
      SetPrice("ma1",Time[0], ma1_buffer[pos],White);    
      
      ma2_buffer[pos]=iMA(NULL,0,ma2,NULL,MODE_EMA,PRICE_WEIGHTED,pos);
      SetPrice("ma2",Time[0], ma2_buffer[pos],Orange); 
      
      ma3_buffer[pos]=iMA(NULL,0,ma3,NULL,MODE_EMA,PRICE_WEIGHTED,pos);
      SetPrice("ma3",Time[0], ma3_buffer[pos],Blue); 
      
      ma4_buffer[pos]=iMA(NULL,0,ma4,NULL,MODE_EMA,PRICE_WEIGHTED,pos);
      SetPrice("ma4",Time[0], ma4_buffer[pos],Red); 
      
      ma5_buffer[pos]=iMA(NULL,0,ma5,NULL,MODE_EMA,PRICE_WEIGHTED,pos);
      SetPrice("ma5",Time[0], ma5_buffer[pos],Red); 
      
      pos--;
  
   }
//----
   
//----

   return(0);
  }
//+------------------------------------------------------------------+
void SetPrice(string name, datetime Tm, double Prc, color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_ARROW, 0, Tm, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, 1);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1,Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, 1);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     } 
  }

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

Recommend