//+------------------------------------------------------------------+
//|   TRO_TradeLines                                                 |
//|                                                                  | 
//|   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/" 

#property indicator_chart_window
 


//---- input parameters 

extern bool Show.Labels = true ;
extern bool Show.Gauge  = true ;

extern double    myUpper      = 0 ; 
extern double    myLower      = 0 ;
extern double    myWindow     = 0.77 ;
extern int       myBars       = 8 ;
extern int       myShift      = 0 ;

extern int myChartY = 200 ;

extern bool   Show.PriceBox  = true ;
extern int    myBoxWidth     = 2;

extern int    myPips         = 25 ;



//---- buffers


int i;
  
double R1, R2, R3 ;  

double X05 ;
double X06 ;   
double X07 ;
double X08, XRN ; 
double xRet ;
double xRetPct;    
  
string tChartPeriod ; 

string tLabel01, tLabel02, tLabel03, tLabel04, tLabel05, tLabel06, tLabel07  ;   
 

double range  ;
double DynR; 
double DynS;  
datetime StartTime;
int digits ;

double point, Entry, work, goShort, goLong, reward, risk, ratio, Pct, line00, line25, line50, line75, line100  ;

bool xAutoCalc = false;
int nHH, nLL, nn; 
 
string shortName, OBJ001, OBJ002,OBJ003,OBJ004,OBJ005,OBJ006,OBJ007,OBJ008,OBJ009,  tShortName;
string OBJ010, OBJ011, OBJ012,OBJ013,OBJ014,OBJ015,OBJ016,OBJ017,OBJ018,OBJ019;
string OBJ020, OBJ021, OBJ022,OBJ023,OBJ024,OBJ025,OBJ026,OBJ027,OBJ028,OBJ029;

color colorLine ;

//+------------------------------------------------------------------+
   
int init()
  {

  shortName  = MakeUniqueName("tlns ","") + myBars ;
  tChartPeriod =  TimeFrameToString(Period()) ;
  IndicatorShortName(shortName);
   
  tShortName = shortName ;

  OBJ001 = shortName + "001" ;
  OBJ002 = shortName + "002" ;
  OBJ003 = shortName + "003" ;
  OBJ004 = shortName + "004" ;
  OBJ005 = shortName + "005" ;
  OBJ006 = shortName + "006" ;
  OBJ007 = shortName + "007" ;
  OBJ008 = shortName + "008" ;
  OBJ009 = shortName + "009" ;
  OBJ010 = shortName + "010" ;
  OBJ011 = shortName + "0011" ;
  OBJ012 = shortName + "0012" ;
  OBJ013 = shortName + "0013" ;
  OBJ014 = shortName + "0014" ;
  OBJ015 = shortName + "0015" ;
  OBJ016 = shortName + "0016" ;
  OBJ017 = shortName + "0017" ;
  OBJ018 = shortName + "0018" ;
  OBJ019 = shortName + "0019" ;
  OBJ020 = shortName + "0020" ;
  OBJ021 = shortName + "0021" ;
  OBJ022 = shortName + "0022" ;
  OBJ023 = shortName + "0023" ;
  OBJ024 = shortName + "0024" ;  
 
  
  digits = Digits ;
  point  = Point ;     
   
 

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

    
   ObjectDelete(OBJ001);
   ObjectDelete(OBJ002);
   ObjectDelete(OBJ003);
   ObjectDelete(OBJ004);  
   ObjectDelete(OBJ005); 
   ObjectDelete(OBJ006);
   ObjectDelete(OBJ007);
   ObjectDelete(OBJ008);
   ObjectDelete(OBJ009);
   ObjectDelete(OBJ010);

   ObjectDelete(tShortName+"01"); 
   ObjectDelete(tShortName+"02"); 
   ObjectDelete(tShortName+"03"); 
   ObjectDelete(tShortName+"04"); 
   ObjectDelete(tShortName+"05");        
   return(0);
  }
  
//+------------------------------------------------------------------+ 

int start()
{

DoWork() ;  

return(0);

} 

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

void DoWork()
{
  
 
 
 nHH      =  Highest(NULL,0,MODE_HIGH,myBars,myShift); 
 nLL      =  Lowest(NULL,0,MODE_LOW,myBars,myShift); 
 
 myUpper      = High[nHH]; 
 myLower      = Low[nLL]; 

      
if(nHH < nLL)
{
line00    = myUpper ;
line25    = myUpper - ( myPips * point ) ;
line50    = myUpper - ( 2 * myPips * point ) ;
line75    = myUpper - ( 3 * myPips * point ) ;
line100   = myUpper - ( 4 * myPips * point ) ;
colorLine = Red ;
nn        = nHH ;
}
else
{
line00    = myLower ;
line25    = myLower + (  myPips * point ) ;
line50    = myLower + ( 2 * myPips * point ) ;
line75    = myLower + ( 3 * myPips * point ) ;
line100   = myLower + ( 4 * myPips * point ) ;
colorLine = Lime ;
nn        = nLL ;
}


if(ObjectFind(OBJ006)==-1) {ObjectCreate(OBJ006,OBJ_TREND,0,0,0,0); ObjectSet(OBJ006,OBJPROP_RAY,false); }         

ObjectSet(OBJ006,OBJPROP_COLOR,colorLine);                            
ObjectSet(OBJ006,OBJPROP_STYLE,2);                              
ObjectMove(OBJ006,0,Time[nn],line00);
ObjectMove(OBJ006,1,Time[0],line00);   

if(ObjectFind(OBJ002)==-1) {ObjectCreate(OBJ002,OBJ_TREND,0,0,0,0); ObjectSet(OBJ002,OBJPROP_RAY,false); }         

ObjectSet(OBJ002,OBJPROP_COLOR,colorLine);                            
ObjectSet(OBJ002,OBJPROP_STYLE,2);                              
ObjectMove(OBJ002,0,Time[nn],line100);
ObjectMove(OBJ002,1,Time[0],line100);   

if(ObjectFind(OBJ003)==-1) {ObjectCreate(OBJ003,OBJ_TREND,0,0,0,0); ObjectSet(OBJ003,OBJPROP_RAY,false); }         

ObjectSet(OBJ003,OBJPROP_COLOR,colorLine);                            
ObjectSet(OBJ003,OBJPROP_STYLE,3);                              
ObjectMove(OBJ003,0,Time[nn],line75);
ObjectMove(OBJ003,1,Time[0],line75);   


  
if(ObjectFind(OBJ004)==-1) {ObjectCreate(OBJ004,OBJ_TREND,0,0,0,0); ObjectSet(OBJ004,OBJPROP_RAY,false); }         

ObjectSet(OBJ004,OBJPROP_COLOR,colorLine);                            
ObjectSet(OBJ004,OBJPROP_STYLE,1);                              
ObjectMove(OBJ004,0,Time[nn],line50);
ObjectMove(OBJ004,1,Time[0],line50);   

   
if(ObjectFind(OBJ005)==-1) {ObjectCreate(OBJ005,OBJ_TREND,0,0,0,0); ObjectSet(OBJ005,OBJPROP_RAY,false); }         

ObjectSet(OBJ005,OBJPROP_COLOR,colorLine);                            
ObjectSet(OBJ005,OBJPROP_STYLE,0);                              
ObjectMove(OBJ005,0,Time[nn],line25);
ObjectMove(OBJ005,1,Time[0],line25);  

if(Show.PriceBox) { DoBox() ; }
     
     

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


 string note2 = "Default Font Color";
 color  twFontColor              = DimGray;
 string note3                  = "Font Size";
 int twFontSize                  = 8;
 string note4                  = "Font Type";
 string twFontType               = "Verdana"; // Tahoma Courier
string RAN953 =  "*** TRO TradeLines ***"  ;   
string tObjName03 = "TROTL"  ; 
    
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, RAN953 , twFontSize ,  twFontType,  twFontColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, 3);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,  5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, 10); 
//+------------------------------------------------------------------+        

   WindowRedraw();        
     
   return(0);
}

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


void DoBox()    
{


      if (ObjectFind(tShortName+"01") != 0)
      {
          ObjectCreate(tShortName+"01",OBJ_ARROW,0,Time[0],line100);
          ObjectSet(tShortName+"01",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"01",OBJPROP_COLOR,colorLine);  
          ObjectSet(tShortName+"01",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"01",0,Time[0],line100);
         ObjectSet(tShortName+"01",OBJPROP_COLOR,colorLine);  
      }

       if (ObjectFind(tShortName+"02") != 0)
      {
          ObjectCreate(tShortName+"02",OBJ_ARROW,0,Time[0],line75);
          ObjectSet(tShortName+"02",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"02",OBJPROP_COLOR,colorLine);  
          ObjectSet(tShortName+"02",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"02",0,Time[0],line75);
         ObjectSet(tShortName+"02",OBJPROP_COLOR,colorLine);  
      }

 
      if (ObjectFind(tShortName+"03") != 0)
      {
          ObjectCreate(tShortName+"03",OBJ_ARROW,0,Time[0],line50);
          ObjectSet(tShortName+"03",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"03",OBJPROP_COLOR,colorLine);  
          ObjectSet(tShortName+"03",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"03",0,Time[0],line50);
         ObjectSet(tShortName+"03",OBJPROP_COLOR,colorLine);  
      }
      
      if (ObjectFind(tShortName+"04") != 0)
      {
          ObjectCreate(tShortName+"04",OBJ_ARROW,0,Time[0],line25);
          ObjectSet(tShortName+"04",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"04",OBJPROP_COLOR,colorLine);  
          ObjectSet(tShortName+"04",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"04",0,Time[0],line25);
         ObjectSet(tShortName+"04",OBJPROP_COLOR,colorLine);  
      }

      if (ObjectFind(tShortName+"05") != 0)
      {
          ObjectCreate(tShortName+"05",OBJ_ARROW,0,Time[0],line00);
          ObjectSet(tShortName+"05",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tShortName+"05",OBJPROP_COLOR,colorLine);  
          ObjectSet(tShortName+"05",OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tShortName+"05",0,Time[0],line00);
         ObjectSet(tShortName+"05",OBJPROP_COLOR,colorLine);  
      }
            
} // void

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

        

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);
}
//+------------------------------------------------------------------+
 
string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}
//+------------------------------------------------------------------+ 

/*
Comment(
"myUpper = ", DoubleToStr( myUpper, Digits), "\n",
"myLower = ", DoubleToStr( myLower, Digits), "\n",
"reward = ", DoubleToStr( reward, Digits), "\n",
"risk = ", DoubleToStr( risk, Digits), "\n",
"ratio = ", DoubleToStr( ratio, Digits), "\n",

"") ;

*/