//+------------------------------------------------------------------+
//|                                                   HaosVisual.mq4 |
//|                                              Converted by mrslav |
//+------------------------------------------------------------------+
#property copyright " Copyright © 2006, HomeSoft Corp."
#property link      " spiky@transkeino.ru"

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 DarkGoldenrod
#property indicator_width1 1
#property indicator_color2 Lime
#property indicator_color3 Coral
#property indicator_width3 2
#property indicator_color4 Coral
#property indicator_width4 2
#property indicator_color5 Lime
#property indicator_width5 2
#property indicator_color6 Lime
#property indicator_width6 2
#property indicator_color7 DodgerBlue
#property indicator_maximum 50
#property indicator_minimum -50

extern string WPR1        = "*** WPR1 ***";
extern int    t3_period   = 8;
extern double b           = 0.7;
extern int    per         = 14;
extern int    psel        = 30;
extern int    pbuy        = -30;
extern string WPR2        = "*** WPR2 ***";
extern int    t3_period_2 = 8;
extern double b_2         = 0.7;
extern int    per_2       = 96;
extern int    psel_2      = 40;
extern int    pbuy_2      = -40;
extern int    mBar        = 500;
bool          ft          = true;

double Buffer1[],Buffer2[],e1,e2,e3,e4,e5,e6,c1,c2,c3,c4,n,w1,w2,b2,b3,dpo,t3,wpr,trig,
       qe1,qe2,qe3,qe4,qe5,qe6,qc1,qc2,qc3,qc4,qn,qw1,qw2,qb2,qb3,qdpo,qt3,qwpr,qtrig;
double Dn2[];
double Dn1[];
double Mid[];
double Up1[];
double Up2[];
int    i;
//+------------------------------------------------------------------+
int init() {
   IndicatorShortName("Haos Visual");
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,Buffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(1,Buffer2);
   SetIndexEmptyValue(1,0.0);
   SetLevelValue(0,psel_2);
   SetLevelValue(1,psel);
   SetLevelValue(2,0);
   SetLevelValue(3,pbuy);
   SetLevelValue(4,pbuy_2);
   SetLevelStyle(2,0,DimGray);
   SetIndexLabel(0,"Быстрая очень линия");
   SetIndexLabel(1,"Совсем медленный ВПР");
   SetIndexLabel(3,"Продавай срочно");
   SetIndexLabel(2,"Покупай уже");
   SetIndexLabel(4,"Сильны медведи");
   SetIndexLabel(5,"Быки рвут всех");
   
   
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(6,DRAW_HISTOGRAM,STYLE_SOLID);
   
   SetIndexBuffer(2,Up1);
   SetIndexBuffer(3,Dn1);
   SetIndexBuffer(4,Up2);
   SetIndexBuffer(5,Dn2);
   SetIndexBuffer(6,Mid); 
   return(0); }
//+------------------------------------------------------------------+
int start() {

   if(ft) { b2=b*b; b3=b2*b; c1=-b3; c2=(3*(b2+b3)); c3=-3*(2*b2+b+b3); c4=(1+3*b+b3+3*b2); n=t3_period;
            qb2=b_2*b_2; qb3=qb2*b_2; qc1=-qb3; qc2=(3*(qb2+qb3)); qc3=-3*(2*qb2+b_2+qb3); qc4=(1+3*b_2+qb3+3*qb2); qn=t3_period_2;
   if(n<1) n=1; n=1+0.5*(n-1); w1=2/(n+1); w2=1-w1;
   if(qn<1) qn=1; qn=1+0.5*(qn-1); qw1=2/(qn+1); qw2=1-qw1; ft=false; } 
//+------------------------------------------------------------------+
   for(i=mBar; i>=0; i--) { 
   wpr=iWPR(NULL,0,per,i);
   qwpr=iWPR(NULL,0,per_2,i);

   e1=w1*wpr+w2*e1; e2=w1*e1+w2*e2; e3=w1*e2+w2*e3; e4=w1*e3+w2*e4; e5=w1*e4+w2*e5; e6=w1*e5+w2*e6;
   t3=c1*e6+c2*e5+c3*e4+c4*e3+50;
   Buffer1[i]=t3;
   
   qe1=qw1*qwpr+qw2*qe1; qe2=qw1*qe1+qw2*qe2; qe3=qw1*qe2+qw2*qe3; qe4=qw1*qe3+qw2*qe4; qe5=qw1*qe4+qw2*qe5; qe6=qw1*qe5+qw2*qe6;
   qt3=qc1*qe6+qc2*qe5+qc3*qe4+qc4*qe3+50;
   Buffer2[i]=qt3;
   
   if (t3>psel && qt3>psel_2) {
       Dn2[i]=qt3;
	    Up2[i]=0; 
	    Dn1[i]=0;
	    Up1[i]=0;
	    Mid[i]=0;
      }
      else if (t3<=psel && qt3>psel_2) {
	    Dn1[i]=qt3;
	    Up2[i]=0; 
	    Dn2[i]=0;
	    Up1[i]=0;
	    Mid[i]=0;
	    }
	   else  if (t3<pbuy && qt3<pbuy_2) {
	    Up2[i]=qt3;
	    Dn2[i]=0; 
	    Dn1[i]=0;
	    Up1[i]=0;
	    Mid[i]=0;
      }
	   else if (t3>=pbuy && qt3<pbuy_2) 
	    {
	    Up1[i]=qt3;
	    Up2[i]=0; 
	    Dn1[i]=0;
	    Dn2[i]=0;
	    Mid[i]=0;
	    }
	    else 
	    {
	    Mid[i]=qt3;
	    Up2[i]=0; 
	    Dn1[i]=0;
	    Up1[i]=0;
	    Dn2[i]=0;
	    }
   
   }
   
   
   
   return(0); }
//+------------------------------------------------------------------+