⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ta_stochf.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Generated */    else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    /* min/max are checked for optInFastD_Period. *//* Generated */    if( (int)optInFastD_Period == TA_INTEGER_DEFAULT )/* Generated */       optInFastD_Period = 3;/* Generated */    else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    #if !defined(_MANAGED) && !defined(_JAVA)/* Generated */    if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT )/* Generated */       optInFastD_MAType = (TA_MAType)0;/* Generated */    else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    #endif /* !defined(_MANAGED) && !defined(_JAVA)*//* Generated */    #if !defined(_JAVA)/* Generated */    if( !outFastK )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    if( !outFastD )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    #endif /* !defined(_JAVA) *//* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK *//* Generated */ /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/   /* Insert TA function code here. */   /* With stochastic, there is a total of 4 different lines that    * are defined: FASTK, FASTD, SLOWK and SLOWD.    *    * The D is the signal line usually drawn over its    * corresponding K function.    *    *                    (Today's Close - LowestLow)    *  FASTK(Kperiod) =  --------------------------- * 100    *                     (HighestHigh - LowestLow)    *       *  FASTD(FastDperiod, MA type) = MA Smoothed FASTK over FastDperiod    *     *  SLOWK(SlowKperiod, MA type) = MA Smoothed FASTK over SlowKperiod    *    *  SLOWD(SlowDperiod, MA Type) = MA Smoothed SLOWK over SlowDperiod    *    * The HighestHigh and LowestLow are the extreme values among the    * last 'Kperiod'.    *      * SLOWK and FASTD are equivalent when using the same period.    *    * The following shows how these four lines are made available in TA-LIB:    *    *  TA_STOCH  : Returns the SLOWK and SLOWD    *  TA_STOCHF : Returns the FASTK and FASTD    *    * The TA_STOCH function correspond to the more widely implemented version    * found in many software/charting package. The TA_STOCHF is more rarely    * used because its higher volatility cause often whipsaws.    */   /* Identify the lookback needed. */   lookbackK      = optInFastK_Period-1;   lookbackFastD  = LOOKBACK_CALL(MA)( optInFastD_Period, optInFastD_MAType );   lookbackTotal  = lookbackK + lookbackFastD;   /* Move up the start index if there is not    * enough initial data.    */   if( startIdx < lookbackTotal )      startIdx = lookbackTotal;   /* Make sure there is still something to evaluate. */   if( startIdx > endIdx )   {      /* Succeed... but no data in the output. */      VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);      VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);      return ENUM_VALUE(RetCode,TA_SUCCESS,Success);   }   /* Do the K calculation:    *    *    Kt = 100 x ((Ct-Lt)/(Ht-Lt))    *    * Kt is today stochastic    * Ct is today closing price.    * Lt is the lowest price of the last K Period (including today)    * Ht is the highest price of the last K Period (including today)    */   /* Proceed with the calculation for the requested range.    * Note that this algorithm allows the input and    * output to be the same buffer.    */   outIdx = 0;   /* Calculate just enough K for ending up with the caller     * requested range. (The range of k must consider all    * the lookback involve with the smoothing).    */   trailingIdx = startIdx-lookbackTotal;   today       = trailingIdx+lookbackK;   lowestIdx   = highestIdx = -1;   diff = highest = lowest  = 0.0;   /* Allocate a temporary buffer large enough to    * store the K.    *    * If the output is the same as the input, great    * we just save ourself one memory allocation.    */   #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA )      bufferIsAllocated = 0;   #endif   #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY )      /* Always alloc, since output is of different type and       * its allocated size is not guarantee to be as large as       * the input.       */      ARRAY_ALLOC( tempBuffer, endIdx-today+1 );   #else      if( (outFastK == inHigh) ||           (outFastK == inLow)  ||           (outFastK == inClose) )      {         tempBuffer = outFastK;      }      else if( (outFastD == inHigh) ||               (outFastD == inLow)  ||               (outFastD == inClose) )      {         tempBuffer = outFastD;      }      else      {         #if !defined( _MANAGED ) && !defined( _JAVA )            bufferIsAllocated = 1;         #endif         ARRAY_ALLOC(tempBuffer, endIdx-today+1 );      }   #endif   /* Do the K calculation */   while( today <= endIdx )   {      /* Set the lowest low */      tmp = inLow[today];      if( lowestIdx < trailingIdx )      {         lowestIdx = trailingIdx;         lowest = inLow[lowestIdx];         i = lowestIdx;         while( ++i<=today )         {            tmp = inLow[i];            if( tmp < lowest )            {               lowestIdx = i;               lowest = tmp;            }         }         diff = (highest - lowest)/100.0;      }      else if( tmp <= lowest )      {         lowestIdx = today;         lowest = tmp;         diff = (highest - lowest)/100.0;      }      /* Set the highest high */      tmp = inHigh[today];      if( highestIdx < trailingIdx )      {         highestIdx = trailingIdx;         highest = inHigh[highestIdx];         i = highestIdx;         while( ++i<=today )         {            tmp = inHigh[i];            if( tmp > highest )            {               highestIdx = i;               highest = tmp;            }         }         diff = (highest - lowest)/100.0;      }      else if( tmp >= highest )      {         highestIdx = today;         highest = tmp;         diff = (highest - lowest)/100.0;      }      /* Calculate stochastic. */      if( diff != 0.0 )        tempBuffer[outIdx++] = (inClose[today]-lowest)/diff;      else        tempBuffer[outIdx++] = 0.0;      trailingIdx++;      today++;    }   /* Fast-K calculation completed. This K calculation is returned    * to the caller. It is smoothed to become Fast-D.    */   retCode = FUNCTION_CALL_DOUBLE(MA)( 0, outIdx-1,                                       tempBuffer, optInFastD_Period,                                       optInFastD_MAType,                                        outBegIdx, outNBElement, outFastD );   if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement)) == 0 )   {      #if defined(USE_SINGLE_PRECISION_INPUT)         ARRAY_FREE( tempBuffer );       #else         ARRAY_FREE_COND( bufferIsAllocated, tempBuffer );       #endif      /* Something wrong happen? No further data? */      VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);      VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);      return retCode;    }   /* Copy tempBuffer into the caller buffer.     * (Calculation could not be done directly in the    *  caller buffer because more input data then the    *  requested range was needed for doing %D).    */   ARRAY_MEMMOVE( outFastK, 0, tempBuffer, lookbackFastD, (int)VALUE_HANDLE_DEREF(outNBElement) );   /* Don't need K anymore, free it if it was allocated here. */   #if defined(USE_SINGLE_PRECISION_INPUT)      ARRAY_FREE( tempBuffer );    #else      ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -