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

📄 ta_bbands.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/{   /* Insert local variables here. */   ENUM_DECLARATION(RetCode) retCode;   int i;   double tempReal, tempReal2;   ARRAY_REF(tempBuffer1);   ARRAY_REF(tempBuffer2);/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****//* Generated */ /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK/* Generated */ /* Generated */    /* Validate the requested output range. *//* Generated */    if( startIdx < 0 )/* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);/* Generated */    if( (endIdx < 0) || (endIdx < startIdx))/* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);/* Generated */ /* Generated */    #if !defined(_JAVA)/* Generated */    if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */    #endif /* !defined(_JAVA)*//* Generated */    /* min/max are checked for optInTimePeriod. *//* Generated */    if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )/* Generated */       optInTimePeriod = 5;/* Generated */    else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    if( optInNbDevUp == TA_REAL_DEFAULT )/* Generated */       optInNbDevUp = 2.000000e+0;/* Generated */    else if( (optInNbDevUp < -3.000000e+37) ||/* Generated */  (optInNbDevUp > 3.000000e+37) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    if( optInNbDevDn == TA_REAL_DEFAULT )/* Generated */       optInNbDevDn = 2.000000e+0;/* Generated */    else if( (optInNbDevDn < -3.000000e+37) ||/* Generated */  (optInNbDevDn > 3.000000e+37) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    #if !defined(_MANAGED) && !defined(_JAVA)/* Generated */    if( (int)optInMAType == TA_INTEGER_DEFAULT )/* Generated */       optInMAType = (TA_MAType)0;/* Generated */    else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    #endif /* !defined(_MANAGED) && !defined(_JAVA)*//* Generated */    #if !defined(_JAVA)/* Generated */    if( !outRealUpperBand )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    if( !outRealMiddleBand )/* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);/* Generated */ /* Generated */    if( !outRealLowerBand )/* 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. */   /* Identify TWO temporary buffer among the outputs.    *    * These temporary buffers allows to perform the    * calculation without any memory allocation.    *    * Whenever possible, make the tempBuffer1 be the    * middle band output. This will save one copy operation.    */   #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY )      tempBuffer1 = outRealMiddleBand;      tempBuffer2 = outRealLowerBand;   #else      if( inReal == outRealUpperBand )      {         tempBuffer1 = outRealMiddleBand;         tempBuffer2 = outRealLowerBand;      }      else if( inReal == outRealLowerBand )      {         tempBuffer1 = outRealMiddleBand;         tempBuffer2 = outRealUpperBand;      }      else if( inReal == outRealMiddleBand )      {         tempBuffer1 = outRealLowerBand;         tempBuffer2 = outRealUpperBand;      }      else      {         tempBuffer1 = outRealMiddleBand;         tempBuffer2 = outRealUpperBand;      }      /* Check that the caller is not doing tricky things.        * (like using the input buffer in two output!)       */      if( (tempBuffer1 == inReal) || (tempBuffer2 == inReal) )         return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);   #endif   /* Calculate the middle band, which is a moving average.    * The other two bands will simply add/substract the    * standard deviation from this middle band.    */   retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal,                                optInTimePeriod, optInMAType,                                outBegIdx, outNBElement, tempBuffer1 );   if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) )   {      VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);      return retCode;   }   /* Calculate the standard deviation into tempBuffer2. */   if( optInMAType == ENUM_VALUE(MAType,TA_MAType_SMA,Sma) )   {      /* A small speed optimization by re-using the       * already calculated SMA.       */       FUNCTION_CALL(INT_stddev_using_precalc_ma)( inReal, tempBuffer1,                                                    (int)VALUE_HANDLE_DEREF(outBegIdx), (int)VALUE_HANDLE_DEREF(outNBElement),                                                   optInTimePeriod, tempBuffer2 );   }   else   {      /* Calculate the Standard Deviation */      retCode = FUNCTION_CALL(STDDEV)( (int)VALUE_HANDLE_DEREF(outBegIdx), endIdx, inReal,                                       optInTimePeriod, 1.0,                                       outBegIdx, outNBElement, tempBuffer2 );      if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) )      {         VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);         return retCode;      }   }   /* Copy the MA calculation into the middle band ouput, unless    * the calculation was done into it already!    */   #if !defined(USE_SINGLE_PRECISION_INPUT)      if( tempBuffer1 != outRealMiddleBand )      {         ARRAY_COPY( outRealMiddleBand, tempBuffer1, VALUE_HANDLE_DEREF(outNBElement) );      }   #endif   /* Now do a tight loop to calculate the upper/lower band at    * the same time.     *    * All the following 5 loops are doing the same, except there    * is an attempt to speed optimize by eliminating uneeded    * multiplication.    */   if( optInNbDevUp == optInNbDevDn )   {      if(  optInNbDevUp == 1.0 )      {         /* No standard deviation multiplier needed. */         for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ )         {            tempReal  = tempBuffer2[i];            tempReal2 = outRealMiddleBand[i];            outRealUpperBand[i] = tempReal2 + tempReal;            outRealLowerBand[i] = tempReal2 - tempReal;         }      }      else      {         /* Upper/lower band use the same standard deviation multiplier. */         for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ )         {            tempReal  = tempBuffer2[i] * optInNbDevUp;            tempReal2 = outRealMiddleBand[i];            outRealUpperBand[i] = tempReal2 + tempReal;            outRealLowerBand[i] = tempReal2 - tempReal;         }      }   }   else if( optInNbDevUp == 1.0 )   {      /* Only lower band has a standard deviation multiplier. */      for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ )      {         tempReal  = tempBuffer2[i];         tempReal2 = outRealMiddleBand[i];         outRealUpperBand[i] = tempReal2 + tempReal;         outRealLowerBand[i] = tempReal2 - (tempReal * optInNbDevDn);      }   }   else if( optInNbDevDn == 1.0 )   {      /* Only upper band has a standard deviation multiplier. */      for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ )      {         tempReal  = tempBuffer2[i];         tempReal2 = outRealMiddleBand[i];         outRealLowerBand[i] = tempReal2 - tempReal;         outRealUpperBand[i] = tempReal2 + (tempReal * optInNbDevUp);      }   }   else   {      /* Upper/lower band have distinctive standard deviation multiplier. */      for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ )      {         tempReal  = tempBuffer2[i];         tempReal2 = outRealMiddleBand[i];         outRealUpperBand[i] = tempReal2 + (tempReal * optInNbDevUp);         outRealLowerBand[i] = tempReal2 - (tempReal * optInNbDevDn);      }   }

⌨️ 快捷键说明

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