//+------------------------------------------------------------------+ 
//|   _TRO_Rocket_Tank                                               | 
//|                                                                  | 
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |
//|   therumpledone@gmail.com                                        |  
//+------------------------------------------------------------------+ 


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

//---- indicator settings 
#property indicator_chart_window
#property indicator_buffers 0


//---- indicator parameters  
 

extern int win = 0;
extern int price.x.offset= 0 ;
extern int price.y.offset= 100 ;

extern bool my.alert.sound     = false ;

extern int   myFontSize      = 15 ;
extern int   Chart_Period    = 0;
extern int   myThreshold     = 10 ;
extern int   myBars          = 10 ;



extern color Up_color = Lime;
extern color Eq_color = Yellow;
extern color Dn_color = Red;


string tLabel01, tLabel02, tLabel03 ;

int xBarVal,xRocketBar,oHighBar,MyBar ,xTankBar,digits ;

double xTankMax, xTank,xRocketMax,xRocket ,MyVal ,oHighVal,xSpeed,xMaxVal ;

string  tTmsg,tRmsg, symbol, tPeriod ;

double rclose, tclose, close, point, xThreshold  ;

color RColor,   TColor ;

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 

int init() 
{ 

tPeriod = " "+TimeFrameToString( Chart_Period ) ;
symbol =  Symbol() ;

if(Chart_Period == 0) { Chart_Period = Period() ; }

tLabel01 = "RT9929" + Chart_Period + myBars + symbol;
tLabel02 = "RT9930" + Chart_Period + myBars + symbol;
tLabel03 = "RT9931" + Chart_Period + myBars + symbol;

digits = Digits ;
point = Point ;

xThreshold = myThreshold * point ;

return(0); 
  } 

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

int deinit() 
{ 
ObjectsDeleteAll( win, 21);
ObjectsDeleteAll( win, 22);
ObjectsDeleteAll( win, 23);
   ObjectDelete(tLabel01);
   ObjectDelete(tLabel02);
   ObjectDelete(tLabel03); 
      
}  

//+------------------------------------------------------------------+ 
int start() 
{ 


  
int limit; 
  
close  = iClose(NULL,Chart_Period,0) ; 


tRmsg = "" ;
tTmsg = "" ;

xSpeed     = 0; 
xTankMax   = 0;
xRocketMax = 0;

xMaxVal = 0;
xBarVal = 0;
 
xTank = fTank( );

xRocket = fRocket( );

if(xTankMax > xThreshold )
{
xMaxVal = xTankMax;
xBarVal = xTankBar;
TColor = Red ;
tTmsg  =  "TANKING " +  DoubleToStr(xTankMax/point,0)  + " pips in " + xTankBar + " bars"  ;
if( my.alert.sound ) { Alert( tTmsg  ) ; }

}



if( xRocketMax > xThreshold)
{
xMaxVal = xRocketMax;
xBarVal = xRocketBar;

RColor = Lime ;
tRmsg  =  "ROCKETING " + DoubleToStr(xRocketMax/point,0) + " pips in "  + xRocketBar  + " bars" ;
if( my.alert.sound ) { Alert( tRmsg ) ; } 

}

//if (xBarVal != 0) { xSpeed = 100 * (xMaxVal / xBarVal) ; }

       
   ObjectCreate(tLabel01, OBJ_LABEL, win, 0, 0); 
   ObjectSetText(tLabel01,tRmsg, myFontSize, "Arial Bold", RColor );
   ObjectSet(tLabel01, OBJPROP_CORNER, 0);
   ObjectSet(tLabel01, OBJPROP_XDISTANCE, price.x.offset);
   ObjectSet(tLabel01, OBJPROP_YDISTANCE, price.y.offset);
   
   ObjectCreate(tLabel02, OBJ_LABEL, win, 0, 0); 
   ObjectSetText(tLabel02,tTmsg, myFontSize, "Arial Bold", TColor );
   ObjectSet(tLabel02, OBJPROP_CORNER, 0);
   ObjectSet(tLabel02, OBJPROP_XDISTANCE, price.x.offset);
   ObjectSet(tLabel02, OBJPROP_YDISTANCE, myFontSize*2+price.y.offset);
      
   
   
   WindowRedraw();    
 
//} 

/*
Comment( tRmsg , "\n",  
         tTmsg, "\n", 
         "xRocketMax ", xRocketMax , "\n", 
         "xRocketBar ", xRocketBar , "\n",        
         "xTankMax ", xTankMax, "\n",
         "xTankBar ", xTankBar, "\n",         
         "rclose ", rclose, "\n",         
         "tclose ", tclose, "\n",                 
         "threshold ", xThreshold ) ;

*/

   return(0); 
} 

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

 
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}
 
 
//+------------------------------------------------------------------+ 

int fRocket( ) 
{
MyVal = 0 ;
MyBar = 0 ;
xMaxVal = 0 ;

for (int i=1;i<=myBars;i++)
{ 
rclose = iClose(NULL,Chart_Period,i) ;

if ( close - rclose  > MyVal ) 
{
MyVal = close - rclose  ;
MyBar = i ;
}

}// for

xRocketMax = MyVal ;
xRocketBar = MyBar ;

return ( 0 );
}

//+------------------------------------------------------------------+
int fTank( )
{
MyVal = 0 ;
MyBar = 0 ;
xMaxVal = 0 ;

for (int i=1;i<=myBars;i++)
{ 
tclose = iClose(NULL,Chart_Period,i) ;

if ( tclose - close > MyVal ) 
{
MyVal = tclose  - close  ;
MyBar = i ;
}

}// for

xTankMax = MyVal ;
xTankBar = MyBar ;

return ( 0 );
}
 
  
/*
   
   ObjectCreate(tLabel02, OBJ_LABEL, win, 0, 0); 
   ObjectSetText(tLabel02,ttank, 15, "Arial Bold", tankColor );
   ObjectSet(tLabel02, OBJPROP_CORNER, 0);
   ObjectSet(tLabel02, OBJPROP_XDISTANCE, 520+price.x.offset);
   ObjectSet(tLabel02, OBJPROP_YDISTANCE, 100+price.y.offset); 
                                        
   ObjectCreate(tLabel03, OBJ_LABEL, win, 0, 0);
   
   ObjectSetText(tLabel03,DoubleToStr(close, Digits ) +tPeriod , 30, "Arial Bold", ClOpColor );
   ObjectSet(tLabel03, OBJPROP_CORNER, 0);
   ObjectSet(tLabel03, OBJPROP_XDISTANCE, 520+price.x.offset); // 765
   ObjectSet(tLabel03, OBJPROP_YDISTANCE, 60+price.y.offset); 
          


*/