示例#1
0
TA_RetCode TA_SMA( TA_Integer    startIdx,
                   TA_Integer    endIdx,
                   const TA_Real inReal_0[],
                   TA_Integer    optInTimePeriod_0, /* From 2 to TA_INTEGER_MAX */
                   TA_Integer   *outBegIdx,
                   TA_Integer   *outNbElement,
                   TA_Real       outReal_0[] )
/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
{
   /* Insert local variables here. */

/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

#ifndef TA_FUNC_NO_RANGE_CHECK

   /* Validate the requested output range. */
   if( startIdx < 0 )
      return TA_OUT_OF_RANGE_START_INDEX;
   if( (endIdx < 0) || (endIdx < startIdx))
      return TA_OUT_OF_RANGE_END_INDEX;

   /* Validate the parameters. */
   if( !inReal_0 ) return TA_BAD_PARAM;
   /* min/max are checked for optInTimePeriod_0. */
   if( (TA_Integer)optInTimePeriod_0 == TA_INTEGER_DEFAULT )
      optInTimePeriod_0 = 30;
   else if( ((TA_Integer)optInTimePeriod_0 < 2) || ((TA_Integer)optInTimePeriod_0 > 2147483647) )
      return TA_BAD_PARAM;

   if( outReal_0 == NULL )
      return TA_BAD_PARAM;

#endif /* TA_FUNC_NO_RANGE_CHECK */

/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

   /* Insert TA function code here. */

   return TA_INT_SMA( startIdx,
                      endIdx,
                      inReal_0,
                      optInTimePeriod_0,
                      outBegIdx, outNbElement, outReal_0 );
}
示例#2
0
TA_RetCode TA_MA( TA_Integer    startIdx,
                  TA_Integer    endIdx,
                  const TA_Real inReal_0[],
                  TA_Integer    optInTimePeriod_0, /* From 2 to TA_INTEGER_MAX */
                  TA_MAType     optInMAType_1,
                  TA_Integer   *outBegIdx,
                  TA_Integer   *outNbElement,
                  TA_Real       outReal_0[] )
/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
{
   /* Insert local variables here. */
   TA_Real *dummyBuffer;
   TA_RetCode retCode;

/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

#ifndef TA_FUNC_NO_RANGE_CHECK

   /* Validate the requested output range. */
   if( startIdx < 0 )
      return TA_OUT_OF_RANGE_START_INDEX;
   if( (endIdx < 0) || (endIdx < startIdx))
      return TA_OUT_OF_RANGE_END_INDEX;

   /* Validate the parameters. */
   if( !inReal_0 ) return TA_BAD_PARAM;
   /* min/max are checked for optInTimePeriod_0. */
   if( (TA_Integer)optInTimePeriod_0 == TA_INTEGER_DEFAULT )
      optInTimePeriod_0 = 30;
   else if( ((TA_Integer)optInTimePeriod_0 < 2) || ((TA_Integer)optInTimePeriod_0 > 2147483647) )
      return TA_BAD_PARAM;

   if( (TA_Integer)optInMAType_1 == TA_INTEGER_DEFAULT )
      optInMAType_1 = 0;
   else if( ((TA_Integer)optInMAType_1 < 0) || ((TA_Integer)optInMAType_1 > 8) )
      return TA_BAD_PARAM;

   if( outReal_0 == NULL )
      return TA_BAD_PARAM;

#endif /* TA_FUNC_NO_RANGE_CHECK */

/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

   /* Simply call the internal implementation of the
    * requested moving average.
    */
   switch( optInMAType_1 )
   {
   case TA_MAType_SMA:
      return TA_INT_SMA( startIdx, endIdx,                         
                         inReal_0, optInTimePeriod_0,                         
                         outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_EMA:
      return TA_INT_EMA( startIdx, endIdx,
                         inReal_0,
                         optInTimePeriod_0, PER_TO_K(optInTimePeriod_0),
                         outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_WMA:
      return TA_INT_WMA( startIdx, endIdx,
                         inReal_0, optInTimePeriod_0,
                         outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_DEMA:
      return TA_DEMA( startIdx, endIdx,
                      inReal_0, optInTimePeriod_0,
                      outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_TEMA:
      return TA_TEMA( startIdx, endIdx,
                      inReal_0, optInTimePeriod_0,
                      outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_TRIMA:
      return TA_TRIMA( startIdx, endIdx,
                       inReal_0, optInTimePeriod_0,
                       outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_KAMA:
      return TA_KAMA( startIdx, endIdx,
                      inReal_0, optInTimePeriod_0,
                      outBegIdx, outNbElement, outReal_0 );
      break;
   case TA_MAType_MAMA:
      /* The optInTimePeriod_0 is ignored and the FAMA output of the MAMA
       * is ignored.
       */
      dummyBuffer = TA_Malloc( sizeof(TA_Real)*(endIdx-startIdx+1) );
      if( !dummyBuffer )
         return TA_ALLOC_ERR;

      retCode = TA_MAMA( startIdx, endIdx,
                         inReal_0, 0.5, 0.05,
                         outBegIdx, outNbElement,
                         outReal_0, dummyBuffer );
      TA_Free( dummyBuffer );
      return retCode;
      break;
   case TA_MAType_T3:
      return TA_T3( startIdx, endIdx,
                    inReal_0, optInTimePeriod_0, 0.7,
                    outBegIdx, outNbElement, outReal_0 );
      break;
   }

   *outBegIdx    = 0;
   *outNbElement = 0;

   return TA_BAD_PARAM;                        
}