<commit_before>/* TA-LIB Copyright (c) 1999-2003, <NAME>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *
 * - Neither name of author nor the names of its contributors
 *   may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* List of contributors:
 *
 *  Initial  Name/description
 *  -------------------------------------------------------------------
 *  MF       <NAME>
 *  PP       <NAME>
 *
 *
 * Change history:
 *
 *  MMDDYY BY   Description
 *  -------------------------------------------------------------------
 *  120802 MF   Template creation.
 *  101103 PP   Initial creation of code.
 *
 */

/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
/* All code within this section is automatically
 * generated by gen_code. Any modification will be lost
 * next time gen_code is run.
 */
/* Generated */ 
/* Generated */ #if defined( _MANAGED )
/* Generated */    #using <mscorlib.dll>
/* Generated */    #include "Core.h"
/* Generated */    #define TA_INTERNAL_ERROR(Id) (TA_INTERNAL_ERROR)
/* Generated */    namespace TA { namespace Lib {
/* Generated */ #else
/* Generated */    #include <string.h>
/* Generated */    #include <math.h>
/* Generated */    #include "ta_func.h"
/* Generated */    #include "ta_trace.h"
/* Generated */ #endif
/* Generated */ 
/* Generated */ #ifndef TA_UTILITY_H
/* Generated */    #include "ta_utility.h"
/* Generated */ #endif
/* Generated */ 
/* Generated */ #ifndef TA_MEMORY_H
/* Generated */    #include "ta_memory.h"
/* Generated */ #endif
/* Generated */ 
/* Generated */ #define TA_PREFIX(x) TA_##x
/* Generated */ #define INPUT_TYPE   double
/* Generated */ 
/* Generated */ #if defined( _MANAGED )
/* Generated */ int Core::STOCHRSI_Lookback( int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                            int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                            TA_MAType     optInFastD_MAType ) /* Generated */ 
/* Generated */ #else
/* Generated */ int TA_STOCHRSI_Lookback( int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                         int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                         TA_MAType     optInFastD_MAType ) /* Generated */ 
/* Generated */ #endif
/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
{
   /* insert lookback code here. */
   int retValue;

   retValue = TA_RSI_Lookback( optInFastK_Period ) + TA_STOCHF_Lookback( optInFastK_Period, optInFastD_Period, optInFastD_MAType );

   return retValue;
}

/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
/*
 * TA_STOCHRSI - Stochastic Relative Strength Index
 * 
 * Input  = double
 * Output = double, double
 * 
 * Optional Parameters
 * -------------------
 * optInFastK_Period:(From 1 to 100000)
 *    Time period for building the Fast-K line
 * 
 * optInFastD_Period:(From 1 to 100000)
 *    Smoothing for making the Fast-D line. Usually set to 3
 * 
 * optInFastD_MAType:
 *    Type of Moving Average for Fast-D
 * 
 * 
 */
/* Generated */ 
/* Generated */ #if defined( _MANAGED )
/* Generated */ enum Core::TA_RetCode Core::STOCHRSI( int    startIdx,
/* Generated */                                       int    endIdx,
/* Generated */                                       double       inReal __gc [],
/* Generated */                                       int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                                       int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                                       TA_MAType     optInFastD_MAType,
/* Generated */                                       [OutAttribute]Int32 *outBegIdx,
/* Generated */                                       [OutAttribute]Int32 *outNbElement,
/* Generated */                                       double        outFastK __gc [],
/* Generated */                                       double        outFastD __gc [] )
/* Generated */ #else
/* Generated */ TA_RetCode TA_STOCHRSI( int    startIdx,
/* Generated */                         int    endIdx,
/* Generated */                         const double inReal[],
/* Generated */                         int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                         int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                         TA_MAType     optInFastD_MAType,
/* Generated */                         int          *outBegIdx,
/* Generated */                         int          *outNbElement,
/* Generated */                         double        outFastK[],
/* Generated */                         double        outFastD[] )
/* Generated */ #endif
/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
{
   /* insert local variable here */
   ARRAY_REF(tempRSIBuffer);

   TA_RetCode retCode;
   int lookbackTotal, lookbackRSI, tempArraySize;
   int outBegIdx1, outBegIdx2, outNbElement1;

/**** START GENCODE SECTION 3 - 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 TA_OUT_OF_RANGE_START_INDEX;
/* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
/* Generated */       return TA_OUT_OF_RANGE_END_INDEX;
/* Generated */ 
/* Generated */    /* Validate the parameters. */
/* Generated */    if( !inReal ) return TA_BAD_PARAM;
/* Generated */    /* min/max are checked for optInFastK_Period. */
/* Generated */    if( (int)optInFastK_Period == TA_INTEGER_DEFAULT )
/* Generated */       optInFastK_Period = 5;
/* Generated */    else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) )
/* Generated */       return TA_BAD_PARAM;
/* 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 TA_BAD_PARAM;
/* Generated */ 
/* Generated */    #if !defined(_MANAGED)
/* Generated */    if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT )
/* Generated */       optInFastD_MAType = 0;
/* Generated */    else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */    #endif /* !defined(_MANAGED) */
/* Generated */    if( outFastK == NULL )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */    if( outFastD == NULL )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
/* Generated */ 
/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

   /* Insert TA function code here. */
  
   /* 
    * Stochastic RSI
    *
    */

   *outBegIdx    = 0;
   *outNbElement = 0;

   /* Adjust startIdx to account for the lookback period. */
   lookbackRSI = TA_RSI_Lookback( optInFastK_Period );
   lookbackTotal = lookbackRSI + TA_STOCHF_Lookback( optInFastK_Period, optInFastD_Period, optInFastD_MAType );

   if( startIdx < lookbackTotal )
      startIdx = lookbackTotal;

   /* Make sure there is still something to evaluate. */
   if( startIdx >= endIdx )
   {
      *outBegIdx = 0;
      *outNbElement = 0;
      return TA_SUCCESS;
   }

   *outBegIdx = startIdx;

   tempArraySize = (endIdx - startIdx) + 1 + lookbackTotal;

   ARRAY_ALLOC( tempRSIBuffer, tempArraySize );

   retCode = TA_PREFIX(RSI)(startIdx, 
                            endIdx, 
                            inReal, 
                            optInFastK_Period, 
                            &outBegIdx1, 
                            &outNbElement1, 
                            tempRSIBuffer);

   if( retCode != TA_SUCCESS || outNbElement1 == 0 )
   {
      ARRAY_FREE( tempRSIBuffer );
      *outBegIdx = 0;
      *outNbElement = 0;
      return retCode;
   }
   
   tempArraySize--;
   tempArraySize -= lookbackRSI;

   retCode = TA_STOCHF(0,
                       tempArraySize,
                       tempRSIBuffer,
                       tempRSIBuffer,
                       tempRSIBuffer,
                       optInFastK_Period,
                       optInFastD_Period,
                       optInFastD_MAType,
                       &outBegIdx2,
                       outNbElement,
                       outFastK,
                       outFastD);
 
   ARRAY_FREE( tempRSIBuffer );

   if( retCode != TA_SUCCESS || outNbElement == 0 )
   {
      *outBegIdx = 0;
      *outNbElement = 0;
      return retCode;
   }

   return TA_SUCCESS;
}

/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
/* Generated */ 
/* Generated */ #define  USE_SINGLE_PRECISION_INPUT
/* Generated */ #if !defined( _MANAGED )
/* 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 Core::TA_RetCode Core::STOCHRSI( int    startIdx,
/* Generated */                                       int    endIdx,
/* Generated */                                       float        inReal __gc [],
/* Generated */                                       int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                                       int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                                       TA_MAType     optInFastD_MAType,
/* Generated */                                       [OutAttribute]Int32 *outBegIdx,
/* Generated */                                       [OutAttribute]Int32 *outNbElement,
/* Generated */                                       double        outFastK __gc [],
/* Generated */                                       double        outFastD __gc [] )
/* Generated */ #else
/* Generated */ TA_RetCode TA_S_STOCHRSI( int    startIdx,
/* Generated */                           int    endIdx,
/* Generated */                           const float  inReal[],
/* Generated */                           int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                           int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                           TA_MAType     optInFastD_MAType,
/* Generated */                           int          *outBegIdx,
/* Generated */                           int          *outNbElement,
/* Generated */                           double        outFastK[],
/* Generated */                           double        outFastD[] )
/* Generated */ #endif
/* Generated */ {
/* Generated */    ARRAY_REF(tempRSIBuffer);
/* Generated */    TA_RetCode retCode;
/* Generated */    int lookbackTotal, lookbackRSI, tempArraySize;
/* Generated */    int outBegIdx1, outBegIdx2, outNbElement1;
/* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
/* Generated */     if( startIdx < 0 )
/* Generated */        return TA_OUT_OF_RANGE_START_INDEX;
/* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
/* Generated */        return TA_OUT_OF_RANGE_END_INDEX;
/* Generated */     if( !inReal ) return TA_BAD_PARAM;
/* Generated */     if( (int)optInFastK_Period == TA_INTEGER_DEFAULT )
/* Generated */        optInFastK_Period = 5;
/* Generated */     else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) )
/* Generated */        return TA_BAD_PARAM;
/* 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 TA_BAD_PARAM;
/* Generated */     #if !defined(_MANAGED)
/* Generated */     if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT )
/* Generated */        optInFastD_MAType = 0;
/* Generated */     else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) )
/* Generated */        return TA_BAD_PARAM;
/* Generated */     #endif 
/* Generated */     if( outFastK == NULL )
/* Generated */        return TA_BAD_PARAM;
/* Generated */     if( outFastD == NULL )
/* Generated */        return TA_BAD_PARAM;
/* Generated */  #endif 
/* Generated */    *outBegIdx    = 0;
/* Generated */    *outNbElement = 0;
/* Generated */    lookbackRSI = TA_RSI_Lookback( optInFastK_Period );
/* Generated */    lookbackTotal = lookbackRSI + TA_STOCHF_Lookback( optInFastK_Period, optInFastD_Period, optInFastD_MAType );
/* Generated */    if( startIdx < lookbackTotal )
/* Generated */       startIdx = lookbackTotal;
/* Generated */    if( startIdx >= endIdx )
/* Generated */    {
/* Generated */       *outBegIdx = 0;
/* Generated */       *outNbElement = 0;
/* Generated */       return TA_SUCCESS;
/* Generated */    }
/* Generated */    *outBegIdx = startIdx;
/* Generated */    tempArraySize = (endIdx - startIdx) + 1 + lookbackTotal;
/* Generated */    ARRAY_ALLOC( tempRSIBuffer, tempArraySize );
/* Generated */    retCode = TA_PREFIX(RSI)(startIdx, 
/* Generated */                             endIdx, 
/* Generated */                             inReal, 
/* Generated */                             optInFastK_Period, 
/* Generated */                             &outBegIdx1, 
/* Generated */                             &outNbElement1, 
/* Generated */                             tempRSIBuffer);
/* Generated */    if( retCode != TA_SUCCESS || outNbElement1 == 0 )
/* Generated */    {
/* Generated */       ARRAY_FREE( tempRSIBuffer );
/* Generated */       *outBegIdx = 0;
/* Generated */       *outNbElement = 0;
/* Generated */       return retCode;
/* Generated */    }
/* Generated */    tempArraySize--;
/* Generated */    tempArraySize -= lookbackRSI;
/* Generated */    retCode = TA_STOCHF(0,
/* Generated */                        tempArraySize,
/* Generated */                        tempRSIBuffer,
/* Generated */                        tempRSIBuffer,
/* Generated */                        tempRSIBuffer,
/* Generated */                        optInFastK_Period,
/* Generated */                        optInFastD_Period,
/* Generated */                        optInFastD_MAType,
/* Generated */                        &outBegIdx2,
/* Generated */                        outNbElement,
/* Generated */                        outFastK,
/* Generated */                        outFastD);
/* Generated */    ARRAY_FREE( tempRSIBuffer );
/* Generated */    if( retCode != TA_SUCCESS || outNbElement == 0 )
/* Generated */    {
/* Generated */       *outBegIdx = 0;
/* Generated */       *outNbElement = 0;
/* Generated */       return retCode;
/* Generated */    }
/* Generated */    return TA_SUCCESS;<commit_msg>Add independent control to the RSI period + correct some limit cases.<commit_after>/* TA-LIB Copyright (c) 1999-2003, <NAME>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *
 * - Neither name of author nor the names of its contributors
 *   may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* List of contributors:
 *
 *  Initial  Name/description
 *  -------------------------------------------------------------------
 *  MF       <NAME>
 *  PP       <NAME>
 *
 *
 * Change history:
 *
 *  MMDDYY BY   Description
 *  -------------------------------------------------------------------
 *  120802 MF   Template creation.
 *  101103 PP   Initial creation of code.
 *  112603 MF   Add independent control to the RSI period.
 */

/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
/* All code within this section is automatically
 * generated by gen_code. Any modification will be lost
 * next time gen_code is run.
 */
/* Generated */ 
/* Generated */ #if defined( _MANAGED )
/* Generated */    #using <mscorlib.dll>
/* Generated */    #include "Core.h"
/* Generated */    #define TA_INTERNAL_ERROR(Id) (TA_INTERNAL_ERROR)
/* Generated */    namespace TA { namespace Lib {
/* Generated */ #else
/* Generated */    #include <string.h>
/* Generated */    #include <math.h>
/* Generated */    #include "ta_func.h"
/* Generated */    #include "ta_trace.h"
/* Generated */ #endif
/* Generated */ 
/* Generated */ #ifndef TA_UTILITY_H
/* Generated */    #include "ta_utility.h"
/* Generated */ #endif
/* Generated */ 
/* Generated */ #ifndef TA_MEMORY_H
/* Generated */    #include "ta_memory.h"
/* Generated */ #endif
/* Generated */ 
/* Generated */ #define TA_PREFIX(x) TA_##x
/* Generated */ #define INPUT_TYPE   double
/* Generated */ 
/* Generated */ #if defined( _MANAGED )
/* Generated */ int Core::STOCHRSI_Lookback( int           optInTimePeriod, /* From 2 to 100000 */
/* Generated */                            int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                            int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                            TA_MAType     optInFastD_MAType ) /* Generated */ 
/* Generated */ #else
/* Generated */ int TA_STOCHRSI_Lookback( int           optInTimePeriod, /* From 2 to 100000 */
/* Generated */                         int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                         int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                         TA_MAType     optInFastD_MAType ) /* Generated */ 
/* Generated */ #endif
/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
{
   /* insert lookback code here. */
   int retValue;

   retValue = TA_RSI_Lookback( optInTimePeriod ) + TA_STOCHF_Lookback( optInFastK_Period, optInFastD_Period, optInFastD_MAType );

   return retValue;
}

/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
/*
 * TA_STOCHRSI - Stochastic Relative Strength Index
 * 
 * Input  = double
 * Output = double, double
 * 
 * Optional Parameters
 * -------------------
 * optInTimePeriod:(From 2 to 100000)
 *    Number of period
 * 
 * optInFastK_Period:(From 1 to 100000)
 *    Time period for building the Fast-K line
 * 
 * optInFastD_Period:(From 1 to 100000)
 *    Smoothing for making the Fast-D line. Usually set to 3
 * 
 * optInFastD_MAType:
 *    Type of Moving Average for Fast-D
 * 
 * 
 */
/* Generated */ 
/* Generated */ #if defined( _MANAGED )
/* Generated */ enum Core::TA_RetCode Core::STOCHRSI( int    startIdx,
/* Generated */                                       int    endIdx,
/* Generated */                                       double       inReal __gc [],
/* Generated */                                       int           optInTimePeriod, /* From 2 to 100000 */
/* Generated */                                       int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                                       int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                                       TA_MAType     optInFastD_MAType,
/* Generated */                                       [OutAttribute]Int32 *outBegIdx,
/* Generated */                                       [OutAttribute]Int32 *outNbElement,
/* Generated */                                       double        outFastK __gc [],
/* Generated */                                       double        outFastD __gc [] )
/* Generated */ #else
/* Generated */ TA_RetCode TA_STOCHRSI( int    startIdx,
/* Generated */                         int    endIdx,
/* Generated */                         const double inReal[],
/* Generated */                         int           optInTimePeriod, /* From 2 to 100000 */
/* Generated */                         int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                         int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                         TA_MAType     optInFastD_MAType,
/* Generated */                         int          *outBegIdx,
/* Generated */                         int          *outNbElement,
/* Generated */                         double        outFastK[],
/* Generated */                         double        outFastD[] )
/* Generated */ #endif
/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
{
   /* insert local variable here */
   ARRAY_REF(tempRSIBuffer);

   TA_RetCode retCode;
   int lookbackTotal, lookbackSTOCHF, tempArraySize;
   int outBegIdx1, outBegIdx2, outNbElement1;

/**** START GENCODE SECTION 3 - 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 TA_OUT_OF_RANGE_START_INDEX;
/* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
/* Generated */       return TA_OUT_OF_RANGE_END_INDEX;
/* Generated */ 
/* Generated */    /* Validate the parameters. */
/* Generated */    if( !inReal ) return TA_BAD_PARAM;
/* Generated */    /* min/max are checked for optInTimePeriod. */
/* Generated */    if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
/* Generated */       optInTimePeriod = 14;
/* Generated */    else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */    /* min/max are checked for optInFastK_Period. */
/* Generated */    if( (int)optInFastK_Period == TA_INTEGER_DEFAULT )
/* Generated */       optInFastK_Period = 5;
/* Generated */    else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) )
/* Generated */       return TA_BAD_PARAM;
/* 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 TA_BAD_PARAM;
/* Generated */ 
/* Generated */    #if !defined(_MANAGED)
/* Generated */    if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT )
/* Generated */       optInFastD_MAType = 0;
/* Generated */    else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */    #endif /* !defined(_MANAGED) */
/* Generated */    if( outFastK == NULL )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */    if( outFastD == NULL )
/* Generated */       return TA_BAD_PARAM;
/* Generated */ 
/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
/* Generated */ 
/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/

   /* Insert TA function code here. */
  
   /* Stochastic RSI
    * 
    * Reference: "Stochastic RSI and Dynamic Momentum Index"
    *            by <NAME> and <NAME>
    *            Stock&Commodities V.11:5 (189-199)
    *
    * The TA-Lib version offer flexibility beyond what is explain
    * in the Stock&Commodities article.
    *
    * To calculate the "Unsmoothed stochastic RSI" with symmetry like 
    * explain in the article, keep the optInTimePeriod and optInFastK_Period
    * equal. Example:
    *        
    *    unsmoothed stoch RSI 14 : optInTimePeriod   = 14
    *                              optInFastK_Period = 14
    *                              optInFastD_Period = 'x'
    *
    * The outFastK is the unsmoothed RSI discuss in the article.
    *
    * You can set the optInFastD_Period to smooth the RSI. The smooth
    * version will be found in outFastD. The outFastK will still contain
    * the unsmoothed stoch RSI. If you do not care about the smoothing of
    * the StochRSI, just leave optInFastD_Period to 1 and ignore outFastD.
    */

   *outBegIdx    = 0;
   *outNbElement = 0;

   /* Adjust startIdx to account for the lookback period. */
   lookbackSTOCHF  = TA_STOCHF_Lookback( optInFastK_Period, optInFastD_Period, optInFastD_MAType );
   lookbackTotal   = TA_RSI_Lookback( optInTimePeriod ) + lookbackSTOCHF;

   if( startIdx < lookbackTotal )
      startIdx = lookbackTotal;

   /* Make sure there is still something to evaluate. */
   if( startIdx > endIdx )
   {
      *outBegIdx = 0;
      *outNbElement = 0;
      return TA_SUCCESS;
   }

   *outBegIdx = startIdx;

   tempArraySize = (endIdx - startIdx) + 1 + lookbackSTOCHF;

   ARRAY_ALLOC( tempRSIBuffer, tempArraySize );

   retCode = TA_PREFIX(RSI)(startIdx-lookbackSTOCHF, 
                            endIdx, 
                            inReal, 
                            optInTimePeriod, 
                            &outBegIdx1, 
                            &outNbElement1, 
                            tempRSIBuffer);

   if( retCode != TA_SUCCESS || outNbElement1 == 0 )
   {
      ARRAY_FREE( tempRSIBuffer );
      *outBegIdx = 0;
      *outNbElement = 0;
      return retCode;
   }
   
   retCode = TA_STOCHF(0,
                       tempArraySize-1,
                       tempRSIBuffer,
                       tempRSIBuffer,
                       tempRSIBuffer,
                       optInFastK_Period,
                       optInFastD_Period,
                       optInFastD_MAType,
                       &outBegIdx2,
                       outNbElement,
                       outFastK,
                       outFastD);
 
   ARRAY_FREE( tempRSIBuffer );

   if( retCode != TA_SUCCESS || outNbElement == 0 )
   {
      *outBegIdx = 0;
      *outNbElement = 0;
      return retCode;
   }

   return TA_SUCCESS;
}

/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
/* Generated */ 
/* Generated */ #define  USE_SINGLE_PRECISION_INPUT
/* Generated */ #if !defined( _MANAGED )
/* 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 Core::TA_RetCode Core::STOCHRSI( int    startIdx,
/* Generated */                                       int    endIdx,
/* Generated */                                       float        inReal __gc [],
/* Generated */                                       int           optInTimePeriod, /* From 2 to 100000 */
/* Generated */                                       int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                                       int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                                       TA_MAType     optInFastD_MAType,
/* Generated */                                       [OutAttribute]Int32 *outBegIdx,
/* Generated */                                       [OutAttribute]Int32 *outNbElement,
/* Generated */                                       double        outFastK __gc [],
/* Generated */                                       double        outFastD __gc [] )
/* Generated */ #else
/* Generated */ TA_RetCode TA_S_STOCHRSI( int    startIdx,
/* Generated */                           int    endIdx,
/* Generated */                           const float  inReal[],
/* Generated */                           int           optInTimePeriod, /* From 2 to 100000 */
/* Generated */                           int           optInFastK_Period, /* From 1 to 100000 */
/* Generated */                           int           optInFastD_Period, /* From 1 to 100000 */
/* Generated */                           TA_MAType     optInFastD_MAType,
/* Generated */                           int          *outBegIdx,
/* Generated */                           int          *outNbElement,
/* Generated */                           double        outFastK[],
/* Generated */                           double        outFastD[] )
/* Generated */ #endif
/* Generated */ {
/* Generated */    ARRAY_REF(tempRSIBuffer);
/* Generated */    TA_RetCode retCode;
/* Generated */    int lookbackTotal, lookbackSTOCHF, tempArraySize;
/* Generated */    int outBegIdx1, outBegIdx2, outNbElement1;
/* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
/* Generated */     if( startIdx < 0 )
/* Generated */        return TA_OUT_OF_RANGE_START_INDEX;
/* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
/* Generated */        return TA_OUT_OF_RANGE_END_INDEX;
/* Generated */     if( !inReal ) return TA_BAD_PARAM;
/* Generated */     if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
/* Generated */        optInTimePeriod = 14;
/* Generated */     else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
/* Generated */        return TA_BAD_PARAM;
/* Generated */     if( (int)optInFastK_Period == TA_INTEGER_DEFAULT )
/* Generated */        optInFastK_Period = 5;
/* Generated */     else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) )
/* Generated */        return TA_BAD_PARAM;
/* 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 TA_BAD_PARAM;
/* Generated */     #if !defined(_MANAGED)
/* Generated */     if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT )
/* Generated */        optInFastD_MAType = 0;
/* Generated */     else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) )
/* Generated */        return TA_BAD_PARAM;
/* Generated */     #endif 
/* Generated */     if( outFastK == NULL )
/* Generated */        return TA_BAD_PARAM;
/* Generated */     if( outFastD == NULL )
/* Generated */        return TA_BAD_PARAM;
/* Generated */  #endif 
/* Generated */    *outBegIdx    = 0;
/* Generated */    *outNbElement = 0;
/* Generated */    lookbackSTOCHF  = TA_STOCHF_Lookback( optInFastK_Period, optInFastD_Period, optInFastD_MAType );
/* Generated */    lookbackTotal   = TA_RSI_Lookback( optInTimePeriod ) + lookbackSTOCHF;
/* Generated */    if( startIdx < lookbackTotal )
/* Generated */       startIdx = lookbackTotal;
/* Generated */    if( startIdx > endIdx )
/* Generated */    {
/* Generated */       *outBegIdx = 0;
/* Generated */       *outNbElement = 0;
/* Generated */       return TA_SUCCESS;
/* Generated */    }
/* Generated */    *outBegIdx = startIdx;
/* Generated */    tempArraySize = (endIdx - startIdx) + 1 + lookbackSTOCHF;
/* Generated */    ARRAY_ALLOC( tempRSIBuffer, tempArraySize );
/* Generated */    retCode = TA_PREFIX(RSI)(startIdx-lookbackSTOCHF, 
/* Generated */                             endIdx, 
/* Generated */                             inReal, 
/* Generated */                             optInTimePeriod, 
/* Generated */                             &outBegIdx1, 
/* Generated */                             &outNbElement1, 
/* Generated */                             tempRSIBuffer);
/* Generated */    if( retCode != TA_SUCCESS || outNbElement1 == 0 )
/* Generated */    {
/* Generated */       ARRAY_FREE( tempRSIBuffer );
/* Generated */       *outBegIdx = 0;
/* Generated */       *outNbElement = 0;
/* Generated */       return retCode;
/* Generated */    }
/* Generated */    retCode = TA_STOCHF(0,
/* Generated */                        tempArraySize-1,
/* Generated */                        tempRSIBuffer,
/* Generated */                        tempRSIBuffer,
/* Generated */                        tempRSIBuffer,
/* Generated */                        optInFastK_Period,
/* Generated */                        optInFastD_Period,
/* Generated */                        optInFastD_MAType,
/* Generated */                        &outBegIdx2,
/* Generated */                        outNbElement,
/* Generated */                        outFastK,
/* Generated */                        outFastD);
/* Generated */    ARRAY_FREE( tempRSIBuffer );
/* Generated */    if( retCode != TA_SUCCESS || outNbElement == 0 )
/* Generated */    {
/* Generated */       *outBegIdx = 0;
/* Generated */       *outNbElement = 0;
/* Generated */       return retCode;
/* Generated */    }
/* Generated */    return TA_SUCCESS;
{'fraction_non_alphanumeric': 0.12142302493457191, 'fraction_numerical': 0.014926231629806448, 'mean_word_length': 1.797875764402961, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 110, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6510036', 'n_tokens_mistral': 10817, 'n_tokens_neox': 9503, 'n_words': 2642}