请问如何获取cci近20根k线内,cci的最高或最低点对应‘k线’的最高或最低点

 

以下是我使用的方法,但是不能准确的获取到。请问有什么更好的方法吗

    double max=0,min=0;

    int jishu=0;

    for(int i=0;i<10000;i++)

     {

       if(-100>ccixian(i) && ccixian(i+1) >ccixian(i) && ccixian(i-1) >ccixian(i) ) //最低点

        {

          if(jishu>11)

           {

             break;

           }

          max=High[i];

          jishu++;

        } 

       if(ccixian(i)>100  && ccixian(i)> ccixian(i+1)  &&   ccixian(i)> ccixian(i-1))

        {

          if(jishu>11)

           {

             break;

           }

          min=Low[i];

          jishu++;

        } 

      }

 
//+------------------------------------------------------------------+
//|                                                     test_cci.mq4 |
//|                                         Copyright 2022, fxMeter. |
//|                            https://www.mql5.com/en/users/fxmeter |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, fxMeter."
#property link      "https://www.mql5.com/en/users/fxmeter"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
   int bars = 20; //20个K先内
   int shift = GetCCIMax(bars);//20个K线内,CCI最大的那个K线的索引
   double hi = iHigh(NULL,0,shift);//对应的K线的最高价

   //
   shift = GetCCIMin(bars); //20个K线内,CCI最小的那个K线的索引
   double low = iLow(NULL,0,shift);//对应的K线的最低价
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetCCIMax(int bars)
{
   double max = iCCI(NULL,0,14,PRICE_TYPICAL,0);
   int shift = 0;
   for(int i=1; i<bars && i<Bars; i++)
   {
      double v = iCCI(NULL,0,14,PRICE_TYPICAL,i);
      if(v>max)
      {
         shift = i;
         max = v;
      }
   }
   return(shift);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetCCIMin(int bars)
{
   double min = iCCI(NULL,0,14,PRICE_TYPICAL,0);
   int shift = 0;
   for(int i=1; i<bars && i<Bars; i++)
   {
      double v = iCCI(NULL,0,14,PRICE_TYPICAL,i);
      if(v<min)
      {
         shift = i;
         min = v;
      }
   }
   return(shift);
}

//+------------------------------------------------------------------+
 
Ziheng Zhuang #:

非常感谢您的帮助,通过您的方法已经可以了。