/* TA-LIB Copyright (c) 1999-2026, Mario Fortier * 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. */ /* AUTO-GENERATED by ta_codegen — DO NOT EDIT. * Source of truth: ta_codegen/input// (regenerate: cd ta_codegen/generator && cargo run -- generate) */ #include #include #include "ta_func.h" #include "ta_utility.h" #include "ta_memory.h" #include "ta_func_stream_private.h" /* List of contributors: * * Initial Name/description * ------------------------------------------------------------------- * MF Mario Fortier * CC Claude Code (AI assistant) * * Change history: * * MMDDYY BY Description * ------------------------------------------------------------------- * 112400 MF Template creation. * 052603 MF Adapt code to compile with .NET Managed C++ * 062804 MF Resolve div by zero bug on limit case. * 082326 MF,CC Fix #253. Test the gain+loss total exactly instead of against * the fixed TA_IS_ZERO band, which zeroed the index for any * instrument quoted small enough to fall under it. * 090926 MF,CC #410 Scale the Wilder step by a hoisted 1/period and split the * gain/loss without a branch; the loop-carried chain keeps * neither a divide nor a 50/50 mispredict. * 092826 MF,CC #466 Drop the period-1 copy-through; the range starts at 2. * 093026 MF,CC #480 Answer the neutral 50 instead of 0 when neither a gain nor * a loss has been seen; 0 read as extremely oversold. */ TA_NOINLINE TA_LIB_API int TA_RSI_Lookback( int optInTimePeriod ) { if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) optInTimePeriod = 14; else if( (int)optInTimePeriod < 2 || (int)optInTimePeriod > 100000 ) return -1; return optInTimePeriod + TA_GLOBALS_UNSTABLE(TA_FUNC_UNST_RSI,Rsi,((optInTimePeriod > 1) ? 10 * optInTimePeriod : 0),((optInTimePeriod > 1) ? 19 * optInTimePeriod : 0)); } TA_LIB_API int TA_RSI_DisplayShift( int optInTimePeriod, int outputIdx ) { if( TA_RSI_Lookback( optInTimePeriod ) < 0 ) return INT_MIN; if( outputIdx < 0 || outputIdx >= 1 ) return INT_MIN; return 0; } TA_LIB_API TA_RetCode TA_RSI( int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[] ) { int outIdx; int today; int lookbackTotal; int i; double gainDelta; double invPeriod; double prevGain; double prevLoss; double prevValue; double tempValue1; double tempValue2; if( (startIdx < 0) || (startIdx > TA_INDEX_MAX) ) return TA_OUT_OF_RANGE_START_INDEX; if( (endIdx < 0) || (endIdx > TA_INDEX_MAX) || (endIdx < startIdx) ) return TA_OUT_OF_RANGE_END_INDEX; if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) optInTimePeriod = 14; else if( (int)optInTimePeriod < 2 || (int)optInTimePeriod > 100000 ) return TA_BAD_PARAM; if( !inReal ) return TA_BAD_PARAM; if( !outBegIdx || !outNBElement ) return TA_BAD_PARAM; if( !outReal ) return TA_BAD_PARAM; /* The following algorithm is base on the original * work from Wilder's and shall represent the * original idea behind the classic RSI. */ *outBegIdx= 0; *outNBElement= 0; /* Adjust startIdx to account for the lookback period. */ lookbackTotal = (int)TA_RSI_Lookback(optInTimePeriod); if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } /* Make sure there is still something to evaluate. */ if( startIdx > endIdx ) { return TA_SUCCESS; } outIdx = 0; /* Index into the output. */ invPeriod = 1.0 / (double)optInTimePeriod; /* Accumulate Wilder's "Average Gain" and "Average Loss" * among the initial period. */ today = startIdx - lookbackTotal; prevValue = (double)inReal[today]; prevGain = 0.0; prevLoss = 0.0; today = today + 1; for( i = optInTimePeriod; i > 0; i -= 1 ) { tempValue1 = (double)inReal[today]; today = today + 1; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; } /* Subsequent prevLoss and prevGain are smoothed * using the previous values (Wilder's approach). * 1) Multiply the previous by 'period-1'. * 2) Add today's gain to one accumulator and today's loss to the other, * both unconditionally: gainDelta - tempValue2 is the exact loss delta * for every finite tempValue2, so no branch on a 50/50 predicate. * 3) Scale by 1/'period'. */ prevLoss *= invPeriod; prevGain *= invPeriod; /* Often documentation present the RSI calculation as follow: * RSI = 100 - (100 / 1 + (prevGain/prevLoss)) * * The following is equivalent: * RSI = 100 * (prevGain/(prevGain+prevLoss)) * * The second equation is used here for speed optimization. * * prevGain+prevLoss is a sum of non-negative magnitudes, so it is zero when * every change since the seed was exactly zero, or once both have decayed to * zero. Test it exactly, never against a fixed band: a gain carries the * quote unit, so a constant put against it zeroes a healthy oscillator for * an instrument quoted below it (issue #253). * * A zero total is 0/0, no gain against no loss, so it answers the neutral * 50 (issue #480). Keep it apart from the one-sided cases, which are 0 and * 100 and reach the division. */ if( today > startIdx ) { tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { outReal[outIdx] = 100.0 * (prevGain / tempValue1); outIdx = outIdx + 1; } else { outReal[outIdx] = 50.0; outIdx = outIdx + 1; } } else { /* Skip the unstable period. Do the processing * but do not write it in the output. */ while( today < startIdx ) { tempValue1 = (double)inReal[today]; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(optInTimePeriod - 1); prevGain *= (double)(optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= invPeriod; prevGain *= invPeriod; today = today + 1; } } /* Unstable period skipped... now continue * processing if needed. */ while( today <= endIdx ) { tempValue1 = (double)inReal[today]; today = today + 1; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(optInTimePeriod - 1); prevGain *= (double)(optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= invPeriod; prevGain *= invPeriod; tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { outReal[outIdx] = 100.0 * (prevGain / tempValue1); outIdx = outIdx + 1; } else { outReal[outIdx] = 50.0; outIdx = outIdx + 1; } } *outBegIdx= startIdx; *outNBElement= outIdx; return TA_SUCCESS; } TA_RetCode TA_S_RSI( int startIdx, int endIdx, const float inReal[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[] ) { int outIdx; int today; int lookbackTotal; int i; double gainDelta; double invPeriod; double prevGain; double prevLoss; double prevValue; double tempValue1; double tempValue2; if( (startIdx < 0) || (startIdx > TA_INDEX_MAX) ) return TA_OUT_OF_RANGE_START_INDEX; if( (endIdx < 0) || (endIdx > TA_INDEX_MAX) || (endIdx < startIdx) ) return TA_OUT_OF_RANGE_END_INDEX; if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) optInTimePeriod = 14; else if( (int)optInTimePeriod < 2 || (int)optInTimePeriod > 100000 ) return TA_BAD_PARAM; if( !inReal ) return TA_BAD_PARAM; if( !outBegIdx || !outNBElement ) return TA_BAD_PARAM; if( !outReal ) return TA_BAD_PARAM; *outBegIdx= 0; *outNBElement= 0; lookbackTotal = (int)TA_RSI_Lookback(optInTimePeriod); if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } if( startIdx > endIdx ) { return TA_SUCCESS; } outIdx = 0; invPeriod = 1.0 / (double)optInTimePeriod; today = startIdx - lookbackTotal; prevValue = (double)inReal[today]; prevGain = 0.0; prevLoss = 0.0; today = today + 1; for( i = optInTimePeriod; i > 0; i -= 1 ) { tempValue1 = (double)inReal[today]; today = today + 1; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; } prevLoss *= invPeriod; prevGain *= invPeriod; if( today > startIdx ) { tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { outReal[outIdx] = 100.0 * (prevGain / tempValue1); outIdx = outIdx + 1; } else { outReal[outIdx] = 50.0; outIdx = outIdx + 1; } } else { while( today < startIdx ) { tempValue1 = (double)inReal[today]; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(optInTimePeriod - 1); prevGain *= (double)(optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= invPeriod; prevGain *= invPeriod; today = today + 1; } } while( today <= endIdx ) { tempValue1 = (double)inReal[today]; today = today + 1; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(optInTimePeriod - 1); prevGain *= (double)(optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= invPeriod; prevGain *= invPeriod; tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { outReal[outIdx] = 100.0 * (prevGain / tempValue1); outIdx = outIdx + 1; } else { outReal[outIdx] = 50.0; outIdx = outIdx + 1; } } *outBegIdx= startIdx; *outNBElement= outIdx; return TA_SUCCESS; } /**** Streaming API *****/ struct TA_RSI_Stream { /* The bars this handle has an output for (see TA_RSI_OutRange). */ int outRangeBegIdx; int outRangeCount; /* The value(s) at the last bar the stream counted (see TA_RSI_Value). */ double cur_outReal; int optInTimePeriod; double invPeriod; double pad_0; double prevGain; double prevLoss; double prevValue; }; /* Private function, not in public API. */ static void TA_RSI_StepImpl( struct TA_RSI_Stream *sp, double inReal, double *outReal ) { double gainDelta; double tempValue1; double tempValue2; tempValue1 = (double)inReal; tempValue2 = tempValue1 - sp->prevValue; sp->prevValue = tempValue1; sp->prevLoss *= (double)(sp->optInTimePeriod - 1); sp->prevGain *= (double)(sp->optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; sp->prevGain += gainDelta; sp->prevLoss += gainDelta - tempValue2; sp->prevLoss *= sp->invPeriod; sp->prevGain *= sp->invPeriod; tempValue1 = sp->prevGain + sp->prevLoss; if( tempValue1 > 0.0 ) { *outReal= 100.0 * (sp->prevGain / tempValue1); } else { *outReal= 50.0; } sp->cur_outReal = *outReal; } static TA_RetCode TA_RSI_OpenImpl( struct TA_RSI_Stream **stream, const double inReal[], int startIdx, int historyLen, int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[], int outStride ) { struct TA_RSI_Stream *sp; int endIdx; if( !stream ) return TA_BAD_PARAM; *stream = NULL; if( historyLen < 1 ) return TA_OUT_OF_RANGE_START_INDEX; if( historyLen > TA_INDEX_MAX + 1 ) return TA_OUT_OF_RANGE_END_INDEX; if( !inReal || !outReal ) return TA_BAD_PARAM; if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) optInTimePeriod = 14; else if( (int)optInTimePeriod < 2 || (int)optInTimePeriod > 100000 ) return TA_BAD_PARAM; if( startIdx > historyLen - 1 ) { *outBegIdx = 0; *outNBElement = 0; return TA_INSUFFICIENT_HISTORY; } endIdx = historyLen - 1; { int outIdx; int today; int lookbackTotal; int i; double gainDelta; double invPeriod = 0.0; double prevGain = 0.0; double prevLoss = 0.0; double prevValue = 0.0; double tempValue1; double tempValue2; /* The following algorithm is base on the original * work from Wilder's and shall represent the * original idea behind the classic RSI. */ *outBegIdx= 0; *outNBElement= 0; /* Adjust startIdx to account for the lookback period. */ lookbackTotal = (int)TA_RSI_Lookback(optInTimePeriod); if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } /* Make sure there is still something to evaluate. */ if( startIdx > endIdx ) { return TA_INSUFFICIENT_HISTORY; } outIdx = 0; /* Index into the output. */ invPeriod = 1.0 / (double)optInTimePeriod; /* Accumulate Wilder's "Average Gain" and "Average Loss" * among the initial period. */ today = startIdx - lookbackTotal; prevValue = (double)inReal[today]; prevGain = 0.0; prevLoss = 0.0; today = today + 1; for( i = optInTimePeriod; i > 0; i -= 1 ) { tempValue1 = (double)inReal[today]; today = today + 1; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; } /* Subsequent prevLoss and prevGain are smoothed * using the previous values (Wilder's approach). * 1) Multiply the previous by 'period-1'. * 2) Add today's gain to one accumulator and today's loss to the other, * both unconditionally: gainDelta - tempValue2 is the exact loss delta * for every finite tempValue2, so no branch on a 50/50 predicate. * 3) Scale by 1/'period'. */ prevLoss *= invPeriod; prevGain *= invPeriod; /* Often documentation present the RSI calculation as follow: * RSI = 100 - (100 / 1 + (prevGain/prevLoss)) * * The following is equivalent: * RSI = 100 * (prevGain/(prevGain+prevLoss)) * * The second equation is used here for speed optimization. * * prevGain+prevLoss is a sum of non-negative magnitudes, so it is zero when * every change since the seed was exactly zero, or once both have decayed to * zero. Test it exactly, never against a fixed band: a gain carries the * quote unit, so a constant put against it zeroes a healthy oscillator for * an instrument quoted below it (issue #253). * * A zero total is 0/0, no gain against no loss, so it answers the neutral * 50 (issue #480). Keep it apart from the one-sided cases, which are 0 and * 100 and reach the division. */ if( today > startIdx ) { tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { outReal[outIdx * outStride] = 100.0 * (prevGain / tempValue1); outIdx = outIdx + 1; } else { outReal[outIdx * outStride] = 50.0; outIdx = outIdx + 1; } } else { /* Skip the unstable period. Do the processing * but do not write it in the output. */ while( today < startIdx ) { tempValue1 = (double)inReal[today]; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(optInTimePeriod - 1); prevGain *= (double)(optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= invPeriod; prevGain *= invPeriod; today = today + 1; } } /* Unstable period skipped... now continue * processing if needed. */ while( today <= endIdx ) { tempValue1 = (double)inReal[today]; today = today + 1; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(optInTimePeriod - 1); prevGain *= (double)(optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= invPeriod; prevGain *= invPeriod; tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { outReal[outIdx * outStride] = 100.0 * (prevGain / tempValue1); outIdx = outIdx + 1; } else { outReal[outIdx * outStride] = 50.0; outIdx = outIdx + 1; } } *outBegIdx= startIdx; *outNBElement= outIdx; /* Capture the live batch state into the handle. */ sp = (struct TA_RSI_Stream *)TA_Malloc( sizeof(*sp) ); if( !sp ) { return TA_ALLOC_ERR; } memset( sp, 0, sizeof(*sp) ); sp->optInTimePeriod = optInTimePeriod; sp->invPeriod = invPeriod; sp->prevGain = prevGain; sp->prevLoss = prevLoss; sp->prevValue = prevValue; sp->outRangeBegIdx = *outBegIdx; sp->outRangeCount = *outNBElement; sp->cur_outReal = outReal[(*outNBElement - 1) * outStride]; *stream = sp; return TA_SUCCESS; } } /* Private function, not in public API. */ TA_RetCode TA_RSI_OpenInternal( struct TA_RSI_Stream **stream, const double inReal[], int startIdx, int historyLen, int optInTimePeriod, double *outReal ) { TA_RetCode retCode; int dummyBegIdx = 0; int dummyNBElement = 0; double sink_outReal = 0.0; retCode = TA_RSI_OpenImpl( stream, inReal, startIdx, historyLen, optInTimePeriod, &dummyBegIdx, &dummyNBElement, &sink_outReal, 0 ); if( retCode == TA_SUCCESS ) { *outReal = sink_outReal; } return retCode; } TA_LIB_API TA_RetCode TA_RSI_Open( TA_RSI_Stream **stream, const double inReal[], int historyLen, int optInTimePeriod, double *outReal ) { if( !stream ) return TA_BAD_PARAM; *stream = NULL; if( historyLen < 1 ) return TA_OUT_OF_RANGE_START_INDEX; if( historyLen > TA_INDEX_MAX + 1 ) return TA_OUT_OF_RANGE_END_INDEX; if( !inReal || !outReal ) return TA_BAD_PARAM; return TA_RSI_OpenInternal( stream, inReal, 0, historyLen, optInTimePeriod, outReal ); } TA_LIB_API TA_RetCode TA_RSI_OpenAndFill( TA_RSI_Stream **stream, const double inReal[], int historyLen, int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[] ) { if( !stream ) return TA_BAD_PARAM; *stream = NULL; if( historyLen < 1 ) return TA_OUT_OF_RANGE_START_INDEX; if( historyLen > TA_INDEX_MAX + 1 ) return TA_OUT_OF_RANGE_END_INDEX; if( !inReal || !outBegIdx || !outNBElement || !outReal ) return TA_BAD_PARAM; if( (const void *)outReal == (const void *)inReal ) return TA_BAD_PARAM; return TA_RSI_OpenAndFillInternal( stream, inReal, 0, historyLen, optInTimePeriod, outBegIdx, outNBElement, outReal ); } /* Private function, not in public API. */ TA_RetCode TA_RSI_OpenAndFillInternal( struct TA_RSI_Stream **stream, const double inReal[], int startIdx, int historyLen, int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[] ) { return TA_RSI_OpenImpl( stream, inReal, startIdx, historyLen, optInTimePeriod, outBegIdx, outNBElement, outReal, 1 ); } TA_LIB_API TA_RetCode TA_RSI_Update( TA_RSI_Stream *stream, double inReal, double *outReal ) { if( !stream ) return TA_BAD_PARAM; if( stream->outRangeBegIdx + stream->outRangeCount > TA_INDEX_MAX ) return TA_OUT_OF_RANGE_END_INDEX; if( !outReal ) return TA_BAD_PARAM; if( !TA_IS_FINITE( inReal ) ) return TA_BAD_PARAM; TA_RSI_StepImpl( stream, inReal, outReal ); stream->outRangeCount++; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_RSI_Peek( const TA_RSI_Stream *stream, double inReal, double *outReal ) { const struct TA_RSI_Stream *sp = stream; double gainDelta; double tempValue1; double tempValue2; double prevGain; double prevLoss; double prevValue; if( !stream || !outReal ) return TA_BAD_PARAM; if( !TA_IS_FINITE( inReal ) ) return TA_BAD_PARAM; prevGain = sp->prevGain; prevLoss = sp->prevLoss; prevValue = sp->prevValue; tempValue1 = (double)inReal; tempValue2 = tempValue1 - prevValue; prevValue = tempValue1; prevLoss *= (double)(sp->optInTimePeriod - 1); prevGain *= (double)(sp->optInTimePeriod - 1); gainDelta = (tempValue2 > 0.0) ? tempValue2 : 0.0; prevGain += gainDelta; prevLoss += gainDelta - tempValue2; prevLoss *= sp->invPeriod; prevGain *= sp->invPeriod; tempValue1 = prevGain + prevLoss; if( tempValue1 > 0.0 ) { *outReal= 100.0 * (prevGain / tempValue1); } else { *outReal= 50.0; } return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_RSI_Close( TA_RSI_Stream *stream ) { if( stream ) TA_Free( stream ); return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_RSI_Value( const TA_RSI_Stream *stream, double *outReal ) { if( !stream || !outReal ) return TA_BAD_PARAM; *outReal = stream->cur_outReal; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_RSI_OutRange( const TA_RSI_Stream *stream, int *outBegIdx, int *outNBElement ) { if( !stream || !outBegIdx || !outNBElement ) return TA_BAD_PARAM; *outBegIdx = stream->outRangeBegIdx; *outNBElement = stream->outRangeCount; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_RSI_Advance( TA_RSI_Stream *stream ) { if( !stream ) return TA_BAD_PARAM; if( stream->outRangeBegIdx + stream->outRangeCount > TA_INDEX_MAX ) return TA_OUT_OF_RANGE_END_INDEX; stream->outRangeCount++; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_RSI_Clone( const TA_RSI_Stream *stream, TA_RSI_Stream **clone ) { struct TA_RSI_Stream *sp; if( !clone ) return TA_BAD_PARAM; *clone = NULL; if( !stream ) return TA_BAD_PARAM; sp = (struct TA_RSI_Stream *)TA_Malloc( sizeof(*sp) ); if( !sp ) return TA_ALLOC_ERR; *sp = *stream; *clone = sp; return TA_SUCCESS; }