//+------------------------------------------------------------------+
//|                                                       mnBigE.mq4 |
//+------------------------------------------------------------------+
#property copyright "mn"

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Red

extern int     mTF1     = 15,
               mTF2     = 60,
               mTF3     = 240,
               mPrd1    = 3,
               mPrd2    = 8,
               mPrd3    = 20;
extern bool    mAlert   = true;

double mShort[], mLong[], mNeutral[], mShort2[], mLong2[];

//-------------------------------------------------------------------
int init()
{
 SetIndexBuffer(0, mShort);
 SetIndexBuffer(1, mLong);
 SetIndexBuffer(2, mNeutral);
 SetIndexBuffer(3, mShort2);
 SetIndexBuffer(4, mLong2);
 SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, 4, clrNavy);
 SetIndexStyle(1, DRAW_HISTOGRAM, EMPTY, 4, clrMaroon);
 SetIndexStyle(2, DRAW_HISTOGRAM, EMPTY, 4, clrPlum);
 SetIndexStyle(3, DRAW_HISTOGRAM, EMPTY, 4, clrBlue);
 SetIndexStyle(4, DRAW_HISTOGRAM, EMPTY, 4, clrRed);
 SetIndexLabel(0, "");
 SetIndexLabel(1, "");
 SetIndexLabel(2, "");
 SetIndexLabel(3, "");
 SetIndexLabel(4, "");

 IndicatorShortName("MnBigE " + mTF1  + " " + mTF2  + " " + mTF3);
 
 return(0);
}

//-------------------------------------------------------------------
int deinit()
{
   Comment("");
   
   return(0);
}

//-------------------------------------------------------------------
int start()
 {
   double mMA, mMA2, mMA3, mS1, mS2, mS3, mL1, mL2, mL3;
   int mCounted  = IndicatorCounted();
      if(mCounted<0) return(-1);
      if(mCounted>0) mCounted--;
           int limit = MathMin(Bars-mCounted,Bars-1);
            
      for(int i = limit; i >= 0; i--)
      {
        int j = iBarShift(NULL, mTF1, Time[i], false);
        mMA       = iMA(NULL, mTF1, mPrd2, 0, 1, 0, j);
        mS1 = iMA(NULL, mTF1, mPrd1, 0, 1, 0, j)/mMA;
        mL1  = iMA(NULL, mTF1, mPrd3, 0, 1, 0, j)/mMA;

        j = iBarShift(NULL, mTF2, Time[i], false);
        mMA2       = iMA(NULL, mTF2, mPrd2, 0, 1, 0, j);
        mS2 = iMA(NULL, mTF2, mPrd1, 0, 1, 0, j)/mMA2;
        mL2  = iMA(NULL, mTF2, mPrd3, 0, 1, 0, j)/mMA2;

        j = iBarShift(NULL, mTF3, Time[i], false);
        mMA3       = iMA(NULL, mTF3, mPrd2, 0, 1, 0, j);
        mS3 = iMA(NULL, mTF3, mPrd1, 0, 1, 0, j)/mMA3;
        mL3  = iMA(NULL, mTF3, mPrd3, 0, 1, 0, j)/mMA3;
        
        if(mS1 > 1 && mS2 > 1 && mL1 < 1 && mL2 < 1)
          {
            mShort2[i] = 1; 
            mLong2[i] = 0;
          }
        else if(mS1 < 1 && mS2 < 1 && mL1 > 1 && mL2 > 1)
          {
            mShort2[i] = 0; 
            mLong2[i] = 1;
          }
        else
          { mShort2[i] = 0; mLong2[i] = 0; }

        if(mS1 > 1 && mS2 > 1 && mS3 > 1 && mL1 < 1 && mL2 < 1 && mL3 < 1)
          {
            mShort[i] = 2; 
            mLong[i] = 0;
            mNeutral[i] = 0;
          }
        else if(mS1 < 1 && mS2 < 1 && mS3 < 1 && mL1 > 1 && mL2 > 1 && mL3 > 1)
          {
            mShort[i] = 0; 
            mLong[i] = 2;
            mNeutral[i] = 0;
          }
        else 
          {
            mShort[i] = 0; 
            mLong[i] = 0;
            mNeutral[i] = 2;
          }
      }
   
   if(mAlert)
   {
   }
 
 return(0);
 }

//-------------------------------------------------------------------
