//+------------------------------------------------------------------+ 
//|   TRO_MM_STOPPING_VOLUME                                         | 
//|                                                                  | 
//|   Copyright © 2009, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|   All my indicators should be considered donationware. That is   |
//|   you are free to use them for your personal use, and are        |
//|   under no obligation to pay for them. However, if you do find   |
//|   this or any of my other indicators help you with your trading  |
//|   then any Gift or Donation as a show of appreciation is         |
//|   gratefully accepted.                                           |
//|                                                                  |
//|   Gifts or Donations also keep me motivated in producing more    |
//|   great free indicators. :-)                                     |
//|                                                                  |
//|   PayPal - THERUMPLEDONE@GMAIL.COM                               |  
//+------------------------------------------------------------------+ 
//| Use http://therumpledone.mbtrading.com/fx/ as your forex broker  |  
//| ...tell them therumpledone sent you!                             |  
//+------------------------------------------------------------------+ 


#property  copyright "Copyright © 2009, Avery T. Horton, Jr. aka TRO" 
#property  link      "http://www.therumpledone.com/" 
 

#property indicator_chart_window
  

//+------------------------------------------------------------------+  
 
extern bool  Show.Heading  =  true ;  
extern int  yAxis  = 60 ;
extern int  Corner = 1;


 

extern color TextColor    = DodgerBlue;
extern color HiLightColor = Magenta;

extern color StopVolLowColor  = Red;
extern color StopVolHighColor = Lime;
extern color NoSignalColor    = DimGray;


extern int   StopVolHighSymbol = 108 ; // x = 251
extern int   StopVolLowSymbol  = 108 ;
extern int   NoSignalSymbol    = 108 ;
//+------------------------------------------------------------------+

double num, denom;

int tframe[]={1,5,15,30,60,240,1440,10080,43200};

string tf[]={"M1","M5","M15","M30","H1","H4","D1","W1","MN","TOT"};

int tfnumber=9,columns=9 ;  
 

string TimeFrameStr;
double IndValLONG[9],IndValD[9] , CMI[9];

int xpos[10], ypos[10];
int w , j , xposTAG, LONG,   CC, nHH, nLL;

string TAG = "StopVolmm"   ;

string Arrow   ; 
 

string theArrowLONG[10],theArrowD[10] ;
color   theColorLONG[10], theColorD[10] ;



string ArrowHeadRt =  "Ø" ; // 216 up arrow head
string ArrowHeadUp =  "Ù" ; // 217 up arrow head
string ArrowHeadDn =  "Ú" ; // 218 up arrow head 

string symbol, tChartPeriod,  tLONGName ;  
int    digits, period , i ; 
 
double point ;

color thecolor, hdColor ;  

double  cVOLUME, pVOLUME, H, L, H1, L1, cRANGE, pRANGE;

bool StopVolLow, StopVolHigh ; 

string CustomName ;

int shift = 1;

bool firsttime  =  true ;

string   StopVolHighArrow  ;
string   StopVolLowArrow   ;
string   NoSignalArrow     ; 

//+------------------------------------------------------------------+
int init()
{
 
 
StopVolHighArrow = CharToStr(StopVolHighSymbol) ;
StopVolLowArrow  = CharToStr(StopVolLowSymbol) ;
NoSignalArrow    = CharToStr(NoSignalSymbol) ; 
 
 
deinit();

   period       = Period() ;   
   symbol       = Symbol() ;
   digits       =  Digits ;   
   point        =  Point ; 

   if(digits == 5 || digits == 3) { digits = digits - 1 ; point = point * 10 ; }   
 

if(Corner == 1 || Corner == 3)
{ 
   for( w = 0 ; w < columns ; w++) { xpos[w] = 15 + ((10 - w)*23) ; } 
   xposTAG = 270 ;
} 
else
{
   for( w=0;w<columns;w++) { xpos[w] = w*23 + 50 ; }
   xposTAG = 10 ;
}
/*
         ObjectCreate(TAG+"HD1",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD1",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD1",OBJPROP_XDISTANCE,xposTAG);
         ObjectSet(TAG+"HD1",OBJPROP_YDISTANCE,yAxis+30);
         ObjectSetText(TAG+"HD1","VOLUME" ,8,"Tahoma",TextColor);
         

         ObjectCreate(TAG+"HD",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD",OBJPROP_XDISTANCE,xposTAG);
         ObjectSet(TAG+"HD",OBJPROP_YDISTANCE,yAxis+50);
         ObjectSetText(TAG+"HD","LONG",8,"Tahoma",TextColor);

 
         
         ObjectCreate(TAG+"HD2",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD2",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD2",OBJPROP_XDISTANCE,xposTAG);
         ObjectSet(TAG+"HD2",OBJPROP_YDISTANCE,yAxis+70);
         ObjectSetText(TAG+"HD2","C-C",8,"Tahoma",TextColor);         


   for( w=0;w<columns;w++)
      {
      
         if(tframe[w] == period) { hdColor = HiLightColor ; }
         else  { hdColor = TextColor ; }
      
         ObjectCreate(TAG+tf[w],OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+tf[w],OBJPROP_CORNER,Corner);
         ObjectSet(TAG+tf[w],OBJPROP_XDISTANCE,xpos[w]);
         ObjectSet(TAG+tf[w],OBJPROP_YDISTANCE,yAxis+15);
         ObjectSetText(TAG+tf[w],tf[w],8,"Tahoma",hdColor);                     
      }
*/
//----
   
   
   return(0);
  } 
  

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

void ObDeleteObjectsByPrefix(string Prefix)
  {
   int L = StringLen(Prefix);
   int i = 0; 
   while(i < ObjectsTotal())
     {
       string ObjName = ObjectName(i);
       if(StringSubstr(ObjName, 0, L) != Prefix) 
         { 
           i++; 
           continue;
         }
       ObjectDelete(ObjName);
     }
  }
    
//+------------------------------------------------------------------+
int deinit()
  {
        
   ObDeleteObjectsByPrefix(TAG);  
   TRO() ;
   return(0);
  }
  
//+------------------------------------------------------------------+
int start()
  {

  
   if(firsttime)
   {
      firsttime  =  false ;
      
         ObjectCreate(TAG+"HD1",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD1",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD1",OBJPROP_XDISTANCE,xposTAG);
         ObjectSet(TAG+"HD1",OBJPROP_YDISTANCE,yAxis+30);
         ObjectSetText(TAG+"HD1", "StopVol" ,8,"Tahoma",TextColor);
         
      
   if(Show.Heading)
   {
   for( w = 0;w<columns;w++)
      {
      
         if(tframe[w]  ==  period) { hdColor  =  HiLightColor ; }
         else  { hdColor  =  TextColor ; }
      
         ObjectCreate(TAG+tf[w],OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+tf[w],OBJPROP_CORNER,Corner);
         ObjectSet(TAG+tf[w],OBJPROP_XDISTANCE,xpos[w]);
         ObjectSet(TAG+tf[w],OBJPROP_YDISTANCE,yAxis+15);
         ObjectSetText(TAG+tf[w],tf[w],8,"Tahoma",hdColor);                     
      }
   } // if
   
   
   }  // if(firsttime)
  
        
//----
   

   for( j=0;j<columns ;j++)
   {
      if (ObjectFind(TAG+j) != 0)
      {
      
         ObjectCreate(TAG+j+"C",OBJ_LABEL,0,0,0,0,0);        
         ObjectSet(TAG+j+"C",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+j+"C",OBJPROP_XDISTANCE,xpos[j]);
         ObjectSet(TAG+j+"C",OBJPROP_YDISTANCE,yAxis+30);
         ObjectSetText(TAG+j+"C","00",8,"Tahoma",White);
         
/*                 
         ObjectCreate(TAG+j,OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+j,OBJPROP_CORNER,Corner);
         ObjectSet(TAG+j,OBJPROP_XDISTANCE,xpos[j]);
         ObjectSet(TAG+j,OBJPROP_YDISTANCE,yAxis+50);
         ObjectSetText(TAG+j,CharToStr(108),12,"Wingdings",White);
       
         
         ObjectCreate(TAG+j+"D",OBJ_LABEL,0,0,0,0,0);         
         ObjectSet(TAG+j+"D",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+j+"D",OBJPROP_XDISTANCE,xpos[j]);
         ObjectSet(TAG+j+"D",OBJPROP_YDISTANCE,yAxis+70);
         ObjectSetText(TAG+j+"D",CharToStr(110),12,"Tahoma",White);              
*/         
         
      }// if
   } // for

    
   for(int x=0;x<tfnumber;x++)
   {
 
   cVOLUME = iVolume(symbol,tframe[x],0); 
   pVOLUME = iVolume(symbol,tframe[x],1);  
   
   H = iHigh(symbol,tframe[x],0);
   L = iLow(symbol,tframe[x],0);

   H1 = iHigh(symbol,tframe[x],1);
   L1 = iLow(symbol,tframe[x],1); 
  
   cRANGE = H - L ;
   pRANGE = H1 - L1 ;
   
   StopVolLow  = cVOLUME > pVOLUME && cRANGE < pRANGE && L < L1 ;   
   StopVolHigh = cVOLUME > pVOLUME && cRANGE < pRANGE && H > H1 ;   
   
   while(true)
   {
      if (StopVolLow ){theArrowLONG[x] = StopVolLowArrow  ; theColorLONG[x] = StopVolLowColor  ;  break ; }
      if (StopVolHigh){theArrowLONG[x] = StopVolHighArrow ; theColorLONG[x] = StopVolHighColor ;  break ; }
 
      theArrowLONG[x] = NoSignalArrow ; theColorLONG[x] = NoSignalColor;
      break ;


   } // while

        
      for(int  y=0;y<columns;y++)
      { 
//         ObjectSetText(TAG+y,theArrowLONG[y],12,"Wingdings",theColorLONG[y]);
         ObjectSetText(TAG+y+"C",theArrowLONG[y] ,9,"Wingdings",theColorLONG[y]);
//         ObjectSetText(TAG+y+"D",theArrowD[y],12,"Wingdings",theColorD[y]);
      }  
  
  } // for
//----

 

   return(0);
  }
//+------------------------------------------------------------------+  
void TRO()
{   
   
   string tObjName03    = "TROTAG"  ;  
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, CharToStr(78) , 12 ,  "Wingdings",  DimGray );
   ObjectSet(tObjName03, OBJPROP_CORNER, 3);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, 5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, 5 );  
}


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

/*
double z = iCustom(symbol, tframe[x], CustomName, NumberOfBars,NumberOfBars,LookBack,false,myCorner,x.offset,y.offset,myFont,myFontSize, 2,0);       


if( tframe[x] == 30 ) 
{ 
Comment(
"x " , x , "\n" ,
"tframe[x] " , tframe[x] , "\n" ,
"VOLUME " , DoubleToStr(VOLUME,Digits) , "\n" ,
"z " , DoubleToStr(z,Digits) , "\n" ,
 
"") ;  
}

 

//+------------------------------------------------------------------+  
void DoShowLegend()
{ 

int yInc = 100 ;

   setObject(TAG+"CH","Climax High" ,30,yInc+20,ClimaxHighColor); setObject(TAG+"CH1",Arrow ,11,yInc+21,ClimaxHighColor     ,"Wingdings");
     
   setObject(TAG+"NE","Neutral" ,30,yInc+33,NeutralColor); setObject(TAG+"NE1",Arrow ,11,yInc+34,NeutralColor     ,"Wingdings");

   setObject(TAG+"LO","Low" ,30,yInc+46,LowColor); setObject(TAG+"LO1",Arrow ,11,yInc+46,LowColor,"Wingdings");
  
   setObject(TAG+"HI","High",30,yInc+59,HighChurnColor); setObject(TAG+"HI1",Arrow ,11,yInc+59,HighChurnColor,"Wingdings");

   setObject(TAG+"CL","Climax Low" ,30,yInc+72,ClimaxLowColor); setObject(TAG+"CL1",Arrow ,11,yInc+72,ClimaxLowColor,"Wingdings");
  
   setObject(TAG+"CC","Climax Churn",30,yInc+85,ClimaxChurnColor); setObject(TAG+"CC1",Arrow ,11,yInc+85,ClimaxChurnColor,"Wingdings");
        
}
//+------------------------------------------------------------------+  

void setObject(string labelName,string text,int x,int y,color theColor, string font = "Courier New",int size=10,int angle=0)
{
 
      
      if (ObjectFind(labelName) == -1)
          {
             ObjectCreate(labelName,OBJ_LABEL,0,0,0);
             ObjectSet(labelName,OBJPROP_CORNER,0);
             if (angle != 0)
                  ObjectSet(labelName,OBJPROP_ANGLE,angle);
          }               
       ObjectSet(labelName,OBJPROP_XDISTANCE,x);
       ObjectSet(labelName,OBJPROP_YDISTANCE,y);
       ObjectSetText(labelName,text,size,font,theColor);
}
  
*/