//[i]J_TPO 
// 这个是双向震荡器 使用 J_TPO. 
// 它使用两个明显的时间量程. If both are positive that is a trend buy, 
// if both are negative a trend sell, and mixed, neutral. 
#property indicator_separate_window 
#property indicator_buffers 4 
#property indicator_color1 Green 
#property indicator_color2 Yellow 
#property indicator_color3 Blue 
#property indicator_color4 Red 
#property indicator_maximum 100 
#property indicator_minimum -100 
extern int LenShort =  23;                                        //空长度 
extern int LenLong =  39;                                         //多长度 
double ExtMapBuffer1[];                                              //数组1 
double ExtMapBuffer2[];                                              //数组2 
double ExtMapBuffer3[];                                              //数组3 
double ExtMapBuffer4[];                                              //数组4 
//+------------------------初始化------------------------------------+ 
int init() 
  { 
   SetIndexStyle(0,DRAW_LINE); 
   SetIndexBuffer(0, ExtMapBuffer1); 
   SetIndexStyle(1,DRAW_LINE); 
   SetIndexBuffer(1, ExtMapBuffer2); 
   SetIndexStyle(2,DRAW_HISTOGRAM); 
   SetIndexBuffer(2, ExtMapBuffer3); 
   SetIndexStyle(3,DRAW_HISTOGRAM); 
   SetIndexBuffer(3, ExtMapBuffer4); 
   return(0); 
  } 
//+--------------------------主函数----------------------------------+ 
int start() 
  { 
   int limit; 
   int counted_bars= IndicatorCounted(); 
   if(counted_bars 
      return(-1); 
   if(counted_bars>0) 
      counted_bars--; 
   limit= MathMin(Bars-counted_bars+1,Bars-LenLong-1); 
   if((LenLong 
      Print("J_TPO_CD:  长度至少为3"); 
      return(0);                                
     } 
   double sqrtLenShort= MathSqrt(LenShort+0.0);                       //空开方(空长度) 
   double sqrtLenLong= MathSqrt(LenLong+0.0);                         //多开方(多长度) 
   for(int i= limit; i>= 0; i--){ 
      double J1, J2, diff; 
      J1= J_TPO_value(Close, LenShort,i);                             //J1为 调用子函数值 
      J2= J_TPO_value(Close, LenLong,i); 
      ExtMapBuffer1[i]=  J1*100.0;                                    //数组1为  
      ExtMapBuffer2[i]=  J2*100.0; 
      if(J1*J2 >=  0.0){  
         // same sign. 
         if(J1 > 0.0){                                            //若 
            ExtMapBuffer3[i]= 50.0;                                  //数组3为50 
            ExtMapBuffer4[i]= 0.0; 
            } 
         else  
         if(J1 
            ExtMapBuffer3[i]= 0.0;                                //数组3为 0 
            ExtMapBuffer4[i]= -50.0; 
           } 
        } 
      else{                                                      //否则 
         ExtMapBuffer3[i]= 0.0;                                      //数组3和4都 为0 
         ExtMapBuffer4[i]= 0.0; 
        } 
     } 
   return(0); 
  } 
//+------------------------------------------------------------------+ 
double J_TPO_value(double 用价[], int 指定跨期, int shift)  
  { 
   double 指标值; 
   double 因子; 
   double Lenp1half; 
   double accum; 
   double 临时容器; 
   double 最大值; 
   int    j; 
   int    最大时; 
   double 数组1[]; 
   double 数组2[]; 
   double 数组3[]; 
   bool   flag; 
   accum= 0; 
   //-- 
   ArrayResize(数组1,指定跨期+1); 
   ArrayResize(数组2,指定跨期+1); 
   ArrayResize(数组3,指定跨期+1); 
   //-- 
   for(int m=1; m 
      数组2[m]= m; 
      数组3[m]= m; 
      数组1[m]= 用价[shift+指定跨期-m]; 
     } 
   // sort 数组1[] in ascending order, 数组2[] is the permutation index  
   // Note, this is a poor quadratic search, and will not scale well with 指定跨期 
   for(m= 1; m 
      // find max 指标值 & its location in 数组1 [m..m+指定跨期] 
      最大值= 数组1[m]; 
      最大时= m; 
      for(j= m+1; j 
         if(数组1[j] 
            最大值= 数组1[j]; 
            最大时= j; 
           } 
        } 
      //--交换最大值 
      临时容器= 数组1[m]; 
      数组1[m]= 数组1[最大时]; 
      数组1[最大时]= 临时容器; 
      临时容器= 数组2[m]; 
      数组2[m]= 数组2[最大时]; 
      数组2[最大时]= 临时容器; 
     } 
   // 数组3[1..指定跨期] is nominally 1..m, but this here adjusts for 
   // ties. 
   m= 1; 
   while(m 
      //--查找重复值  
      j= m+1; 
      flag= true; 
      accum= 数组3[m]; 
      while(flag) { 
         if(数组1[m]!= 数组1[j]){ 
            if(j-m>1){ 
               // a streak of repeated values was found 
               // and so replace 数组3[] for those with  
               // its average 
               accum= accum/(j - m); 
               for(int n=m; n 
                  数组3[n]= accum; 
              } 
            flag= false; 
            } 
          else{ 
            accum += 数组3[j]; 
            j++; 
           } 
        } 
      m= j; 
     } 
   //-- 
   因子= 12.0/(指定跨期*(指定跨期-1)*(指定跨期+1)); 
   Lenp1half= (指定跨期 + 1) * 0.5; 
   for(accum= 0,m= 1; m 
      // Print("m= "+m+"Arr2[m] = "+数组2[m]+" 数组3[m]= "+数组3[m]);  
      accum+= (数组3[m] - Lenp1half) *(数组2[m] - Lenp1half); 
     } 
   指标值= 因子 * accum; 
   // Print("JTPO_B:  accum =  "+accum+" norm =  "+因子);  
   return(指标值); 
  } 
 //--------试译者:  hance66.blog.163.com/blog/  --------+ 
 |