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

📄 ta_abstract.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 3 页
字号:
   const TA_FuncInfo *funcInfo;   if( param == NULL )   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Make sure this index really exist. */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   if( paramIndex >= funcInfo->nbInput )   {      return TA_BAD_PARAM;   }      /* Verify the type of the parameter. */   paramInfo = paramHolderPriv->in[paramIndex].inputInfo;   if( !paramInfo ) return TA_INTERNAL_ERROR(2);   if( paramInfo->type != TA_Input_Price )   {      return TA_INVALID_PARAM_HOLDER_TYPE;   }   /* keep a copy of the provided parameter. */   #define SET_PARAM_INFO(lowerParam,upperParam) \   { \      if( paramInfo->flags & TA_IN_PRICE_##upperParam ) \      { \         if( lowerParam == NULL ) \         { \            return TA_BAD_PARAM; \         } \         paramHolderPriv->in[paramIndex].data.inPrice.lowerParam = lowerParam; \      } \   }   SET_PARAM_INFO(open, OPEN );   SET_PARAM_INFO(high, HIGH );   SET_PARAM_INFO(low, LOW );   SET_PARAM_INFO(close, CLOSE );   SET_PARAM_INFO(volume, VOLUME );   SET_PARAM_INFO(openInterest, OPENINTEREST );   #undef SET_PARAM_INFO   /* This parameter is now initialized, clear the corresponding bit. */   paramHolderPriv->inBitmap &= ~(1<<paramIndex);   return TA_SUCCESS;}TA_RetCode TA_SetOptInputParamInteger( TA_ParamHolder *param,                                       unsigned int paramIndex,                                       TA_Integer value ){      TA_ParamHolderPriv *paramHolderPriv;   const TA_OptInputParameterInfo *paramInfo;   const TA_FuncInfo *funcInfo;   if( param == NULL )   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Make sure this index really exist. */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   if( paramIndex >= funcInfo->nbOptInput )   {      return TA_BAD_PARAM;   }      /* Verify the type of the parameter. */   paramInfo = paramHolderPriv->optIn[paramIndex].optInputInfo;   if( !paramInfo ) return TA_INTERNAL_ERROR(2);   if( (paramInfo->type != TA_OptInput_IntegerRange) &&       (paramInfo->type != TA_OptInput_IntegerList) )   {      return TA_INVALID_PARAM_HOLDER_TYPE;   }   /* keep a copy of the provided parameter. */   paramHolderPriv->optIn[paramIndex].data.optInInteger = value;    return TA_SUCCESS;}TA_RetCode TA_SetOptInputParamReal( TA_ParamHolder *param,                                    unsigned int paramIndex,                                    TA_Real value ){      TA_ParamHolderPriv *paramHolderPriv;   const TA_OptInputParameterInfo *paramInfo;   const TA_FuncInfo *funcInfo;   if( param == NULL )   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Make sure this index really exist. */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   if( paramIndex >= funcInfo->nbOptInput )   {      return TA_BAD_PARAM;   }      /* Verify the type of the parameter. */   paramInfo = paramHolderPriv->optIn[paramIndex].optInputInfo;   if( !paramInfo ) return TA_INTERNAL_ERROR(2);   if( (paramInfo->type != TA_OptInput_RealRange) &&       (paramInfo->type != TA_OptInput_RealList) )   {      return TA_INVALID_PARAM_HOLDER_TYPE;   }   /* keep a copy of the provided parameter. */   paramHolderPriv->optIn[paramIndex].data.optInReal = value;    return TA_SUCCESS;}/* Setup the parameters indicating where to store the output. */TA_RetCode TA_SetOutputParamIntegerPtr( TA_ParamHolder *param,                                        unsigned int paramIndex,                                        TA_Integer     *out ){      TA_ParamHolderPriv *paramHolderPriv;   const TA_OutputParameterInfo *paramInfo;   const TA_FuncInfo *funcInfo;   if( (param == NULL) || (out == NULL) )   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Make sure this index really exist. */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   if( paramIndex >= funcInfo->nbOutput )   {      return TA_BAD_PARAM;   }      /* Verify the type of the parameter. */   paramInfo = paramHolderPriv->out[paramIndex].outputInfo;   if( !paramInfo ) return TA_INTERNAL_ERROR(2);   if( paramInfo->type != TA_Output_Integer )   {      return TA_INVALID_PARAM_HOLDER_TYPE;   }   /* keep a copy of the provided parameter. */   paramHolderPriv->out[paramIndex].data.outInteger = out;    /* This parameter is now initialized, clear the corresponding bit. */   paramHolderPriv->outBitmap &= ~(1<<paramIndex);   return TA_SUCCESS;}TA_RetCode TA_SetOutputParamRealPtr( TA_ParamHolder *param,                                     unsigned int paramIndex,                                     TA_Real        *out ){      TA_ParamHolderPriv *paramHolderPriv;   const TA_OutputParameterInfo *paramInfo;   const TA_FuncInfo *funcInfo;   if( (param == NULL) || (out == NULL) )   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Make sure this index really exist. */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   if( paramIndex >= funcInfo->nbOutput )   {      return TA_BAD_PARAM;   }      /* Verify the type of the parameter. */   paramInfo = paramHolderPriv->out[paramIndex].outputInfo;   if( !paramInfo ) return TA_INTERNAL_ERROR(2);   if( paramInfo->type != TA_Output_Real )   {      return TA_INVALID_PARAM_HOLDER_TYPE;   }   /* keep a copy of the provided parameter. */   paramHolderPriv->out[paramIndex].data.outReal = out;    /* This parameter is now initialized, clear the corresponding bit. */   paramHolderPriv->outBitmap &= ~(1<<paramIndex);   return TA_SUCCESS;}TA_RetCode TA_GetLookback( const TA_ParamHolder *param, TA_Integer *lookback ){      const TA_ParamHolderPriv *paramHolderPriv;   const TA_FuncDef *funcDef;   const TA_FuncInfo *funcInfo;   TA_FrameLookback lookbackFunction;   if( (param == NULL) || (lookback == NULL))   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Get the pointer on the lookback function. */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   funcDef = (const TA_FuncDef *)funcInfo->handle;   if( !funcDef ) return TA_INTERNAL_ERROR(2);   lookbackFunction = funcDef->lookback;   if( !lookbackFunction ) return TA_INTERNAL_ERROR(2);   /* Perform the function call. */   *lookback = (*lookbackFunction)( paramHolderPriv );   return TA_SUCCESS;}/* Finally, call a TA function with the parameters. */TA_RetCode TA_CallFunc( const TA_ParamHolder *param,                        TA_Integer            startIdx,                        TA_Integer            endIdx,                        TA_Integer           *outBegIdx,                        TA_Integer           *outNbElement ){      TA_RetCode retCode;   const TA_ParamHolderPriv *paramHolderPriv;   const TA_FuncDef *funcDef;   const TA_FuncInfo *funcInfo;   TA_FrameFunction function;   if( (param == NULL) ||       (outBegIdx == NULL) ||       (outNbElement == NULL) )   {      return TA_BAD_PARAM;   }   paramHolderPriv = (TA_ParamHolderPriv *)(param->hiddenData);   if( paramHolderPriv->magicNumber != TA_PARAM_HOLDER_PRIV_MAGIC_NB )   {      return TA_INVALID_PARAM_HOLDER;   }   /* Check that all parameters are initialize (except the optInput). */   if( paramHolderPriv->inBitmap != 0 )   {      return TA_INPUT_NOT_ALL_INITIALIZE;   }   if( paramHolderPriv->outBitmap != 0 )   {      return TA_OUTPUT_NOT_ALL_INITIALIZE;   }   /* Get the pointer on the function */   funcInfo = paramHolderPriv->funcInfo;   if( !funcInfo ) return TA_INVALID_HANDLE;   funcDef = (const TA_FuncDef *)funcInfo->handle;   if( !funcDef ) return TA_INTERNAL_ERROR(2);   function = funcDef->function;   if( !function ) return TA_INTERNAL_ERROR(2);   /* Perform the function call. */   retCode = (*function)( paramHolderPriv, startIdx, endIdx,                          outBegIdx, outNbElement );   return retCode;}/**** Local functions definitions.     ****/static TA_RetCode getGroupId( const char *groupString, unsigned int *groupId ){   unsigned int i;   for( i=0; i < TA_NB_GROUP_ID; i++ )   {      if( strcmp( TA_GroupString[i], groupString ) == 0 )      {         *groupId = i;         return TA_SUCCESS;      }   }   return TA_GROUP_NOT_FOUND;}static TA_RetCode getGroupSize( TA_GroupId groupId, unsigned int *groupSize ){   #ifdef TA_GEN_CODE      /* Code used only when compiled with gen_code. */            unsigned int i, j;      const TA_FuncDef **funcDefTable;      const TA_FuncDef *funcDef;      unsigned int tableSize;      unsigned int nbFuncFound;      if( groupId >= TA_NB_GROUP_ID ) return TA_INTERNAL_ERROR(2);           if( !groupSize ) return TA_INTERNAL_ERROR(2);      nbFuncFound = 0;      for( i=0; i < 26; i++ )      {         funcDefTable = TA_DEF_Tables[i];         tableSize = *(TA_DEF_TablesSize[i]);         for( j=0; j < tableSize; j++ )         {            funcDef = funcDefTable[j];            if( funcDef && (funcDef->groupId == groupId) )               nbFuncFound++;         }      }      *groupSize = nbFuncFound;      return TA_SUCCESS;   #else      /* Optimized code in the final library. */      *groupSize = TA_PerGroupSize[groupId];      return TA_SUCCESS;   #endif}#ifdef TA_GEN_CODE   static TA_RetCode getFuncNameByIdx( TA_GroupId groupId,                                       unsigned int idx,                                       const char **stringPtr )#else   static TA_RetCode getFuncNameByIdx( TA_GroupId groupId,                                       unsigned int idx,                                       const char **stringPtr )#endif{   #ifdef TA_GEN_CODE      /* Code used only when compiled with gen_code. */            unsigned int curIdx;      unsigned int i, j, found;      const TA_FuncDef **funcDefTable;      unsigned int tableSize;      const TA_FuncInfo *funcInfo;      if( !stringPtr ) return TA_INTERNAL_ERROR(2);      curIdx = 0;      found = 0;      for( i=0; (i < 26) && !found; i++ )      {         funcDefTable = TA_DEF_Tables[i];         tableSize = *(TA_DEF_TablesSize[i]);         for( j=0; (j < tableSize) && !found; j++ )         {            if( funcDefTable[j]->groupId == groupId )            {               if( idx == curIdx )               {                  funcInfo = funcDefTable[j]->funcInfo;                  if( !funcInfo ) return TA_INTERNAL_ERROR(2);                  *stringPtr = funcInfo->name;                  found = 1;               }               curIdx++;            }         }      }      if( found != 1 ) return TA_INTERNAL_ERROR(2);      if( !(*stringPtr) ) return TA_INTERNAL_ERROR(2);      return TA_SUCCESS;   #else      /* Optimized code in the final library. */      const TA_FuncDef **funcDefTable;      const TA_FuncInfo *funcInfo;      funcDefTable = TA_PerGroupFuncDef[groupId];      funcInfo = funcDefTable[idx]->funcInfo;      *stringPtr = funcInfo->name;      return TA_SUCCESS;   #endif}

⌨️ 快捷键说明

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