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

📄 ta_sarext.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 4 页
字号:
      isLong = 1;   }   else /* optInStartValue_0 < 0 => Start Short */   {      isLong = 0;   }   VALUE_HANDLE_DEREF(outBegIdx) = startIdx;   outIdx = 0;   /* Write the first SAR. */   todayIdx = startIdx;   newHigh = inHigh[todayIdx-1];   newLow  = inLow[todayIdx-1];   SAR_ROUNDING(newHigh);   SAR_ROUNDING(newLow);   if(optInStartValue == 0) /* Default action */   {      if( isLong == 1 )      {         ep  = inHigh[todayIdx];         sar = newLow;      }      else      {         ep  = inLow[todayIdx];         sar = newHigh;      }   }   else if ( optInStartValue > 0 ) /* Start Long at specified value. */   {      ep  = inHigh[todayIdx];      sar = optInStartValue;   }   else /* if optInStartValue < 0 => Start Short at specified value. */   {      ep  = inLow[todayIdx];      sar = std_fabs(optInStartValue);   }   SAR_ROUNDING(sar);   /* Cheat on the newLow and newHigh for the    * first iteration.    */   newLow  = inLow[todayIdx];   newHigh = inHigh[todayIdx];   while( todayIdx <= endIdx )   {      prevLow  = newLow;      prevHigh = newHigh;      newLow  = inLow[todayIdx];      newHigh = inHigh[todayIdx];         todayIdx++;      SAR_ROUNDING(newLow);      SAR_ROUNDING(newHigh);      if( isLong == 1 )      {           /* Switch to short if the low penetrates the SAR value. */         if( newLow <= sar )         {            /* Switch and Overide the SAR with the ep */            isLong = 0;            sar = ep;            /* Make sure the overide SAR is within             * yesterday's and today's range.             */            if( sar < prevHigh )               sar = prevHigh;                        if( sar < newHigh )               sar = newHigh;            /* Output the overide SAR  */            if( optInOffsetOnReverse != 0.0 )               sar += sar * optInOffsetOnReverse;             outReal[outIdx++] = -sar;            /* Adjust afShort and ep */            afShort = optInAccelerationInitShort;            ep = newLow;             /* Calculate the new SAR */            sar = sar + afShort * (ep - sar);            SAR_ROUNDING( sar );            /* Make sure the new SAR is within             * yesterday's and today's range.             */            if( sar < prevHigh )               sar = prevHigh;                        if( sar < newHigh )               sar = newHigh;         }         else         {            /* No switch */            /* Output the SAR (was calculated in the previous iteration) */            outReal[outIdx++] = sar;             /* Adjust afLong and ep. */            if( newHigh > ep )            {               ep = newHigh;               afLong += optInAccelerationLong;               if( afLong > optInAccelerationMaxLong )                  afLong = optInAccelerationMaxLong;            }            /* Calculate the new SAR */            sar = sar + afLong * (ep - sar);            SAR_ROUNDING( sar );            /* Make sure the new SAR is within             * yesterday's and today's range.             */            if( sar > prevLow )               sar = prevLow;                        if( sar > newLow )               sar = newLow;         }      }      else      {         /* Switch to long if the high penetrates the SAR value. */         if( newHigh >= sar )         {            /* Switch and Overide the SAR with the ep */            isLong = 1;            sar = ep;            /* Make sure the overide SAR is within             * yesterday's and today's range.             */            if( sar > prevLow )               sar = prevLow;                        if( sar > newLow )               sar = newLow;            /* Output the overide SAR  */            if( optInOffsetOnReverse != 0.0 )               sar -= sar * optInOffsetOnReverse;            outReal[outIdx++] = sar;            /* Adjust afLong and ep */            afLong = optInAccelerationInitLong;            ep = newHigh;            /* Calculate the new SAR */            sar = sar + afLong * (ep - sar);            SAR_ROUNDING( sar );            /* Make sure the new SAR is within             * yesterday's and today's range.             */            if( sar > prevLow )               sar = prevLow;                        if( sar > newLow )               sar = newLow;         }         else         {            /* No switch */            /* Output the SAR (was calculated in the previous iteration) */            outReal[outIdx++] = -sar;            /* Adjust afShort and ep. */            if( newLow < ep )            {               ep = newLow;               afShort += optInAccelerationShort;               if( afShort > optInAccelerationMaxShort )                  afShort = optInAccelerationMaxShort;            }            /* Calculate the new SAR */            sar = sar + afShort * (ep - sar);            SAR_ROUNDING( sar );            /* Make sure the new SAR is within             * yesterday's and today's range.             */            if( sar < prevHigh )               sar = prevHigh;                        if( sar < newHigh )               sar = newHigh;         }      }   }   VALUE_HANDLE_DEREF(outNBElement) = outIdx;   return ENUM_VALUE(RetCode,TA_SUCCESS,Success);}/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****//* Generated */ /* Generated */ #define  USE_SINGLE_PRECISION_INPUT/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )/* Generated */    #undef   TA_PREFIX/* Generated */    #define  TA_PREFIX(x) TA_S_##x/* Generated */ #endif/* Generated */ #undef   INPUT_TYPE/* Generated */ #define  INPUT_TYPE float/* Generated */ #if defined( _MANAGED )/* Generated */ enum class Core::RetCode Core::SarExt( int    startIdx,/* Generated */                                        int    endIdx,/* Generated */                                        cli::array<float>^ inHigh,/* Generated */                                        cli::array<float>^ inLow,/* Generated */                                        double        optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX *//* Generated */                                        double        optInOffsetOnReverse, /* From 0 to TA_REAL_MAX *//* Generated */                                        double        optInAccelerationInitLong, /* From 0 to TA_REAL_MAX *//* Generated */                                        double        optInAccelerationLong, /* From 0 to TA_REAL_MAX *//* Generated */                                        double        optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX *//* Generated */                                        double        optInAccelerationInitShort, /* From 0 to TA_REAL_MAX *//* Generated */                                        double        optInAccelerationShort, /* From 0 to TA_REAL_MAX *//* Generated */                                        double        optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX *//* Generated */                                        [Out]int%    outBegIdx,/* Generated */                                        [Out]int%    outNBElement,/* Generated */                                        cli::array<double>^  outReal )/* Generated */ #elif defined( _JAVA )/* Generated */ public RetCode sarExt( int    startIdx,/* Generated */                        int    endIdx,/* Generated */                        float        inHigh[],/* Generated */                        float        inLow[],/* Generated */                        double        optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX *//* Generated */                        double        optInOffsetOnReverse, /* From 0 to TA_REAL_MAX *//* Generated */                        double        optInAccelerationInitLong, /* From 0 to TA_REAL_MAX *//* Generated */                        double        optInAccelerationLong, /* From 0 to TA_REAL_MAX *//* Generated */                        double        optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX *//* Generated */                        double        optInAccelerationInitShort, /* From 0 to TA_REAL_MAX *//* Generated */                        double        optInAccelerationShort, /* From 0 to TA_REAL_MAX *//* Generated */                        double        optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX *//* Generated */                        MInteger     outBegIdx,/* Generated */                        MInteger     outNBElement,/* Generated */                        double        outReal[] )/* Generated */ #else/* Generated */ TA_RetCode TA_S_SAREXT( int    startIdx,

⌨️ 快捷键说明

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