//+------------------------------------------------------------------+
//|                                         Moving Average Cross.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
// Input for display
input string               FontName             = "Tahoma";       // Font Name
input int                  FontSize             = 10;             // Font Size
input int                  TextCorner           = 1;              // Text Corner
input color                TextColor            = clrSkyBlue;     // Text Color
input int                  TextXAnchor          = 15;             // Text X Anchor
input int                  TextYAnchor          = 15;             // Text Y Anchor
input int                  FirstMAPeriod        = 10;             // 1st MA Period
input ENUM_MA_METHOD       FirstMAMethod        = MODE_SMA;       // 1st MA Method
input ENUM_APPLIED_PRICE   FirstMAAppliedPrice  = PRICE_CLOSE;    // 1st MA Applied Price
input int                  SecondMAPeriod       = 20;             // 2nd MA Period
input ENUM_MA_METHOD       SecondMAMethod       = MODE_SMA;       // 2nd MA Method
input ENUM_APPLIED_PRICE   SecondMAAppliedPrice = PRICE_CLOSE;    // 2nd MA Applied Price


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
      ObjectsDeleteAll(0, OBJ_LABEL);
  }  
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   DisplayInfo();
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//-------------------------------------------------------------------+
// Draw label                                                        |
//-------------------------------------------------------------------+
   void DrawLabel( string comment, string name, int x, int y, color col)
      {
          ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
          ObjectSet(name, OBJPROP_BACK, false);
          ObjectSet(name, OBJPROP_COLOR, col);
          ObjectSet(name, OBJPROP_CORNER, TextCorner);
          ObjectSet(name, OBJPROP_XDISTANCE, x);
          ObjectSet(name, OBJPROP_YDISTANCE, y);
          ObjectSetText(name, comment, FontSize, FontName);
      }

//-------------------------------------------------------------------+
// Display Info                                                      |
//-------------------------------------------------------------------+

   void DisplayInfo()
      { 
         string   lbl   = "ROOI";
         int      index = 1;
         string   Text  = "";
         double   FirstMAValue   = iMA(NULL,0,FirstMAPeriod,0,FirstMAMethod,FirstMAAppliedPrice,0);
         double   SecondMAValue   = iMA(NULL,0,SecondMAPeriod,0,SecondMAMethod,SecondMAAppliedPrice,0);        
         if ( FirstMAValue > SecondMAValue ) Text = "Up";
         if ( FirstMAValue < SecondMAValue ) Text = "Down";
         if ( FirstMAValue == SecondMAValue ) Text = "Flat";
         
         DrawLabel(  "MATrend is "+Text,
                     lbl+IntegerToString(index),TextXAnchor, TextYAnchor * index, TextColor);index++;
      }