//+------------------------------------------------------------------+
//|   _TRO_WSOWROTL                       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 string iparms = " nPeriod = 9, Limit = 300 " ;
extern int nPeriod = 55; // 9
extern int Limit   = 1000; // 300

extern double Line_Style    = STYLE_DASH ;

extern bool PlotProj     = true ;

extern bool PlotTrend    = true ;
extern bool PlotOldTrend = false ;
extern bool PlotRS       = true ;
extern bool PlotOldRS    = true ;

extern double    iLevelP1=0.382; 
extern double    iLevelP2=0.618; 


extern color ColorProj       = Magenta ;
extern color ColorTrendUp    = Red ;
extern color ColorTrendDn    = Blue ;
extern color ColorOldTrendUp = Maroon ;
extern color ColorOldTrendDn = Navy ;
extern color ColorRes        = Red ;
extern color ColorSup        = Blue ; 
extern color ColorOldRes     = Maroon ;
extern color ColorOldSup     = Navy ;

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

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
    
   ObjectsDeleteAll(0,OBJ_HLINE); 
   ObjectsDeleteAll(0,OBJ_TREND);
    return(0);
  }
  


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

  DoPlot() ;  
  


   double pr1,pr2, ps1,ps2, sr_range;
   
   double r1,r2,r3,r4,r5,r6;
   int rt1,rt2,rt3,rt4,rt5,rt6;
   double s1,s2,s3,s4,s5,s6;
   int st1,st2,st3,st4,st5,st6;

if(Bars<Limit) Limit=Bars-nPeriod;
for(nCurBar=Limit; nCurBar>0; nCurBar--)
   {
   if(Low[nCurBar+(nPeriod-1)/2] == Low[Lowest(NULL,0,MODE_LOW,nPeriod,nCurBar)])
      {
      s6=s5; s5=s4; s4=s3; s3=s2; s2=s1; s1=Low[nCurBar+(nPeriod-1)/2];
      st6=st5; st5=st4; st4=st3; st3=st2; st2=st1; st1=nCurBar+(nPeriod-1)/2;
      }
   if(High[nCurBar+(nPeriod-1)/2] == High[Highest(NULL,0,MODE_HIGH,nPeriod,nCurBar)])
      {
      r6=r5; r5=r4; r4=r3; r3=r2; r2=r1; r1=High[nCurBar+(nPeriod-1)/2];
      rt6=rt5; rt5=rt4; rt4=rt3; rt3=rt2; rt2=rt1; rt1=nCurBar+(nPeriod-1)/2;
      }
   }
//---- Move Object in Chart

if(PlotTrend){
ObjectMove("Trend DN-0",1,Time[st1],s1);
ObjectMove("Trend DN-0",0,Time[st2],s2);
ObjectMove("Trend UP-0",1,Time[rt1],r1);
ObjectMove("Trend UP-0",0,Time[rt2],r2);
}


if(PlotRS){
ObjectMove("WSO-0",0,Time[st1],s1);
ObjectMove("WRO-0",0,Time[rt1],r1);
}

if(PlotOldTrend){
ObjectMove("Trend DN-1",1,Time[st2],s2);
ObjectMove("Trend DN-1",0,Time[st3],s3);
ObjectMove("Trend DN-2",1,Time[st3],s3);
ObjectMove("Trend DN-2",0,Time[st4],s4);
ObjectMove("Trend DN-3",1,Time[st4],s4);
ObjectMove("Trend DN-3",0,Time[st5],s5);
ObjectMove("Trend DN-4",1,Time[st5],s5);
ObjectMove("Trend DN-4",0,Time[st6],s6);
ObjectMove("Trend UP-1",1,Time[rt2],r2);
ObjectMove("Trend UP-1",0,Time[rt3],r3);
ObjectMove("Trend UP-2",1,Time[rt3],r3);
ObjectMove("Trend UP-2",0,Time[rt4],r4);
ObjectMove("Trend UP-3",1,Time[rt4],r4);
ObjectMove("Trend UP-3",0,Time[rt5],r5);
ObjectMove("Trend UP-4",1,Time[rt5],r5);
ObjectMove("Trend UP-4",0,Time[rt6],r6);
}


if(PlotOldRS){
ObjectMove("WSO-1",0,Time[st2],s2);
ObjectMove("WSO-2",0,Time[st3],s3);
ObjectMove("WSO-3",0,Time[st4],s4);
ObjectMove("WSO-4",0,Time[st5],s5);
ObjectMove("WSO-5",0,Time[st6],s6);
ObjectMove("WRO-1",0,Time[rt2],r2);
ObjectMove("WRO-2",0,Time[rt3],r3);
ObjectMove("WRO-3",0,Time[rt4],r4);
ObjectMove("WRO-4",0,Time[rt5],r5);
ObjectMove("WRO-5",0,Time[rt6],r6);
}

if(PlotProj){

sr_range = r1 - s1 ;

pr1= sr_range*iLevelP1 + r1;
pr1= NormalizeDouble(pr1, Digits) ;
pr2= sr_range*iLevelP2 + r1;
pr2= NormalizeDouble(pr2, Digits) ;

ps1= s1 - sr_range*iLevelP1 ;
ps1= NormalizeDouble(ps1, Digits) ;
ps2= s1 - sr_range*iLevelP2 ;
ps2= NormalizeDouble(ps2, Digits) ;

ObjectMove("PRO+2",0,Time[rt1],pr2);
ObjectMove("PRO+1",0,Time[rt1],pr1);

ObjectMove("PRO-1",0,Time[st1],ps1);
ObjectMove("PRO-2",0,Time[st1],ps2);

// Comment("pr1 ",pr1,"  pr2 ",pr2   ,"  ps1 ",ps1   ,"  ps2 ",   ps2     ) ;
 
 

}


   WindowRedraw();   
   
   return(0);
  }
//+------------------------------------------------------------------+

void DoPlot()
{


if(PlotProj )
{

      if (ObjectFind("PRO+1") != 0)
      {
         ObjectCreate("PRO+1",OBJ_HLINE,0,0,0);
         ObjectSet("PRO+1",OBJPROP_COLOR,ColorProj); 
         ObjectSet("PRO+1",OBJPROP_STYLE,Line_Style);
      }
      
      if (ObjectFind("PRO+2") != 0)
      {      
      ObjectCreate("PRO+2",OBJ_HLINE,0,0,0);
      ObjectSet("PRO+2",OBJPROP_STYLE,Line_Style);
      ObjectSet("PRO+2",OBJPROP_COLOR,ColorProj);
      
      }
      
      
      if (ObjectFind("PRO-1") != 0)
      {      
      ObjectCreate("PRO-1",OBJ_HLINE,0,0,0);
      ObjectSet("PRO-1",OBJPROP_COLOR,ColorProj);
      ObjectSet("PRO11",OBJPROP_STYLE,Line_Style);
      }
      
      
      if (ObjectFind("PRO-2") != 0)
      {       
      ObjectCreate("PRO-2",OBJ_HLINE,0,0,0);
      ObjectSet("PRO-2",OBJPROP_COLOR,ColorProj);
      ObjectSet("PRO-2",OBJPROP_STYLE,Line_Style);     
      }
      
}





   for(cnt=0; cnt<=5; cnt++)
   {
      if (ObjectFind("WSO-"+cnt) != 0)
      {
      ObjectCreate("WSO-"+cnt,OBJ_HLINE,0,0,0);
      ObjectSet("WSO-"+cnt,OBJPROP_COLOR,ColorOldSup);
      ObjectSet("WSO-"+cnt,OBJPROP_STYLE,Line_Style);
      }
      
      if (ObjectFind("WRO-"+cnt) != 0)
      {      
      ObjectCreate("WRO-"+cnt,OBJ_HLINE,0,0,0);
      ObjectSet("WRO-"+cnt,OBJPROP_STYLE,Line_Style);      
      ObjectSet("WRO-"+cnt,OBJPROP_COLOR,ColorOldRes);
      
      }
      
   if(cnt<5)
   {
      if (ObjectFind("Trend DN-"+cnt) != 0)
      {       
      ObjectCreate("Trend DN-"+cnt,OBJ_TREND,0,0,0,0,0);
      ObjectSet("Trend DN-"+cnt,OBJPROP_COLOR,ColorOldTrendDn);
      }
      
      if (ObjectFind("Trend UP-"+cnt) != 0)
      {        
      ObjectCreate("Trend UP-"+cnt,OBJ_TREND,0,0,0,0,0);
      ObjectSet("Trend Up-"+cnt,OBJPROP_COLOR,ColorOldTrendUp);
      }
   }   
   
   } // for
    
    ObjectSet("Trend DN-0",OBJPROP_COLOR,ColorTrendDn);
    ObjectSet("Trend Up-0",OBJPROP_COLOR,ColorTrendUp);
    
    ObjectSet("WRO-0",OBJPROP_COLOR,ColorRes);
    ObjectSet("WSO-0",OBJPROP_COLOR,ColorSup);   


}