//-----------------------------------------------------------------------------
//                                                 Mn Range Pcnt              |
//-----------------------------------------------------------------------------

#property copyright "Mn"

#property indicator_chart_window
extern int /*mMaPrd = 10,*/
           mBars = 331,
           mTF   = 1440;
extern int mVertTab = 15, mHorizTab = 50;
extern int mTextSize = 8, mCorner = 0; 
extern color mCol = Red, mCol2 = Blue, mCol3 = Black;

string mColumns[8] = {"OH", "%", "OL",  "%", "OC",  "%", "HL", "%"};
int mRowsPerCol = 11,   mRowVal[11] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
int mFirstVTab = 15, mFirstHTab = 40, mHeadHTab = 40, 
    mNoCols, mCntOH[], mCntOL[], mCntOC[], mCntHL[];
double mPipFact = 1,
       mValOH[], mValOL[], mValOC[], mValHL[];


//-----------------------------------------------------------------------------
void init()
 {
  if(Digits == 3 || Digits == 5)
    mPipFact = 10;
  mNoCols = ArraySize(mColumns);
  ArrayResize(mValOH, mBars);
  ArrayResize(mValOL, mBars);
  ArrayResize(mValOC, mBars);
  ArrayResize(mValHL, mBars);
  ArrayResize(mCntOH, ArraySize(mRowVal));
  ArrayResize(mCntOL, ArraySize(mRowVal));
  ArrayResize(mCntOC, ArraySize(mRowVal));
  ArrayResize(mCntHL, ArraySize(mRowVal));
  
  for(int i = 0; i < mNoCols; i++)
   {
       for(int k = 0; k < mRowsPerCol; k++)
        {
         ObjectCreate("m.Data"+i+k, OBJ_LABEL, 0, 0, 0, 0, 0);
         ObjectSet("m.Data"+i+k, OBJPROP_CORNER, mCorner);
         ObjectSet("m.Data"+i+k, OBJPROP_COLOR, mCol3);
         ObjectSet("m.Data"+i+k, OBJPROP_YDISTANCE, mFirstVTab + mVertTab * k);
         ObjectSet("m.Data"+i+k, OBJPROP_XDISTANCE, mFirstHTab + mHorizTab * i);
         ObjectSetText("m.Data"+i+k, "", mTextSize, "Arial", CLR_NONE);
        } // for k
   }    // for i
   
  for(i = 0; i < mRowsPerCol; i++)
   {
       ObjectCreate("m.RowLabel"+i, OBJ_LABEL, 0, 0, 0, 0, 0);
       ObjectSet("m.RowLabel"+i, OBJPROP_CORNER, mCorner);
       ObjectSet("m.RowLabel"+i, OBJPROP_COLOR, mCol3);
       ObjectSet("m.RowLabel"+i, OBJPROP_YDISTANCE, mFirstVTab + mVertTab * i);
       ObjectSet("m.RowLabel"+i, OBJPROP_XDISTANCE, 2);
       string mTxt = mRowVal[i] + "-" + (mRowVal[i + 1]-1);
       if(i == mRowsPerCol - 1)
         mTxt = ">" + (mRowVal[i] - 1);
       ObjectSetText("m.RowLabel"+i, mTxt, mTextSize, "Arial", CLR_NONE);
   }
   
     for(int j = 0; j < mNoCols; j++)
      {
       ObjectCreate("m.HeadLabel"+j, OBJ_LABEL, 0, 0, 0, 0, 0);
       ObjectSet("m.HeadLabel"+j, OBJPROP_CORNER, mCorner);
       ObjectSet("m.HeadLabel"+j, OBJPROP_COLOR, mCol3);
       ObjectSet("m.HeadLabel"+j, OBJPROP_YDISTANCE, 2);
       ObjectSet("m.HeadLabel"+j, OBJPROP_XDISTANCE, mFirstHTab + 4 + mHorizTab * j);
       ObjectSetText("m.HeadLabel"+j, mColumns[j], mTextSize - 1, "Arial", mCol3);
      }
   
 }

//-----------------------------------------------------------------------------
void start() 
 {
   string mDat;
   static int mTime;
   double mTotCnt = 0, mValH = 0;
   
   if(Time[0] > mTime)
     {
       for(int m = 1; m <= mBars; m++)
        {
          mValOH[m] = (iHigh(NULL, mTF, m) - iOpen(NULL, mTF, m)) / Point / mPipFact;
          mValOL[m] = (iOpen(NULL, mTF, m) - iLow(NULL, mTF, m)) / Point / mPipFact;
          mValOC[m] = (MathMax(iOpen(NULL, mTF, m), iClose(NULL, mTF, m)) - 
                       MathMin(iOpen(NULL, mTF, m), iClose(NULL, mTF, m))) / Point / mPipFact;
          mValHL[m] = (iHigh(NULL, mTF, m) - iLow(NULL, mTF, m)) / Point / mPipFact;
        }
       
       ArrayInitialize(mCntOH, 0);  ArrayInitialize(mCntOL, 0);  
       ArrayInitialize(mCntOC, 0);  ArrayInitialize(mCntHL, 0);  
       for(int c = 0; c < mRowsPerCol; c++)  
        {
         for(m = 1; m <= mBars; m++)
          {
            mValH = mRowVal[c+1]; 
            if(c == mRowsPerCol -1 ) mValH = 2000;
            if(mValOH[m] >= mRowVal[c] && mValOH[m] < mValH)    mCntOH[c]++;
            if(mValOL[m] >= mRowVal[c] && mValOL[m] < mValH)    mCntOL[c]++;
            if(mValOC[m] >= mRowVal[c] && mValOC[m] < mValH)    mCntOC[c]++;
            if(mValHL[m] >= mRowVal[c] && mValHL[m] < mValH)    mCntHL[c]++;
          }
       mTotCnt = mBars; 
       ObjectSetText("m.Data"+0+c, DoubleToStr(mCntOH[c], 0), mTextSize, "Arial", mCol2);
       ObjectSetText("m.Data"+2+c, DoubleToStr(mCntOL[c], 0), mTextSize, "Arial", mCol2);
       ObjectSetText("m.Data"+4+c, DoubleToStr(mCntOC[c], 0), mTextSize, "Arial", mCol2);
       ObjectSetText("m.Data"+6+c, DoubleToStr(mCntHL[c], 0), mTextSize, "Arial", mCol2);

       ObjectSetText("m.Data"+1+c, DoubleToStr(mCntOH[c] / mTotCnt * 100, 1), mTextSize, "Arial", mCol);
       ObjectSetText("m.Data"+3+c, DoubleToStr(mCntOL[c] / mTotCnt * 100, 1), mTextSize, "Arial", mCol);
       ObjectSetText("m.Data"+5+c, DoubleToStr(mCntOC[c] / mTotCnt * 100, 1), mTextSize, "Arial", mCol);
       ObjectSetText("m.Data"+7+c, DoubleToStr(mCntHL[c] / mTotCnt * 100, 1), mTextSize, "Arial", mCol);
          
        }
     }
     
   return(0);
 }

//-----------------------------------------------------------------------------
void deinit()
 {
  string mObj;
  for(int i = ObjectsTotal() - 1; i >= 0; i--)
   {
     mObj = ObjectName(i);
     if(StringSubstr(mObj, 0, 2) == "m.")
       ObjectDelete(mObj);
   }
     
   return(0);
 }
//-----------------------------------------------------------------------------
   /*    for(int k = 0; k < mRowsPerCol; k++)
        {
          mValOH = iCustom(Symbol(), 0, "mn Var ATR", mMaPrd, 0, 0) / Point / mPipFact;
          mValOL = iCustom(Symbol(), 0, "mn Var ATR", mMaPrd, 2, 0) / Point / mPipFact;
          mValOC = iCustom(Symbol(), 0, "mn Var ATR", mMaPrd, 4, 0) / Point / mPipFact;
          mValHL = iCustom(Symbol(), 0, "mn Var ATR", mMaPrd, 6, 0) / Point / mPipFact;
        } // for k*/
        

