//+------------------------------------------------------------------+
//|   _TRO_TRENDLINE                      Ind-WSO+WRO+Trend Line.mq4 |
//|                    Copyright © 2004, http://www.expert-mt4.nm.ru |
//|                                      http://www.expert-mt4.nm.ru |
//| Индикатор был разработан на основе индикатора Widners Oscilator. |
//| Мною была разработана торговая стратегия, основанная на          |
//| показаниях Ind-WSO+WRO+Trend Line индикатора. Подробности        |
//| вы можете узнать в форуме на моем сайте                          |
//| http://www.expert-mt4.nm.ru/forum.dhtml                          |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, http://www.expert-mt4.nm.ru"
#property link      "http://www.expert-mt4.nm.ru"

#property indicator_chart_window
//---- input parameters

extern bool show.OHLC = true ;

extern color MidColor = Aqua ;
extern color pMidColor = Magenta ;
extern color CloseColor = Yellow ;
extern color OpenColor = White ;
extern color LowColor = Red ;
extern color HighColor = Green ;

extern color TLResColor = Magenta ;
extern color TLSupColor = Aqua ;

///---- int Widners Oscilator
int cnt,nCurBar=0;

int ChartPeriod ;

bool sH0, sH1, sL0, sL1 ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
  ChartPeriod = Period();

if ( show.OHLC ) {


      ObjectCreate("WSO-Mid",OBJ_HLINE,0,0,0);
      ObjectSet("WSO-Mid",OBJPROP_COLOR,MidColor); 
      ObjectSet("WSO-Mid",OBJPROP_STYLE,STYLE_DASH); 
              
      ObjectCreate("WSO-pMid",OBJ_HLINE,0,0,0);
      ObjectSet("WSO-pMid",OBJPROP_COLOR,pMidColor);  
      ObjectSet("WSO-pMid",OBJPROP_STYLE,STYLE_DASH); 


      ObjectCreate("WSO-Close",OBJ_HLINE,0,0,0);
      ObjectSet("WSO-Close",OBJPROP_COLOR,CloseColor); 
      ObjectSet("WSO-Close",OBJPROP_STYLE,STYLE_DASH); 
              
      ObjectCreate("WSO-Open",OBJ_HLINE,0,0,0);
      ObjectSet("WSO-Open",OBJPROP_COLOR,White);  
      ObjectSet("WSO-Open",OBJPROP_STYLE,STYLE_DASH); 
      
      ObjectCreate("WSO-0",OBJ_HLINE,0,0,0);
      ObjectSet("WSO-0",OBJPROP_COLOR,LowColor);
      ObjectSet("WSO-0",OBJPROP_STYLE,STYLE_DASH);       
      

      ObjectCreate("WRO-0",OBJ_HLINE,0,0,0);
      ObjectSet("WRO-0",OBJPROP_COLOR,HighColor);
      ObjectSet("WRO-0",OBJPROP_STYLE,STYLE_DASH); 
}


    ObjectCreate("Trend DN-0",OBJ_TREND,0,0,0,0,0);    
    ObjectSet("Trend DN-0",OBJPROP_COLOR,TLSupColor);
    
    ObjectCreate("Trend UP-0",OBJ_TREND,0,0,0,0,0);
    ObjectSet("Trend UP-0",OBJPROP_COLOR,TLResColor);
    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
      ObjectDelete("WSO-Mid");
      ObjectDelete("WSO-pMid");       
      ObjectDelete("WSO-Close");
      ObjectDelete("WSO-Open");
      ObjectDelete("WRO-0");
      ObjectDelete("WSO-0");
      ObjectDelete("Trend UP-0");
      ObjectDelete("Trend DN-0");
      
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
  if( ChartPeriod != PERIOD_H1 ) { Comment ("***error - must be HPERIOD_H1" ) ; return (-1) ; } 
  
//---- TODO: add your code here
   double cLow,pLow,r1,r2,r3,r4,r5,r6,OP,CL;
   int rt1,rt2,rt3,rt4,rt5,rt6, i;
   
   double MD, PM, L0,L1,H0,H1,cHigh,pHigh,s1,s2,s3,s4,s5,s6;
   int D0,D1,st1,st2,st3,st4,st5,st6;

/*
  sH0 = true ;
  sH1 = true ;
  sL0 = true ;  
  sL1 = true ;  
*/
 
 
 cHigh = -1 ;
 cLow = 999999999 ;
 pHigh = -1 ;
 pLow = 999999999 ;
 
 D0 = TimeDay( Time[0] ) ; 
 D1 = D0 - 1 ;
  
 for( i=0; i<=23; i++)
 {
 if( TimeDay( Time[i] ) != D0 ) { break ; }
 
 H0 = iHigh(NULL,ChartPeriod,i) ;
 L0 = iLow(NULL,ChartPeriod,i) ;
 OP = iOpen(NULL,PERIOD_D1 ,1) ;
 CL = iClose(NULL,PERIOD_D1 ,1) ; 
 
    
 if ( H0 > cHigh ) { cHigh  = H0 ; rt1 = i ; }
 if ( L0 < cLow  ) { cLow   = L0 ; st1 = i ; }  
 
 } // for(i=0...
  
      
 for( i=1; i<=47; i++)
 {
 if( TimeDay( Time[i] ) < D1 ) { break ; }
  
 if( TimeDay( Time[i] ) < D0 ) {
 H1 = iHigh(NULL,ChartPeriod,i) ;
 L1 = iLow(NULL,ChartPeriod,i) ;

   
 if ( H1 > pHigh ) { pHigh  = H1 ; rt2 = i ; }
 if ( L1 < pLow  ) { pLow   = L1 ; st2 = i ; }  
 }
 } // for(i=24...      
      

//---- Move Object in Chart

ObjectMove("Trend DN-0",1,Time[st1],cLow); // ("Trend DN-0",1,Time[st1],s1);
ObjectMove("Trend DN-0",0,Time[st2],pLow); //  ("Trend DN-0",0,Time[st2],s2)

ObjectMove("Trend UP-0",1,Time[rt1],cHigh);
ObjectMove("Trend UP-0",0,Time[rt2],pHigh);

if ( show.OHLC ) 
{

MD = (iHigh(NULL,PERIOD_D1,0) + iLow(NULL,PERIOD_D1, 0) ) * 0.50 ;
PM = (H1 + L1) * 0.50 ; 
      
ObjectMove("WSO-0",0,Time[st2],pLow);
ObjectMove("WRO-0",0,Time[rt2],pHigh);

ObjectMove("WSO-Open",0,Time[47],OP);
ObjectMove("WSO-Close",0,Time[47],CL);


ObjectMove("WSO-Mid",0,Time[47],MD);
ObjectMove("WSO-pMid",0,Time[47],PM);
}



/*

Comment( "H0 =", H0, " r1=", r1, " rt1=", rt1, "\n",
         "H1 =", H1, " r2=", r2, " rt2=", rt2, "\n",
         "cHigh=", cHigh, " pHigh=", pHigh, "\n",         
         "L0 =", L0, " s1=", s1, " st1=", st1, "\n",
         "L1 =", L1, " s2=", s2, " st2=", st2, "\n",       
         "cLow=", cLow, " pLow=", pLow, "\n",     
         "D0 =", D0, " D1 =", D1,  "\n",              
         " ") ;
    
*/ 
         
return(0);
}

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