Navigation:Home > Content >

CTG-Structure-x.mq4

Time: 2018-08-18 | Download file:CTG-Structure-x.mq4

//+------------------------------------------------------------------+
//|                                              CTG-Structure-x.mq4 |
//|                                                CompanyName "CTG" |
//|                                     http://chaostradinggroup.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, ChaosTradingGroup.com"
#property link      "http://ChaosTradingGroup.com"

#property indicator_chart_window
#property indicator_buffers 8

#property indicator_color1 Red
#property indicator_color2 Orange
#property indicator_color3 Yellow
#property indicator_color4 Green
#property indicator_color5 DeepSkyBlue
#property indicator_color6 LimeGreen
#property indicator_color7 DeepSkyBlue
#property indicator_color8 Violet
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  2
#property  indicator_width4  2
#property  indicator_width5  2
#property  indicator_width6  2
#property  indicator_width7  2
#property  indicator_width8  2



//---- indicator parameters

extern double k3=0.8;
extern double eq=2.1;
extern int xdist=55;
extern int r1=32;
extern int Bars1=610;
extern int Color1=1;


//---- indicator buffers
double ExtBullBuffer[];
double ExtBull1Buffer[];
double ExtBull2Buffer[];
double ExtBull3Buffer[];
double ExtBull4Buffer[];
double ExtBull5Buffer[];
double ExtBull6Buffer[];
double ExtBull7Buffer[];


//----
int Period1=1,r1z,ExtCountedBars=0,m1,masZ,sk,m2,m3,m4,m5,st,kjk,kjk1,s,r,mn,s2,tal,tal1,tal2,tal3,tal4,limit,we,map,mas,map1,mas1,ue=0,force=0,Period1z,az10,l1,l10,l20,MA_Period,sd1,df,r2,k,a1,a2,wq,z,s1,m=0,o,e,a7,q,d,w1,w2,rs,rs1,az=0,az2;
double a=0,Bull,Bull1,Bull2,Bear8,Bear9,y2,ty2,n10,koef,bars2,red,ty,ty1,y1,forceK,razmer,rem=0,n20,Bull3,Bull4,Bull0,w0,Bull5,Bull6,Bear,Bear1,Bear2,Bear3,Bear31,Bear4,Bear5,Bear6,Bear7,l,k1,n1,n2,z1,z2,oblmin,oblmax;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,EMPTY, 2,C'255,128,128' );
   SetIndexStyle(1,DRAW_LINE,EMPTY, 2,C'255,179,94' );
   SetIndexStyle(2,DRAW_LINE,EMPTY, 2,C'255,236,157');
   SetIndexStyle(3,DRAW_LINE,EMPTY, 2,C'156,255,132' );
   SetIndexStyle(4,DRAW_HISTOGRAM,EMPTY, 2, PaleTurquoise);
   SetIndexStyle(5,DRAW_LINE,EMPTY, 2,PaleGreen );
if (Color1==1)SetIndexStyle(5,DRAW_NONE);   
   SetIndexStyle(6,DRAW_LINE,EMPTY, 2,DeepSkyBlue);
   SetIndexStyle(7,DRAW_ARROW,EMPTY, 2,C'255,121,255');
   
   
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexEmptyValue(5,0.0);
   SetIndexEmptyValue(6,0.0);
   SetIndexEmptyValue(7,0.0);
   SetIndexArrow(7,172);



   SetIndexShift(0,xdist*Period1);
   SetIndexDrawBegin(0,xdist*Period1+MA_Period);
   SetIndexShift(1,xdist*Period1);
   SetIndexDrawBegin(1,xdist*Period1+MA_Period);
    SetIndexShift(2,xdist*Period1);
   SetIndexDrawBegin(2,xdist*Period1+MA_Period);
   SetIndexShift(3,xdist*Period1);
   SetIndexDrawBegin(3,xdist*Period1+MA_Period);
   SetIndexShift(4,xdist*Period1);
   SetIndexDrawBegin(4,xdist*Period1+MA_Period);
   SetIndexShift(5,xdist*Period1);
   SetIndexDrawBegin(5,xdist*Period1+MA_Period);
   SetIndexShift(6,xdist*Period1);
   SetIndexDrawBegin(6,xdist*Period1+MA_Period);
   SetIndexShift(7,xdist*Period1);
   SetIndexDrawBegin(7,xdist*Period1+MA_Period); 

  
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

 
   IndicatorShortName("Strukture-x");
   SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtBullBuffer);
   SetIndexBuffer(1,ExtBull1Buffer);   
   SetIndexBuffer(2,ExtBull2Buffer); 
   SetIndexBuffer(3,ExtBull3Buffer);   
   SetIndexBuffer(4,ExtBull4Buffer);   
   SetIndexBuffer(5,ExtBull5Buffer); 
   SetIndexBuffer(6,ExtBull6Buffer);
   SetIndexBuffer(7,ExtBull7Buffer); 

   SetIndexLabel(0,NULL);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,"Strukture"); 
   SetIndexLabel(5,"Strukture");     
   SetIndexLabel(6,NULL);
   SetIndexLabel(7,"Center"); 
       
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
  
if (Bars1>Bars)Bars1=Bars;


if ( a!=Close[1])
{
a=Close[1];
go();
}

return(0);
}




void go()
{
for(r=1;r<=Bars; r++)
{
ExtBullBuffer[r]=0;
ExtBull1Buffer[r]=0;
ExtBull2Buffer[r]=0;
ExtBull3Buffer[r]=0;
ExtBull4Buffer[r]=0;
ExtBull5Buffer[r]=0;
ExtBull6Buffer[r]=0;
ExtBull7Buffer[r]=0;
}

m=0;
for(r=r1;r<=Bars1; r++)
{
mn=0;
f1();// ищим центры зарусаливания
if (mn==1)f2();
if (m>=5){break;}
}
if (m!=0) f3();
}






void f1()
{
  s1=0;
  k1=0;
  z=0;
  z1=0;
  
for(s=r; s>=0; s--)
{
lolka();
if (Bear>Bear2 && Bull>Bull4 )k1+=1;    
if (Bear<=Bear2 && Bull<=Bull4)k1+=1;
if (k1>=l*k3 && l >= r1 ) {z=1;s1=s;}
if (k1= r1 )break;
}
  
if (z==1)
   {
   z1=0;
   s2=Bars;
   for(s=s1; s>=0; s--)
   {
   lolka();
   if (Bear>Bear2 && Bull>Bull4 )k1+=1;    
   if (Bear<=Bear2 && Bull<=Bull4)k1+=1;
   if (k1>=l*k3){s2=s;z1=1;}
   }
   }

if (z1==1)
   {
   masZ=(r-s2)/(eq*2);
   if (masZ<1) masZ=1;
   if (masZ>72) masZ=72;
   }


if (s2<=masZ+1 && z1==1) 
   {
   
   kjk=0;
   kjk1=0;
   ExtBull4Buffer[r+xdist*Period1]=l/k1;
   for(st=r+xdist*Period1-1; st>=r+xdist*Period1-5; st--)
      {
      if (ExtBull7Buffer[st]!=0)
         {
         kjk1=1;
         if (ExtBull4Buffer[r+xdist*Period1]>ExtBull4Buffer[st]){kjk=1;eraiser();}
         }
      
      }
   if (kjk1==0)
   {
   m=m+1;
   mn=1;
   }
   if (kjk1==1 && kjk==1)
   {
   mn=1;
   }   

   }
}

void f2()
{

if (m==1)
{
      s=r;
      y1=0;
      lolka();
      ExtBull7Buffer[s+xdist*Period1]=Bear;
      for(s=r+xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBullBuffer[s]=Bear3;
      
      if (Color1==1)
         {
            if (s==xdist*Period1)
               {ExtBull4Buffer[s]=Bear5+y1;
                ExtBull5Buffer[s]=Bear4+y1;
               }         
          loles();  
         }
      }
}
      
if (m==2)
{
      s=r;
      y1=0;
      lolka();
      ExtBull7Buffer[s+xdist*Period1]=Bear;
      for(s=r+xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull1Buffer[s]=Bear3;
      
      if (Color1==1)
         {
         loles();
         }
      }
}     
    

if (m==3)
{
      s=r;
      lolka();
      ExtBull7Buffer[s+xdist*Period1]=Bear;
      for(s=r+xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull2Buffer[s]=Bear3;
      if (Color1==1)
         {
         loles();
         }
      }
}      
if (m==4)
{
      s=r;
      lolka();
      ExtBull7Buffer[s+xdist*Period1]=Bear;
      for(s=r+xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull3Buffer[s]=Bear3;
      if (Color1==1)
         {
         loles();
         }
      }
}      
if (m==5)
{
      s=r;
      lolka();
      ExtBull7Buffer[s+xdist*Period1]=Bear;
      for(s=r+xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull6Buffer[s]=Bear3;
      if (Color1==1)
         {
         loles();
         }     
      }
}

}  

void f3()
{
for(s=xdist*Period1; s<=Bars1; s++)ExtBull4Buffer[s]=0;
      

if (Color1==0)
{
if (m==1)
{
      ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
      ty1=ExtBullBuffer[1+xdist*Period1];
      y1=ty-ty1;
      
      for(s=xdist*Period1; s>=1; s--)
      {
      ExtBull5Buffer[s]=ExtBullBuffer[s]+y1;
      }
}

if (m==2)
{

      ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
      ty1=(ExtBullBuffer[1+xdist*Period1]+ExtBull1Buffer[1+xdist*Period1])/2;
      y1=ty-ty1;
      
      for(s=xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull5Buffer[s]=(ExtBullBuffer[s]+ExtBull1Buffer[s])/2+y1;
      }
}
      
if (m==3)
{

      ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
      ty1=(ExtBullBuffer[1+xdist*Period1]+ExtBull1Buffer[1+xdist*Period1]+ExtBull2Buffer[1+xdist*Period1])/3;
      y1=ty-ty1;
      
      for(s=xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull5Buffer[s]=(ExtBullBuffer[s]+ExtBull1Buffer[s]+ExtBull2Buffer[1+xdist*Period1])/3+y1;
      }
}
      
if (m==4)
{

      ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
      ty1=(ExtBullBuffer[1+xdist*Period1]+ExtBull1Buffer[1+xdist*Period1]+ExtBull2Buffer[1+xdist*Period1]+ExtBull3Buffer[1+xdist*Period1])/4;
      y1=ty-ty1;
      
      for(s=xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull5Buffer[s]=(ExtBullBuffer[s]+ExtBull1Buffer[s]+ExtBull2Buffer[1+xdist*Period1]+ExtBull3Buffer[1+xdist*Period1])/4+y1;
      }
}
      
if (m==5)
{

      ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
      ty1=(ExtBullBuffer[1+xdist*Period1]+ExtBull1Buffer[1+xdist*Period1]+ExtBull2Buffer[1+xdist*Period1]+ExtBull3Buffer[1+xdist*Period1]+ExtBull6Buffer[1+xdist*Period1])/5;
      y1=ty-ty1;
      
      for(s=xdist*Period1; s>=1; s--)
      {
      lolka();
      ExtBull5Buffer[s]=(ExtBullBuffer[s]+ExtBull1Buffer[s]+ExtBull2Buffer[1+xdist*Period1]+ExtBull3Buffer[1+xdist*Period1]+ExtBull6Buffer[1+xdist*Period1])/5+y1;
      }
}
            

}

if (Color1==1)
{
if (m==2)
{
      for(s=xdist*Period1; s>=1; s--)
      {
      ExtBull4Buffer[s]=ExtBull4Buffer[s]/2;
      ExtBull5Buffer[s]=ExtBull5Buffer[s]/2;
      }
}

if (m==3)
{
      
     
      for(s=xdist*Period1; s>=1; s--)
      {
      ExtBull4Buffer[s]=ExtBull4Buffer[s]/3;
      ExtBull5Buffer[s]=ExtBull5Buffer[s]/3;
      }
}      

if (m==4)
{
     
      for(s=xdist*Period1; s>=1; s--)
      {
      ExtBull4Buffer[s]=ExtBull4Buffer[s]/4;
      ExtBull5Buffer[s]=ExtBull5Buffer[s]/4;
      }
}
            
if (m==5)
{
     
      for(s=xdist*Period1; s>=1; s--)
      {
      ExtBull4Buffer[s]=ExtBull4Buffer[s]/5;
      ExtBull5Buffer[s]=ExtBull5Buffer[s]/5;
      }
}
}




}
void lolka()
{
map=(r-s)/eq;
if (map<2) map=2;
if (map>144) map=144;
mas=map/2; 
map1=(r-s+1)/eq;
if (map1<2) map1=2;
 if (map1>144) map1=144;
mas1=map1/2;

Bull=iMA(NULL,0,map,1-mas,0,4,s);
Bull4=iMA(NULL,0,map1,1-mas1,0,4,s+1);

Bear=iMA(NULL,0,2,0,0,4,r)*2-iMA(NULL,0,map,1-mas,0,4,r*2-s);
Bear2=iMA(NULL,0,2,0,0,4,r)*2-iMA(NULL,0,map1,1-mas1,0,4,r*2-s-1);

Bear3=iMA(NULL,0,2,0,0,4,r)*2-iMA(NULL,0,map1,1-mas1,0,4,r*2-s+xdist*Period1);
Bear4=iMA(NULL,0,2,0,0,4,r)*2-iHigh(NULL,0,r*2-s+xdist*Period1);
Bear5=iMA(NULL,0,2,0,0,4,r)*2-iLow(NULL,0,r*2-s+xdist*Period1);
Bear6=iMA(NULL,0,2,0,0,4,r)*2-((iHigh(NULL,0,r*2-s+xdist*Period1)-iLow(NULL,0,r*2-s+xdist*Period1))/2+iLow(NULL,0,r*2-s+xdist*Period1));
Bear7=iMA(NULL,0,2,0,0,4,r1z)*2-((iHigh(NULL,0,r1z*2-s+xdist*Period1)-iLow(NULL,0,r1z*2-s+xdist*Period1))/2+iLow(NULL,0,r1z*2-s+xdist*Period1));
Bear8=iMA(NULL,0,2,0,0,4,r1z)*2-iHigh(NULL,0,r1z*2-s1+xdist*Period1);
Bear9=iMA(NULL,0,2,0,0,4,r1z)*2-iLow(NULL,0,r1z*2-s1+xdist*Period1);

l=r-s;


}


void loles()
{
if (s==xdist*Period1)
   {
   ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
   ty1=Bear6;
   y1=ty-ty1;
   }     
if (s <= xdist*Period1)
   {
   ExtBull4Buffer[s]+=Bear5+y1;
   ExtBull5Buffer[s]+=Bear4+y1;
   }

}

void eraiser()
{
ExtBull7Buffer[st]=0;
r1z=st; 
s=xdist*Period1;
lolka();
ty=(iHigh(NULL,0,1)-iLow(NULL,0,1))/2+iLow(NULL,0,1);
ty1=Bear7;
y2=ty-ty1;
for(s1=xdist*Period1; s1>=1; s1--)
{
lolka();
ExtBull4Buffer[s1]-=(Bear9+y2);
ExtBull5Buffer[s1]-=(Bear8+y2);
}
         

}

Recommend