Navigation:Home > Content >

3_Level_ZZ_Semafor_volcano.mq4

Time: 2014-01-20 | Download file:3_Level_ZZ_Semafor_volcano.mq4

//+------------------------------------------------------------------+ 
//|                                3_Level_ZZ_Semafor_volcano.mq4    | 
//+------------------------------------------------------------------+ 
#property copyright "asystem2000 + OnTheRoad_for_volcano" 
#property link      "[email protected]" 

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Brown
#property indicator_color2 Chocolate 
#property indicator_color3 Indigo
#property indicator_color4 DeepPink
#property indicator_color5 LawnGreen
#property indicator_color6 Yellow

//---- input parameters 
extern double Period1=5; 
extern double Period2=13; 
extern double Period3=34; 
extern string   Dev_Step_1="1,3";
extern string   Dev_Step_2="8,5";
extern string   Dev_Step_3="13,8";
extern int Symbol_1_Kod=140;
extern int Symbol_2_Kod=141;
extern int Symbol_3_Kod=142;

//---- buffers 
double FP_BuferUp[];
double FP_BuferDn[]; 
double NP_BuferUp[];
double NP_BuferDn[]; 
double HP_BuferUp[];
double HP_BuferDn[];

double aux_buf_up[1000];
double aux_buf_dn[1000];


string indi_name = "3_Level_ZZ_Semafor";

int F_Period;
int N_Period;
int H_Period;
int Dev1;
int Stp1;
int Dev2;
int Stp2;
int Dev3;
int Stp3;

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  { 
// --------- Корректируем периоды для построения ЗигЗагов
   if (Period1>0) F_Period=MathCeil(Period1*Period()); else F_Period=0; 
   if (Period2>0) N_Period=MathCeil(Period2*Period()); else N_Period=0; 
   if (Period3>0) H_Period=MathCeil(Period3*Period()); else H_Period=0; 
   
//---- Обрабатываем 1 буфер 
   if (Period1>0)
   {
   SetIndexStyle(0,DRAW_LINE,0,1); 
   SetIndexBuffer(0,FP_BuferUp); 
   SetIndexEmptyValue(0,0.0); 
   
   SetIndexStyle(1,DRAW_LINE,0,1); 
   SetIndexBuffer(1,FP_BuferDn); 
   SetIndexEmptyValue(1,0.0); 
   }
   
//---- Обрабатываем 2 буфер 
   if (Period2>0)
   {
   SetIndexStyle(2,DRAW_LINE,0,2); 
   SetIndexBuffer(2,NP_BuferUp); 
   SetIndexEmptyValue(2,0.0); 
   
   SetIndexStyle(3,DRAW_LINE,0,2); 
   SetIndexBuffer(3,NP_BuferDn); 
   SetIndexEmptyValue(3,0.0); 
   }
//---- Обрабатываем 3 буфер 
   if (Period3>0)
   {
   SetIndexStyle(4,DRAW_LINE,0,4); 
   SetIndexBuffer(4,HP_BuferUp); 
   SetIndexEmptyValue(4,0.0); 

   SetIndexStyle(5,DRAW_LINE,0,4); 
   SetIndexBuffer(5,HP_BuferDn); 
   SetIndexEmptyValue(5,0.0); 
   }
// Обрабатываем значения девиаций и шагов
   int CDev=0;
   int CSt=0;
   int Mass[]; 
   int C=0;  
   if (IntFromStr(Dev_Step_1,C, Mass)==1) 
      {
        Stp1=Mass[1];
        Dev1=Mass[0];
      }
   
   if (IntFromStr(Dev_Step_2,C, Mass)==1)
      {
        Stp2=Mass[1];
        Dev2=Mass[0];
      }      
   
   
   if (IntFromStr(Dev_Step_3,C, Mass)==1)
      {
        Stp3=Mass[1];
        Dev3=Mass[0];
      }      
   return(0); 
  } 
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
  { 
//---- 
    
//---- 
   return(0); 
  } 

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start() 
  {
  
   int    i, j , upptr , dnptr , near , far , counted_bars=IndicatorCounted();

//----
   if ( counted_bars > 0 ) counted_bars -- ;
   
   i=Bars-counted_bars;
  
 while ( i >= 0 )
   {
   if (Period1>0) //CountZZ(FP_BuferUp,FP_BuferDn,Period1,Dev1,Stp1);
      {
      for ( j = 0 ; j < 1000 ; j ++ ) {  aux_buf_up[ j ] = 
         iCustom(NULL,0,indi_name,
         Period1,
         Period2,
         Period3,
         Dev_Step_1,
         Dev_Step_2,
         Dev_Step_3,
         Symbol_1_Kod,
         Symbol_2_Kod,
         Symbol_3_Kod,
         0,j+i);
         if ( aux_buf_up[ j ] != 0 ) break ;
         }
      upptr = j ;
         
      for ( j = 0 ; j < 1000 ; j ++ ) {  aux_buf_dn[ j ] = 
         iCustom(NULL,0,indi_name,
         Period1,
         Period2,
         Period3,
         Dev_Step_1,
         Dev_Step_2,
         Dev_Step_3,
         Symbol_1_Kod,
         Symbol_2_Kod,
         Symbol_3_Kod,
         1,j+i);
         if ( aux_buf_dn[ j ] != 0 ) break ;
         }
      dnptr = j ;
         
      if (( upptr != 1000-1 ) && ( dnptr != 1000-1 ))
         {
         //near , far ;
         if ( upptr > dnptr )
            {
            near = dnptr;
            far = upptr;

            FP_BuferUp[i+near] = 0;
            for ( j = 1 ; j <= near ; j ++ ) FP_BuferUp[ i+near - j ] = 0 ;
            
            FP_BuferDn[i+near] = Volume[i+near] ; // * ( Close[ i+near ] - Open[ i+near ] );
            for ( j = 1 ; j <= near ; j ++ ) FP_BuferDn[ i+near - j ] = FP_BuferDn[ i+near+1 - j ] + Volume[i+near - j] ; // * ( Close[ i+near - j ] - Open[ i+near - j ] );
            //for ( j = 0 ; j <= near ; j ++ ) FP_BuferDn[ i+near - j ] *= ( High[ i+near - j ] - Low[ i+near ] ) ;
            }
         else if ( upptr < dnptr )
            {
            far = dnptr;
            near = upptr;

            FP_BuferDn[i+near] = 0;
            for ( j = 1 ; j <= near ; j ++ ) FP_BuferDn[ i+near - j ] = 0 ;
            
            FP_BuferUp[i+near] = Volume[i+near] ; // * ( Close[ i+near ] - Open[ i+near ] );
            for ( j = 1 ; j <= near ; j ++ ) FP_BuferUp[ i+near - j ] = FP_BuferUp[ i+near+1 - j ] + Volume[i+near - j] ; // * ( Close[ i+near-j ] - Open[ i+near-j ] ) ;
            //for ( j = 0 ; j <= near ; j ++ ) FP_BuferUp[ i+near - j ] *= ( Low[ i+near - j ] - High[ i+near ] ) ;
            }
         /*
         FP_BuferUp[i+upptr] = Volume[i+upptr];
         for ( j = 1 ; j <= upptr ; j ++ ) FP_BuferUp[ i+upptr - j ] = FP_BuferUp[ i+upptr+1 - j ] + Volume[i+upptr - j] ;
         FP_BuferDn[i+dnptr] = Volume[i+dnptr];
         for ( j = 1 ; j <= dnptr ; j ++ ) FP_BuferDn[ i+dnptr - j ] = FP_BuferDn[ i+dnptr+1 - j ] + Volume[i+dnptr - j] ;
         */
         }
      }
      
   if (Period2>0) // CountZZ(NP_BuferUp,NP_BuferDn,Period2,Dev2,Stp2);
      {
      for ( j = 0 ; j < 1000 ; j ++ ) {  aux_buf_up[ j ] = 
         iCustom(NULL,0,indi_name,
         Period1,
         Period2,
         Period3,
         Dev_Step_1,
         Dev_Step_2,
         Dev_Step_3,
         Symbol_1_Kod,
         Symbol_2_Kod,
         Symbol_3_Kod,
         2,j+i);
         if ( aux_buf_up[ j ] != 0 ) break ;
         }
      upptr = j ;
         
      for ( j = 0 ; j < 1000 ; j ++ ) {  aux_buf_dn[ j ] = 
         iCustom(NULL,0,indi_name,
         Period1,
         Period2,
         Period3,
         Dev_Step_1,
         Dev_Step_2,
         Dev_Step_3,
         Symbol_1_Kod,
         Symbol_2_Kod,
         Symbol_3_Kod,
         3,j+i);
         if ( aux_buf_dn[ j ] != 0 ) break ;
         }
      dnptr = j ;
         
      if (( upptr != 1000-1 ) && ( dnptr != 1000-1 ))
         {
         //near , far ;
         if ( upptr > dnptr )
            {
            near = dnptr;
            far = upptr;

            NP_BuferUp[i+near] = 0;
            for ( j = 1 ; j <= near ; j ++ ) NP_BuferUp[ i+near - j ] = 0 ;
            
            NP_BuferDn[i+near] = Volume[i+near] ; // * ( Close[ i+near ] - Open[ i+near ] );
            for ( j = 1 ; j <= near ; j ++ ) NP_BuferDn[ i+near - j ] = NP_BuferDn[ i+near+1 - j ] + Volume[i+near - j] ; // * ( Close[ i+near - j ] - Open[ i+near - j ] );
            //for ( j = 0 ; j <= near ; j ++ ) NP_BuferDn[ i+near - j ] *= ( High[ i+near - j ] - Low[ i+near ] ) ;
            }
         else if ( upptr < dnptr )
            {
            far = dnptr;
            near = upptr;

            NP_BuferDn[i+near] = 0;
            for ( j = 1 ; j <= near ; j ++ ) NP_BuferDn[ i+near - j ] = 0 ;
            
            NP_BuferUp[i+near] = Volume[i+near] ; // * ( Close[ i+near ] - Open[ i+near ] );
            for ( j = 1 ; j <= near ; j ++ ) NP_BuferUp[ i+near - j ] = NP_BuferUp[ i+near+1 - j ] + Volume[i+near - j] ; // * ( Close[ i+near-j ] - Open[ i+near-j ] ) ;
            //for ( j = 0 ; j <= near ; j ++ ) NP_BuferUp[ i+near - j ] *= ( Low[ i+near - j ] - High[ i+near ] ) ;
            }
         /*
         NP_BuferUp[i+upptr] = Volume[i+upptr];
         for ( j = 1 ; j <= upptr ; j ++ ) NP_BuferUp[ i+upptr - j ] = NP_BuferUp[ i+upptr+1 - j ] + Volume[i+upptr - j] ;
         NP_BuferDn[i+dnptr] = Volume[i+dnptr];
         for ( j = 1 ; j <= dnptr ; j ++ ) NP_BuferDn[ i+dnptr - j ] = NP_BuferDn[ i+dnptr+1 - j ] + Volume[i+dnptr - j] ;
         */
         }
      }
   
   if (Period3>0) // CountZZ(HP_BuferUp,HP_BuferDn,Period3,Dev3,Stp3);
      {
      for ( j = 0 ; j < 1000 ; j ++ ) {  aux_buf_up[ j ] = 
         iCustom(NULL,0,indi_name,
         Period1,
         Period2,
         Period3,
         Dev_Step_1,
         Dev_Step_2,
         Dev_Step_3,
         Symbol_1_Kod,
         Symbol_2_Kod,
         Symbol_3_Kod,
         4,j+i);
         if ( aux_buf_up[ j ] != 0 ) break ;
         }
      upptr = j ;
         
      for ( j = 0 ; j < 1000 ; j ++ ) {  aux_buf_dn[ j ] = 
         iCustom(NULL,0,indi_name,
         Period1,
         Period2,
         Period3,
         Dev_Step_1,
         Dev_Step_2,
         Dev_Step_3,
         Symbol_1_Kod,
         Symbol_2_Kod,
         Symbol_3_Kod,
         5,j+i);
         if ( aux_buf_dn[ j ] != 0 ) break ;
         }
      dnptr = j ;
         
      if (( upptr != 1000-1 ) && ( dnptr != 1000-1 ))
         {
         //near , far ;
         if ( upptr > dnptr )
            {
            near = dnptr;
            far = upptr;

            HP_BuferUp[i+near] = 0;
            for ( j = 1 ; j <= near ; j ++ ) HP_BuferUp[ i+near - j ] = 0 ;
            
            HP_BuferDn[i+near] = Volume[i+near] ; // * ( Close[ i+near ] - Open[ i+near ] ) ;
            for ( j = 1 ; j <= near ; j ++ ) HP_BuferDn[ i+near - j ] = HP_BuferDn[ i+near+1 - j ] + Volume[i+near - j] ; // * ( Close[ i+near - j ] - Open[ i+near - j ] ) ;
            //for ( j = 0 ; j <= near ; j ++ ) HP_BuferDn[ i+near - j ] *= ( High[ i+near - j ] - Low[ i+near ] ) ;
            }
         else if ( upptr < dnptr )
            {
            far = dnptr;
            near = upptr;

            HP_BuferDn[i+near] = 0;
            for ( j = 1 ; j <= near ; j ++ ) HP_BuferDn[ i+near - j ] = 0 ;
            
            HP_BuferUp[i+near] = Volume[i+near] ; // * ( Close[ i+near ] - Open[ i+near ] ) ;
            for ( j = 1 ; j <= near ; j ++ ) HP_BuferUp[ i+near - j ] = HP_BuferUp[ i+near+1 - j ] + Volume[i+near - j] ; // * ( Close[ i+near-j ] - Open[ i+near-j ] ) ;
            //for ( j = 0 ; j <= near ; j ++ ) HP_BuferUp[ i+near - j ] *= ( Low[ i+near - j ] - High[ i+near ] ) ;
            }
         /*
         HP_BuferUp[i+upptr] = Volume[i+upptr];
         for ( j = 1 ; j <= upptr ; j ++ ) HP_BuferUp[ i+upptr - j ] = HP_BuferUp[ i+upptr+1 - j ] + Volume[i+upptr - j] ;
         HP_BuferDn[i+dnptr] = Volume[i+dnptr];
         for ( j = 1 ; j <= dnptr ; j ++ ) HP_BuferDn[ i+dnptr - j ] = HP_BuferDn[ i+dnptr+1 - j ] + Volume[i+dnptr - j] ;
         */
         }
      }
   
   i -- ;
   }
   
   return(0); 
  } 
//+------------------------------------------------------------------+ 
// дополнительные функции
//int Take


  
int Str2Massive(string VStr, int& M_Count, int& VMass[])
  {
    int val=StrToInteger( VStr);
    if (val>0)
       {
         M_Count++;
         int mc=ArrayResize(VMass,M_Count);
         if (mc==0)return(-1);
          VMass[M_Count-1]=val;
         return(1);
       }
    else return(0);    
  } 
  
  
int IntFromStr(string ValStr,int& M_Count, int& VMass[])
  {
    
    if (StringLen(ValStr)==0) return(-1);
    string SS=ValStr;
    int NP=0; 
    string CS;
    M_Count=0;
    ArrayResize(VMass,M_Count);
    while (StringLen(SS)>0)
      {
            NP=StringFind(SS,",");
            if (NP>0)
               {
                 CS=StringSubstr(SS,0,NP);
                 SS=StringSubstr(SS,NP+1,StringLen(SS));  
               }
               else
               {
                 if (StringLen(SS)>0)
                    {
                      CS=SS;
                      SS="";
                    }
               }
            if (Str2Massive(CS,M_Count,VMass)==0) 
               {
                 return(-2);
               }
      }
    return(1);    
  }

Recommend