/* 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 * ------------------------------------------------------------------- * AC Angelo Ciceri * * * Change history: * * MMDDYY BY Description * ------------------------------------------------------------------- * 011605 AC Creation */ TA_LIB_API int TA_CDLTASUKIGAP_Lookback( void ) { int Near_avgPeriod = TA_Globals->candleSettings[TA_Near].avgPeriod; return Near_avgPeriod + 2; } TA_LIB_API int TA_CDLTASUKIGAP_DisplayShift( int outputIdx ) { if( outputIdx < 0 || outputIdx >= 1 ) return INT_MIN; return 0; } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP( int startIdx, int endIdx, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int *outBegIdx, int *outNBElement, int outInteger[] ) { double NearPeriodTotal; int i; int outIdx; int NearTrailingIdx; int lookbackTotal; int Near_avgPeriod = TA_Globals->candleSettings[TA_Near].avgPeriod; 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( !inOpen ) return TA_BAD_PARAM; if( !inHigh ) return TA_BAD_PARAM; if( !inLow ) return TA_BAD_PARAM; if( !inClose ) return TA_BAD_PARAM; if( !outBegIdx || !outNBElement ) return TA_BAD_PARAM; if( !outInteger ) return TA_BAD_PARAM; /* Identify the minimum number of price bar needed * to calculate at least one output. */ lookbackTotal = TA_CDLTASUKIGAP_Lookback(); /* Move up the start index if there is not * enough initial data. */ if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } /* Make sure there is still something to evaluate. */ if( startIdx > endIdx ) { *outBegIdx= 0; *outNBElement= 0; return TA_SUCCESS; } /* Do the calculation using tight loops. */ /* Add-up the initial period, except for the last value. */ NearPeriodTotal = 0; NearTrailingIdx = startIdx - Near_avgPeriod; i = NearTrailingIdx; while( i < startIdx ) { NearPeriodTotal += TA_CANDLERANGE(Near,i - 1); i += 1; } i = startIdx; /* Proceed with the calculation for the requested range. * Must have: * - upside (downside) gap * - first candle after the window: white (black) candlestick * - second candle: black (white) candlestick that opens within the previous real body and closes under (above) * the previous real body inside the gap * - the size of two real bodies should be near the same * The meaning of "near" is specified with TA_SetCandleSettings * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; * the user should consider that tasuki gap is significant when it appears in a trend, while this function does * not consider it */ outIdx = 0; do { if( (((min(inOpen[i - 1],inClose[i - 1]) > max(inOpen[i - 2],inClose[i - 2])) ? 1 : 0) && /* upside gap */ ((inClose[i - 1] >= inOpen[i - 1]) ? 1 : -1) == 1 && /* 1st: white */ ((inClose[i] >= inOpen[i]) ? 1 : -1) == -1 && /* 2nd: black */ inOpen[i] < inClose[i - 1] && inOpen[i] > inOpen[i - 1] && /* that opens within the white rb */ inClose[i] < inOpen[i - 1] && /* and closes under the white rb */ inClose[i] > max(inClose[i - 2],inOpen[i - 2]) && /* inside the gap */ fabs(fabs(inClose[i - 1] - inOpen[i - 1]) - fabs(inClose[i] - inOpen[i])) < TA_CANDLEAVERAGE(Near,NearPeriodTotal,i - 1)) || /* size of 2 rb near the same */ (((max(inOpen[i - 1],inClose[i - 1]) < min(inOpen[i - 2],inClose[i - 2])) ? 1 : 0) && /* downside gap */ ((inClose[i - 1] >= inOpen[i - 1]) ? 1 : -1) == -1 && /* 1st: black */ ((inClose[i] >= inOpen[i]) ? 1 : -1) == 1 && /* 2nd: white */ inOpen[i] < inOpen[i - 1] && inOpen[i] > inClose[i - 1] && /* that opens within the black rb */ inClose[i] > inOpen[i - 1] && /* and closes above the black rb */ inClose[i] < min(inClose[i - 2],inOpen[i - 2]) && /* inside the gap */ fabs(fabs(inClose[i - 1] - inOpen[i - 1]) - fabs(inClose[i] - inOpen[i])) < TA_CANDLEAVERAGE(Near,NearPeriodTotal,i - 1)) ) /* size of 2 rb near the same */ { outInteger[outIdx++] = ((inClose[i - 1] >= inOpen[i - 1]) ? 1 : -1) * 100; } else { outInteger[outIdx++] = 0; } /* add the current range and subtract the first range: this is done after the pattern recognition * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) */ NearPeriodTotal += TA_CANDLERANGE(Near,i - 1) - TA_CANDLERANGE(Near,NearTrailingIdx - 1); i += 1; NearTrailingIdx += 1; } while( i <= endIdx ); /* All done. Indicate the output limits and return. */ *outNBElement= outIdx; *outBegIdx= startIdx; return TA_SUCCESS; } TA_RetCode TA_S_CDLTASUKIGAP( int startIdx, int endIdx, const float inOpen[], const float inHigh[], const float inLow[], const float inClose[], int *outBegIdx, int *outNBElement, int outInteger[] ) { double NearPeriodTotal; int i; int outIdx; int NearTrailingIdx; int lookbackTotal; int Near_avgPeriod = TA_Globals->candleSettings[TA_Near].avgPeriod; 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( !inOpen ) return TA_BAD_PARAM; if( !inHigh ) return TA_BAD_PARAM; if( !inLow ) return TA_BAD_PARAM; if( !inClose ) return TA_BAD_PARAM; if( !outBegIdx || !outNBElement ) return TA_BAD_PARAM; if( !outInteger ) return TA_BAD_PARAM; lookbackTotal = TA_CDLTASUKIGAP_Lookback(); if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } if( startIdx > endIdx ) { *outBegIdx= 0; *outNBElement= 0; return TA_SUCCESS; } NearPeriodTotal = 0; NearTrailingIdx = startIdx - Near_avgPeriod; i = NearTrailingIdx; while( i < startIdx ) { NearPeriodTotal += TA_CANDLERANGE(Near,i - 1); i += 1; } i = startIdx; outIdx = 0; do { if( (((min((double)inOpen[i - 1],(double)inClose[i - 1]) > max((double)inOpen[i - 2],(double)inClose[i - 2])) ? 1 : 0) && (((double)inClose[i - 1] >= (double)inOpen[i - 1]) ? 1 : -1) == 1 && (((double)inClose[i] >= (double)inOpen[i]) ? 1 : -1) == -1 && (double)inOpen[i] < (double)inClose[i - 1] && (double)inOpen[i] > (double)inOpen[i - 1] && (double)inClose[i] < (double)inOpen[i - 1] && (double)inClose[i] > max((double)inClose[i - 2],(double)inOpen[i - 2]) && fabs(fabs((double)inClose[i - 1] - (double)inOpen[i - 1]) - fabs((double)inClose[i] - (double)inOpen[i])) < TA_CANDLEAVERAGE(Near,NearPeriodTotal,i - 1)) || (((max((double)inOpen[i - 1],(double)inClose[i - 1]) < min((double)inOpen[i - 2],(double)inClose[i - 2])) ? 1 : 0) && (((double)inClose[i - 1] >= (double)inOpen[i - 1]) ? 1 : -1) == -1 && (((double)inClose[i] >= (double)inOpen[i]) ? 1 : -1) == 1 && (double)inOpen[i] < (double)inOpen[i - 1] && (double)inOpen[i] > (double)inClose[i - 1] && (double)inClose[i] > (double)inOpen[i - 1] && (double)inClose[i] < min((double)inClose[i - 2],(double)inOpen[i - 2]) && fabs(fabs((double)inClose[i - 1] - (double)inOpen[i - 1]) - fabs((double)inClose[i] - (double)inOpen[i])) < TA_CANDLEAVERAGE(Near,NearPeriodTotal,i - 1)) ) { outInteger[outIdx++] = (((double)inClose[i - 1] >= (double)inOpen[i - 1]) ? 1 : -1) * 100; } else { outInteger[outIdx++] = 0; } NearPeriodTotal += TA_CANDLERANGE(Near,i - 1) - TA_CANDLERANGE(Near,NearTrailingIdx - 1); i += 1; NearTrailingIdx += 1; } while( i <= endIdx ); *outNBElement= outIdx; *outBegIdx= startIdx; return TA_SUCCESS; } /**** Streaming API *****/ struct TA_CDLTASUKIGAP_Stream { /* The bars this handle has an output for (see TA_CDLTASUKIGAP_OutRange). */ int outRangeBegIdx; int outRangeCount; /* The value(s) at the last bar the stream counted (see TA_CDLTASUKIGAP_Value). */ int cur_outInteger; double NearPeriodTotal; double lag1_inOpen; double lag2_inOpen; double lag1_inHigh; double lag1_inLow; double lag1_inClose; double lag2_inClose; int ringPos_NearTrailingIdx; int ringCap_NearTrailingIdx; int ringLag_NearTrailingIdx; double *ring_NearTrailingIdx_derived; }; /* Private function, not in public API. */ static void TA_CDLTASUKIGAP_ReleaseImpl( struct TA_CDLTASUKIGAP_Stream *sp ) { if( !sp ) return; if( sp->ring_NearTrailingIdx_derived ) TA_Free( sp->ring_NearTrailingIdx_derived ); TA_Free( sp ); } /* Private function, not in public API. */ static void TA_CDLTASUKIGAP_StepImpl( struct TA_CDLTASUKIGAP_Stream *sp, double inOpen, double inHigh, double inLow, double inClose, int *outInteger ) { sp->ring_NearTrailingIdx_derived[sp->ringPos_NearTrailingIdx] = TA_STREAM_CANDLERANGE(Near,inOpen,inHigh,inLow,inClose); if( (((min(sp->lag1_inOpen,sp->lag1_inClose) > max(sp->lag2_inOpen,sp->lag2_inClose)) ? 1 : 0) && /* upside gap */ ((sp->lag1_inClose >= sp->lag1_inOpen) ? 1 : -1) == 1 && /* 1st: white */ ((inClose >= inOpen) ? 1 : -1) == -1 && /* 2nd: black */ inOpen < sp->lag1_inClose && inOpen > sp->lag1_inOpen && /* that opens within the white rb */ inClose < sp->lag1_inOpen && /* and closes under the white rb */ inClose > max(sp->lag2_inClose,sp->lag2_inOpen) && /* inside the gap */ fabs(fabs(sp->lag1_inClose - sp->lag1_inOpen) - fabs(inClose - inOpen)) < TA_STREAM_CANDLEAVERAGE(Near,sp->NearPeriodTotal,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose)) || /* size of 2 rb near the same */ (((max(sp->lag1_inOpen,sp->lag1_inClose) < min(sp->lag2_inOpen,sp->lag2_inClose)) ? 1 : 0) && /* downside gap */ ((sp->lag1_inClose >= sp->lag1_inOpen) ? 1 : -1) == -1 && /* 1st: black */ ((inClose >= inOpen) ? 1 : -1) == 1 && /* 2nd: white */ inOpen < sp->lag1_inOpen && inOpen > sp->lag1_inClose && /* that opens within the black rb */ inClose > sp->lag1_inOpen && /* and closes above the black rb */ inClose < min(sp->lag2_inClose,sp->lag2_inOpen) && /* inside the gap */ fabs(fabs(sp->lag1_inClose - sp->lag1_inOpen) - fabs(inClose - inOpen)) < TA_STREAM_CANDLEAVERAGE(Near,sp->NearPeriodTotal,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose)) ) /* size of 2 rb near the same */ { *outInteger= ((sp->lag1_inClose >= sp->lag1_inOpen) ? 1 : -1) * 100; } else { *outInteger= 0; } /* add the current range and subtract the first range: this is done after the pattern recognition * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) */ sp->NearPeriodTotal += TA_STREAM_CANDLERANGE(Near,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose) - sp->ring_NearTrailingIdx_derived[(sp->ringPos_NearTrailingIdx + sp->ringCap_NearTrailingIdx - sp->ringLag_NearTrailingIdx - 1) % sp->ringCap_NearTrailingIdx]; sp->cur_outInteger = *outInteger; sp->lag2_inOpen = sp->lag1_inOpen; sp->lag1_inOpen = inOpen; sp->lag1_inHigh = inHigh; sp->lag1_inLow = inLow; sp->lag2_inClose = sp->lag1_inClose; sp->lag1_inClose = inClose; sp->ringPos_NearTrailingIdx = sp->ringPos_NearTrailingIdx + 1; if( sp->ringPos_NearTrailingIdx >= sp->ringCap_NearTrailingIdx ) { sp->ringPos_NearTrailingIdx = 0; } } static TA_RetCode TA_CDLTASUKIGAP_OpenImpl( struct TA_CDLTASUKIGAP_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int startIdx, int historyLen, int *outBegIdx, int *outNBElement, int outInteger[], int outStride ) { struct TA_CDLTASUKIGAP_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( !inOpen || !inHigh || !inLow || !inClose || !outInteger ) return TA_BAD_PARAM; if( startIdx > historyLen - 1 ) { *outBegIdx = 0; *outNBElement = 0; return TA_INSUFFICIENT_HISTORY; } endIdx = historyLen - 1; { int Near_avgPeriod = TA_Globals->candleSettings[TA_Near].avgPeriod; double NearPeriodTotal = 0.0; int i; int outIdx; int NearTrailingIdx; int lookbackTotal; /* Identify the minimum number of price bar needed * to calculate at least one output. */ lookbackTotal = TA_CDLTASUKIGAP_Lookback(); /* Move up the start index if there is not * enough initial data. */ if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } /* Make sure there is still something to evaluate. */ if( startIdx > endIdx ) { *outBegIdx= 0; *outNBElement= 0; return TA_INSUFFICIENT_HISTORY; } /* Do the calculation using tight loops. */ /* Add-up the initial period, except for the last value. */ NearPeriodTotal = 0; NearTrailingIdx = startIdx - Near_avgPeriod; i = NearTrailingIdx; while( i < startIdx ) { NearPeriodTotal += TA_CANDLERANGE(Near,i - 1); i += 1; } i = startIdx; /* Proceed with the calculation for the requested range. * Must have: * - upside (downside) gap * - first candle after the window: white (black) candlestick * - second candle: black (white) candlestick that opens within the previous real body and closes under (above) * the previous real body inside the gap * - the size of two real bodies should be near the same * The meaning of "near" is specified with TA_SetCandleSettings * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; * the user should consider that tasuki gap is significant when it appears in a trend, while this function does * not consider it */ outIdx = 0; do { if( (((min(inOpen[i - 1],inClose[i - 1]) > max(inOpen[i - 2],inClose[i - 2])) ? 1 : 0) && /* upside gap */ ((inClose[i - 1] >= inOpen[i - 1]) ? 1 : -1) == 1 && /* 1st: white */ ((inClose[i] >= inOpen[i]) ? 1 : -1) == -1 && /* 2nd: black */ inOpen[i] < inClose[i - 1] && inOpen[i] > inOpen[i - 1] && /* that opens within the white rb */ inClose[i] < inOpen[i - 1] && /* and closes under the white rb */ inClose[i] > max(inClose[i - 2],inOpen[i - 2]) && /* inside the gap */ fabs(fabs(inClose[i - 1] - inOpen[i - 1]) - fabs(inClose[i] - inOpen[i])) < TA_CANDLEAVERAGE(Near,NearPeriodTotal,i - 1)) || /* size of 2 rb near the same */ (((max(inOpen[i - 1],inClose[i - 1]) < min(inOpen[i - 2],inClose[i - 2])) ? 1 : 0) && /* downside gap */ ((inClose[i - 1] >= inOpen[i - 1]) ? 1 : -1) == -1 && /* 1st: black */ ((inClose[i] >= inOpen[i]) ? 1 : -1) == 1 && /* 2nd: white */ inOpen[i] < inOpen[i - 1] && inOpen[i] > inClose[i - 1] && /* that opens within the black rb */ inClose[i] > inOpen[i - 1] && /* and closes above the black rb */ inClose[i] < min(inClose[i - 2],inOpen[i - 2]) && /* inside the gap */ fabs(fabs(inClose[i - 1] - inOpen[i - 1]) - fabs(inClose[i] - inOpen[i])) < TA_CANDLEAVERAGE(Near,NearPeriodTotal,i - 1)) ) /* size of 2 rb near the same */ { outInteger[outIdx++ * outStride] = ((inClose[i - 1] >= inOpen[i - 1]) ? 1 : -1) * 100; } else { outInteger[outIdx++ * outStride] = 0; } /* add the current range and subtract the first range: this is done after the pattern recognition * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) */ NearPeriodTotal += TA_CANDLERANGE(Near,i - 1) - TA_CANDLERANGE(Near,NearTrailingIdx - 1); i += 1; NearTrailingIdx += 1; } while( i <= endIdx ); /* All done. Indicate the output limits and return. */ *outNBElement= outIdx; *outBegIdx= startIdx; /* Capture the live batch state into the handle. */ sp = (struct TA_CDLTASUKIGAP_Stream *)TA_Malloc( sizeof(*sp) ); if( !sp ) { return TA_ALLOC_ERR; } memset( sp, 0, sizeof(*sp) ); sp->NearPeriodTotal = NearPeriodTotal; sp->ringLag_NearTrailingIdx = (int)(i - NearTrailingIdx); sp->ringCap_NearTrailingIdx = sp->ringLag_NearTrailingIdx + 2; if( sp->ringLag_NearTrailingIdx < 0 || sp->ringCap_NearTrailingIdx > historyLen ) { TA_CDLTASUKIGAP_ReleaseImpl( sp ); return TA_INTERNAL_ERROR(306); } { size_t allocN = (size_t)(sp->ringCap_NearTrailingIdx > 0 ? sp->ringCap_NearTrailingIdx : 1); sp->ring_NearTrailingIdx_derived = (double *)TA_Malloc( sizeof(double) * allocN ); if( !sp->ring_NearTrailingIdx_derived ) { TA_CDLTASUKIGAP_ReleaseImpl( sp ); return TA_ALLOC_ERR; } { int fillJ; for( fillJ = historyLen - sp->ringCap_NearTrailingIdx; fillJ < historyLen; fillJ++ ) sp->ring_NearTrailingIdx_derived[fillJ % sp->ringCap_NearTrailingIdx] = TA_STREAM_CANDLERANGE(Near,inOpen[fillJ],inHigh[fillJ],inLow[fillJ],inClose[fillJ]); } } sp->ringPos_NearTrailingIdx = historyLen % sp->ringCap_NearTrailingIdx; sp->lag1_inOpen = inOpen[historyLen - 1]; sp->lag2_inOpen = inOpen[historyLen - 2]; sp->lag1_inHigh = inHigh[historyLen - 1]; sp->lag1_inLow = inLow[historyLen - 1]; sp->lag1_inClose = inClose[historyLen - 1]; sp->lag2_inClose = inClose[historyLen - 2]; sp->outRangeBegIdx = *outBegIdx; sp->outRangeCount = *outNBElement; sp->cur_outInteger = outInteger[(*outNBElement - 1) * outStride]; *stream = sp; return TA_SUCCESS; } } /* Private function, not in public API. */ TA_RetCode TA_CDLTASUKIGAP_OpenInternal( struct TA_CDLTASUKIGAP_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int startIdx, int historyLen, int *outInteger ) { TA_RetCode retCode; int dummyBegIdx = 0; int dummyNBElement = 0; int sink_outInteger = 0; retCode = TA_CDLTASUKIGAP_OpenImpl( stream, inOpen, inHigh, inLow, inClose, startIdx, historyLen, &dummyBegIdx, &dummyNBElement, &sink_outInteger, 0 ); if( retCode == TA_SUCCESS ) { *outInteger = sink_outInteger; } return retCode; } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_Open( TA_CDLTASUKIGAP_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int historyLen, int *outInteger ) { 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( !inOpen || !inHigh || !inLow || !inClose || !outInteger ) return TA_BAD_PARAM; return TA_CDLTASUKIGAP_OpenInternal( stream, inOpen, inHigh, inLow, inClose, 0, historyLen, outInteger ); } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_OpenAndFill( TA_CDLTASUKIGAP_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int historyLen, int *outBegIdx, int *outNBElement, int outInteger[] ) { 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( !inOpen || !inHigh || !inLow || !inClose || !outBegIdx || !outNBElement || !outInteger ) return TA_BAD_PARAM; if( (const void *)outInteger == (const void *)inOpen || (const void *)outInteger == (const void *)inHigh || (const void *)outInteger == (const void *)inLow || (const void *)outInteger == (const void *)inClose ) return TA_BAD_PARAM; return TA_CDLTASUKIGAP_OpenAndFillInternal( stream, inOpen, inHigh, inLow, inClose, 0, historyLen, outBegIdx, outNBElement, outInteger ); } /* Private function, not in public API. */ TA_RetCode TA_CDLTASUKIGAP_OpenAndFillInternal( struct TA_CDLTASUKIGAP_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int startIdx, int historyLen, int *outBegIdx, int *outNBElement, int outInteger[] ) { return TA_CDLTASUKIGAP_OpenImpl( stream, inOpen, inHigh, inLow, inClose, startIdx, historyLen, outBegIdx, outNBElement, outInteger, 1 ); } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_Update( TA_CDLTASUKIGAP_Stream *stream, double inOpen, double inHigh, double inLow, double inClose, int *outInteger ) { if( !stream ) return TA_BAD_PARAM; if( stream->outRangeBegIdx + stream->outRangeCount > TA_INDEX_MAX ) return TA_OUT_OF_RANGE_END_INDEX; if( !outInteger ) return TA_BAD_PARAM; if( !TA_IS_FINITE( inOpen ) || !TA_IS_FINITE( inHigh ) || !TA_IS_FINITE( inLow ) || !TA_IS_FINITE( inClose ) ) return TA_BAD_PARAM; TA_CDLTASUKIGAP_StepImpl( stream, inOpen, inHigh, inLow, inClose, outInteger ); stream->outRangeCount++; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_Peek( const TA_CDLTASUKIGAP_Stream *stream, double inOpen, double inHigh, double inLow, double inClose, int *outInteger ) { const struct TA_CDLTASUKIGAP_Stream *sp = stream; if( !stream || !outInteger ) return TA_BAD_PARAM; if( !TA_IS_FINITE( inOpen ) || !TA_IS_FINITE( inHigh ) || !TA_IS_FINITE( inLow ) || !TA_IS_FINITE( inClose ) ) return TA_BAD_PARAM; if( (((min(sp->lag1_inOpen,sp->lag1_inClose) > max(sp->lag2_inOpen,sp->lag2_inClose)) ? 1 : 0) && /* upside gap */ ((sp->lag1_inClose >= sp->lag1_inOpen) ? 1 : -1) == 1 && /* 1st: white */ ((inClose >= inOpen) ? 1 : -1) == -1 && /* 2nd: black */ inOpen < sp->lag1_inClose && inOpen > sp->lag1_inOpen && /* that opens within the white rb */ inClose < sp->lag1_inOpen && /* and closes under the white rb */ inClose > max(sp->lag2_inClose,sp->lag2_inOpen) && /* inside the gap */ fabs(fabs(sp->lag1_inClose - sp->lag1_inOpen) - fabs(inClose - inOpen)) < TA_STREAM_CANDLEAVERAGE(Near,sp->NearPeriodTotal,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose)) || /* size of 2 rb near the same */ (((max(sp->lag1_inOpen,sp->lag1_inClose) < min(sp->lag2_inOpen,sp->lag2_inClose)) ? 1 : 0) && /* downside gap */ ((sp->lag1_inClose >= sp->lag1_inOpen) ? 1 : -1) == -1 && /* 1st: black */ ((inClose >= inOpen) ? 1 : -1) == 1 && /* 2nd: white */ inOpen < sp->lag1_inOpen && inOpen > sp->lag1_inClose && /* that opens within the black rb */ inClose > sp->lag1_inOpen && /* and closes above the black rb */ inClose < min(sp->lag2_inClose,sp->lag2_inOpen) && /* inside the gap */ fabs(fabs(sp->lag1_inClose - sp->lag1_inOpen) - fabs(inClose - inOpen)) < TA_STREAM_CANDLEAVERAGE(Near,sp->NearPeriodTotal,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose)) ) /* size of 2 rb near the same */ { *outInteger= ((sp->lag1_inClose >= sp->lag1_inOpen) ? 1 : -1) * 100; } else { *outInteger= 0; } return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_Close( TA_CDLTASUKIGAP_Stream *stream ) { TA_CDLTASUKIGAP_ReleaseImpl( stream ); return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_Value( const TA_CDLTASUKIGAP_Stream *stream, int *outInteger ) { if( !stream || !outInteger ) return TA_BAD_PARAM; *outInteger = stream->cur_outInteger; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLTASUKIGAP_OutRange( const TA_CDLTASUKIGAP_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_CDLTASUKIGAP_Advance( TA_CDLTASUKIGAP_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_CDLTASUKIGAP_Clone( const TA_CDLTASUKIGAP_Stream *stream, TA_CDLTASUKIGAP_Stream **clone ) { struct TA_CDLTASUKIGAP_Stream *sp; if( !clone ) return TA_BAD_PARAM; *clone = NULL; if( !stream ) return TA_BAD_PARAM; sp = (struct TA_CDLTASUKIGAP_Stream *)TA_Malloc( sizeof(*sp) ); if( !sp ) return TA_ALLOC_ERR; *sp = *stream; sp->ring_NearTrailingIdx_derived = NULL; if( stream->ring_NearTrailingIdx_derived ) { size_t copyN = (size_t)(sp->ringCap_NearTrailingIdx > 0 ? sp->ringCap_NearTrailingIdx : 1); sp->ring_NearTrailingIdx_derived = (double *)TA_Malloc( sizeof(double) * copyN ); if( !sp->ring_NearTrailingIdx_derived ) { TA_CDLTASUKIGAP_Close( sp ); return TA_ALLOC_ERR; } memcpy( sp->ring_NearTrailingIdx_derived, stream->ring_NearTrailingIdx_derived, sizeof(double) * copyN ); } *clone = sp; return TA_SUCCESS; }