//+------------------------------------------------------------------+ 
//|               tro_123_lines                                      | 
//+------------------------------------------------------------------+  
 
 

#property indicator_chart_window 
#property indicator_buffers 2
#property indicator_color1 MediumVioletRed 
#property indicator_color2 DodgerBlue 
 
//+--------- TRO MODIFICATION ---------------------------------------+ 

extern bool   Sound.Alert    = true ;
 
//---- input parameters 

//extern int LinesToShow      = 10 ; 
extern int BarsBack         = 24 ; 


extern double Line_Style    = STYLE_DASH ;

extern int Symbol_1_Kod=217; //140
extern int Symbol_2_Kod=218; // 141
//extern int Symbol_3_Kod=142;


//---- buffers 
double FP_BuferUp[];
double FP_BuferDn[]; 
double high0, high1, high2 ;
double Low0, Low1, Low2 ;

//+--------- TRO MODIFICATION ---------------------------------------+ 
string symbol, tChartPeriod,  tShortName ;  
int    digits, period  ; 

bool Trigger1,  Trigger2,  Trigger3 ;




color tColor = Yellow ;

string   labelNames;

int      totalLabels;
int      corner;
int      window = 0 ;  
int      LinesPlotted;  

   int limit,i;
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  { 
//+--------- TRO MODIFICATION ---------------------------------------+  
   period       = Period() ;     
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;   

   tShortName = "t123l"+ symbol + tChartPeriod  ;
   labelNames = tShortName;
 
   SetIndexStyle(0,DRAW_ARROW,0,1); 
   SetIndexArrow(0,Symbol_1_Kod); 
   SetIndexBuffer(0,FP_BuferUp); 
   SetIndexEmptyValue(0,0.0); 
   
   SetIndexStyle(1,DRAW_ARROW,0,1); 
   SetIndexArrow(1,Symbol_2_Kod); 
   SetIndexBuffer(1,FP_BuferDn); 
   SetIndexEmptyValue(1,0.0); 
 
   totalLabels     = 0;

   return(0); 
  } 
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
  { 

   while (totalLabels>0) { ObjectDelete(StringConcatenate(labelNames,totalLabels)); totalLabels--;}
 
   ObjectsDeleteAll( window, OBJ_HLINE); 
 
   return(0); 
  } 


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

int start() 
  { 
  
   int counted_bars=IndicatorCounted();
   
   LinesPlotted = 0 ;
   ObjectsDeleteAll( window, OBJ_HLINE); 
   

   limit=Bars-counted_bars;
   

  for(i = 1 ; i <= BarsBack; i++) 
  { 
    high0 = iHigh(NULL,period,i-1) ;
    high1 = iHigh(NULL,period,i) ;     
    high2 = iHigh(NULL,period,i+1) ;    
    
    if( high0 < high1 && high2 < high1 ) {FP_BuferUp[i] = high1 ; setLine(next(), indicator_color1, high1 ); } else  {FP_BuferUp[i] = 0 ; }

   

    Low0 = iLow(NULL,period,i-1) ;
    Low1 = iLow(NULL,period,i) ;     
    Low2 = iLow(NULL,period,i+1) ;    
    
    if( Low0 > Low1 && Low2 > Low1 ) {FP_BuferDn[i] = Low1 ; setLine(next(), indicator_color2, Low1 );  } else  {FP_BuferDn[i] = 0 ; }
  }   
       
       
               
   return(0);
}

//+--------- TRO MODIFICATION ---------------------------------------+  

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);
}
//+------------------------------------------------------------------+

string next() { totalLabels++; return(totalLabels); }  

//+------------------------------------------------------------------+
void setLine(string name, color theColor, double srprice )
{


   string labelName = StringConcatenate(labelNames,name);



      if (ObjectFind(labelName) != 0)
      {
         ObjectCreate(labelName,OBJ_HLINE,0,0,0);
         ObjectSet(labelName,OBJPROP_COLOR,theColor); 
         ObjectSet(labelName,OBJPROP_STYLE,Line_Style);
      } // if
      
 
      ObjectMove(labelName,0,Time[0],srprice); 
      
}      

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


void setObject(string name,string text,int x,int y,color theColor, string font = "Arial",int size=10,int angle=0)
{
   string labelName = StringConcatenate(labelNames,name);

   //
   //
   //
   //
   //
      
      if (ObjectFind(labelName) == -1)
          {
             ObjectCreate(labelName,OBJ_LABEL,window,0,0);
             ObjectSet(labelName,OBJPROP_CORNER,corner);
             if (angle != 0)
                  ObjectSet(labelName,OBJPROP_ANGLE,angle);
          }               
       ObjectSet(labelName,OBJPROP_XDISTANCE,x);
       ObjectSet(labelName,OBJPROP_YDISTANCE,y);
       ObjectSetText(labelName,text,size,font,theColor);
}


//+------------------------------------------------------------------+
/*

Comment( 
"high0 = ", DoubleToStr(high0 , digits), "\n",        
"high1 = ", DoubleToStr(high1 , digits), "\n",  
"high2 = ", DoubleToStr(high2 , digits), "\n",  
"Low0 = ", DoubleToStr(Low0 , digits), "\n",        
"Low1 = ", DoubleToStr(Low1 , digits), "\n",  
"Low2 = ", DoubleToStr(Low2 , digits), "\n",  
"") ; 

*/