/* 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 * ------------------------------------------------------------------- * 100304 AC Creation */ TA_LIB_API int TA_CDLMORNINGSTAR_Lookback( double optInPenetration ) { int BodyLong_avgPeriod = TA_Globals->candleSettings[TA_BodyLong].avgPeriod; int BodyShort_avgPeriod = TA_Globals->candleSettings[TA_BodyShort].avgPeriod; if( optInPenetration == TA_REAL_DEFAULT ) optInPenetration = 0.3; else if( !(optInPenetration >= 0e0 && optInPenetration <= TA_REAL_MAX) ) return -1; return max(BodyShort_avgPeriod,BodyLong_avgPeriod) + 2; } TA_FMA_MULTIVERSION TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR( int startIdx, int endIdx, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], double optInPenetration, int *outBegIdx, int *outNBElement, int outInteger[] ) { double BodyShortPeriodTotal; double BodyLongPeriodTotal; double BodyShortPeriodTotal2; int i; int outIdx; int BodyShortTrailingIdx; int BodyLongTrailingIdx; int lookbackTotal; int BodyLong_avgPeriod = TA_Globals->candleSettings[TA_BodyLong].avgPeriod; int BodyShort_avgPeriod = TA_Globals->candleSettings[TA_BodyShort].avgPeriod; if( (startIdx < 0) || (startIdx > TA_MAX_INDEX) ) return TA_OUT_OF_RANGE_START_INDEX; if( (endIdx < 0) || (endIdx > TA_MAX_INDEX) || (endIdx < startIdx) ) return TA_OUT_OF_RANGE_END_INDEX; if( optInPenetration == TA_REAL_DEFAULT ) optInPenetration = 0.3; else if( !(optInPenetration >= 0e0 && optInPenetration <= TA_REAL_MAX) ) return TA_BAD_PARAM; 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_CDLMORNINGSTAR_Lookback(optInPenetration); /* 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. */ BodyLongPeriodTotal = 0; BodyShortPeriodTotal = 0; BodyShortPeriodTotal2 = 0; BodyLongTrailingIdx = startIdx - 2 - BodyLong_avgPeriod; BodyShortTrailingIdx = startIdx - 1 - BodyShort_avgPeriod; i = BodyLongTrailingIdx; while( i < startIdx - 2 ) { BodyLongPeriodTotal += TA_CANDLERANGE(BodyLong,i); i += 1; } i = BodyShortTrailingIdx; while( i < startIdx - 1 ) { BodyShortPeriodTotal += TA_CANDLERANGE(BodyShort,i); BodyShortPeriodTotal2 += TA_CANDLERANGE(BodyShort,i + 1); i += 1; } i = startIdx; /* Proceed with the calculation for the requested range. * Must have: * - first candle: long black real body * - second candle: star (Short real body gapping down) * - third candle: white real body that moves well within the first candle's real body * The meaning of "short" and "long" is specified with TA_SetCandleSettings * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want * it to be relatively long * outInteger is positive (1 to 100): morning star is always bullish; * the user should consider that a morning star is significant when it appears in a downtrend, * while this function does not consider the trend */ outIdx = 0; do { if( ((inClose[i - 2] >= inOpen[i - 2]) ? 1 : 0 - 1) == 0 - 1 && /* black */ ((inClose[i] >= inOpen[i]) ? 1 : 0 - 1) == 1 && /* white real body */ ((max(inOpen[i - 1],inClose[i - 1]) < min(inOpen[i - 2],inClose[i - 2])) ? 1 : 0) && /* gapping down */ inClose[i] > fma(fabs(inClose[i - 2] - inOpen[i - 2]), optInPenetration, inClose[i - 2]) && /* closing well within 1st rb */ fabs(inClose[i - 2] - inOpen[i - 2]) > TA_CANDLEAVERAGE(BodyLong,BodyLongPeriodTotal,i - 2) && /* 1st: long */ fabs(inClose[i - 1] - inOpen[i - 1]) <= TA_CANDLEAVERAGE(BodyShort,BodyShortPeriodTotal,i - 1) && /* 2nd: short */ fabs(inClose[i] - inOpen[i]) > TA_CANDLEAVERAGE(BodyShort,BodyShortPeriodTotal2,i) ) /* 3rd: longer than short */ { outInteger[outIdx++] = 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) */ BodyLongPeriodTotal += TA_CANDLERANGE(BodyLong,i - 2) - TA_CANDLERANGE(BodyLong,BodyLongTrailingIdx); BodyShortPeriodTotal += TA_CANDLERANGE(BodyShort,i - 1) - TA_CANDLERANGE(BodyShort,BodyShortTrailingIdx); BodyShortPeriodTotal2 += TA_CANDLERANGE(BodyShort,i) - TA_CANDLERANGE(BodyShort,BodyShortTrailingIdx + 1); i += 1; BodyLongTrailingIdx += 1; BodyShortTrailingIdx += 1; } while( i <= endIdx ); /* All done. Indicate the output limits and return. */ *outNBElement= outIdx; *outBegIdx= startIdx; return TA_SUCCESS; } TA_FMA_MULTIVERSION TA_RetCode TA_S_CDLMORNINGSTAR( int startIdx, int endIdx, const float inOpen[], const float inHigh[], const float inLow[], const float inClose[], double optInPenetration, int *outBegIdx, int *outNBElement, int outInteger[] ) { double BodyShortPeriodTotal; double BodyLongPeriodTotal; double BodyShortPeriodTotal2; int i; int outIdx; int BodyShortTrailingIdx; int BodyLongTrailingIdx; int lookbackTotal; int BodyLong_avgPeriod = TA_Globals->candleSettings[TA_BodyLong].avgPeriod; int BodyShort_avgPeriod = TA_Globals->candleSettings[TA_BodyShort].avgPeriod; if( (startIdx < 0) || (startIdx > TA_MAX_INDEX) ) return TA_OUT_OF_RANGE_START_INDEX; if( (endIdx < 0) || (endIdx > TA_MAX_INDEX) || (endIdx < startIdx) ) return TA_OUT_OF_RANGE_END_INDEX; if( optInPenetration == TA_REAL_DEFAULT ) optInPenetration = 0.3; else if( !(optInPenetration >= 0e0 && optInPenetration <= TA_REAL_MAX) ) return TA_BAD_PARAM; 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_CDLMORNINGSTAR_Lookback(optInPenetration); if( startIdx < lookbackTotal ) { startIdx = lookbackTotal; } if( startIdx > endIdx ) { *outBegIdx= 0; *outNBElement= 0; return TA_SUCCESS; } BodyLongPeriodTotal = 0; BodyShortPeriodTotal = 0; BodyShortPeriodTotal2 = 0; BodyLongTrailingIdx = startIdx - 2 - BodyLong_avgPeriod; BodyShortTrailingIdx = startIdx - 1 - BodyShort_avgPeriod; i = BodyLongTrailingIdx; while( i < startIdx - 2 ) { BodyLongPeriodTotal += TA_CANDLERANGE(BodyLong,i); i += 1; } i = BodyShortTrailingIdx; while( i < startIdx - 1 ) { BodyShortPeriodTotal += TA_CANDLERANGE(BodyShort,i); BodyShortPeriodTotal2 += TA_CANDLERANGE(BodyShort,i + 1); i += 1; } i = startIdx; outIdx = 0; do { if( (((double)inClose[i - 2] >= (double)inOpen[i - 2]) ? 1 : 0 - 1) == 0 - 1 && (((double)inClose[i] >= (double)inOpen[i]) ? 1 : 0 - 1) == 1 && ((max((double)inOpen[i - 1],(double)inClose[i - 1]) < min((double)inOpen[i - 2],(double)inClose[i - 2])) ? 1 : 0) && (double)inClose[i] > fma(fabs((double)inClose[i - 2] - (double)inOpen[i - 2]), optInPenetration, (double)inClose[i - 2]) && fabs((double)inClose[i - 2] - (double)inOpen[i - 2]) > TA_CANDLEAVERAGE(BodyLong,BodyLongPeriodTotal,i - 2) && fabs((double)inClose[i - 1] - (double)inOpen[i - 1]) <= TA_CANDLEAVERAGE(BodyShort,BodyShortPeriodTotal,i - 1) && fabs((double)inClose[i] - (double)inOpen[i]) > TA_CANDLEAVERAGE(BodyShort,BodyShortPeriodTotal2,i) ) { outInteger[outIdx++] = 100; } else { outInteger[outIdx++] = 0; } BodyLongPeriodTotal += TA_CANDLERANGE(BodyLong,i - 2) - TA_CANDLERANGE(BodyLong,BodyLongTrailingIdx); BodyShortPeriodTotal += TA_CANDLERANGE(BodyShort,i - 1) - TA_CANDLERANGE(BodyShort,BodyShortTrailingIdx); BodyShortPeriodTotal2 += TA_CANDLERANGE(BodyShort,i) - TA_CANDLERANGE(BodyShort,BodyShortTrailingIdx + 1); i += 1; BodyLongTrailingIdx += 1; BodyShortTrailingIdx += 1; } while( i <= endIdx ); *outNBElement= outIdx; *outBegIdx= startIdx; return TA_SUCCESS; } /**** Streaming API *****/ struct TA_CDLMORNINGSTAR_Stream { /* The bars this handle has an output for (see TA_CDLMORNINGSTAR_OutRange). */ int outRangeBegIdx; int outRangeCount; /* The value(s) at the last bar the stream counted (see TA_CDLMORNINGSTAR_Value). */ int cur_outInteger; double optInPenetration; double BodyShortPeriodTotal; double BodyLongPeriodTotal; double BodyShortPeriodTotal2; double lag1_inOpen; double lag2_inOpen; double lag1_inHigh; double lag2_inHigh; double lag1_inLow; double lag2_inLow; double lag1_inClose; double lag2_inClose; int ringPos_BodyLongTrailingIdx; int ringCap_BodyLongTrailingIdx; double *ring_BodyLongTrailingIdx_derived; int ringPos_BodyShortTrailingIdx; int ringCap_BodyShortTrailingIdx; int ringLag_BodyShortTrailingIdx; double *ring_BodyShortTrailingIdx_derived; }; /* Private function, not in public API. */ static void TA_CDLMORNINGSTAR_ReleaseImpl( struct TA_CDLMORNINGSTAR_Stream *sp ) { if( !sp ) return; if( sp->ring_BodyLongTrailingIdx_derived ) TA_Free( sp->ring_BodyLongTrailingIdx_derived ); if( sp->ring_BodyShortTrailingIdx_derived ) TA_Free( sp->ring_BodyShortTrailingIdx_derived ); TA_Free( sp ); } /* Private function, not in public API. */ static void TA_CDLMORNINGSTAR_StepImpl( struct TA_CDLMORNINGSTAR_Stream *sp, double inOpen, double inHigh, double inLow, double inClose, int *outInteger ) { if( sp->ringCap_BodyLongTrailingIdx == 0 ) { sp->ring_BodyLongTrailingIdx_derived[0] = TA_STREAM_CANDLERANGE(BodyLong,inOpen,inHigh,inLow,inClose); } sp->ring_BodyShortTrailingIdx_derived[sp->ringPos_BodyShortTrailingIdx] = TA_STREAM_CANDLERANGE(BodyShort,inOpen,inHigh,inLow,inClose); if( ((sp->lag2_inClose >= sp->lag2_inOpen) ? 1 : 0 - 1) == 0 - 1 && /* black */ ((inClose >= inOpen) ? 1 : 0 - 1) == 1 && /* white real body */ ((max(sp->lag1_inOpen,sp->lag1_inClose) < min(sp->lag2_inOpen,sp->lag2_inClose)) ? 1 : 0) && /* gapping down */ inClose > fma(fabs(sp->lag2_inClose - sp->lag2_inOpen), sp->optInPenetration, sp->lag2_inClose) && /* closing well within 1st rb */ fabs(sp->lag2_inClose - sp->lag2_inOpen) > TA_STREAM_CANDLEAVERAGE(BodyLong,sp->BodyLongPeriodTotal,sp->lag2_inOpen,sp->lag2_inHigh,sp->lag2_inLow,sp->lag2_inClose) && /* 1st: long */ fabs(sp->lag1_inClose - sp->lag1_inOpen) <= TA_STREAM_CANDLEAVERAGE(BodyShort,sp->BodyShortPeriodTotal,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose) && /* 2nd: short */ fabs(inClose - inOpen) > TA_STREAM_CANDLEAVERAGE(BodyShort,sp->BodyShortPeriodTotal2,inOpen,inHigh,inLow,inClose) ) /* 3rd: longer than short */ { *outInteger= 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->BodyLongPeriodTotal += TA_STREAM_CANDLERANGE(BodyLong,sp->lag2_inOpen,sp->lag2_inHigh,sp->lag2_inLow,sp->lag2_inClose) - sp->ring_BodyLongTrailingIdx_derived[sp->ringPos_BodyLongTrailingIdx]; sp->BodyShortPeriodTotal += TA_STREAM_CANDLERANGE(BodyShort,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose) - sp->ring_BodyShortTrailingIdx_derived[(sp->ringPos_BodyShortTrailingIdx + sp->ringCap_BodyShortTrailingIdx - sp->ringLag_BodyShortTrailingIdx) % sp->ringCap_BodyShortTrailingIdx]; sp->BodyShortPeriodTotal2 += TA_STREAM_CANDLERANGE(BodyShort,inOpen,inHigh,inLow,inClose) - sp->ring_BodyShortTrailingIdx_derived[(sp->ringPos_BodyShortTrailingIdx + sp->ringCap_BodyShortTrailingIdx - sp->ringLag_BodyShortTrailingIdx + 1) % sp->ringCap_BodyShortTrailingIdx]; sp->cur_outInteger = *outInteger; sp->lag2_inOpen = sp->lag1_inOpen; sp->lag1_inOpen = inOpen; sp->lag2_inHigh = sp->lag1_inHigh; sp->lag1_inHigh = inHigh; sp->lag2_inLow = sp->lag1_inLow; sp->lag1_inLow = inLow; sp->lag2_inClose = sp->lag1_inClose; sp->lag1_inClose = inClose; sp->ring_BodyLongTrailingIdx_derived[sp->ringPos_BodyLongTrailingIdx] = TA_STREAM_CANDLERANGE(BodyLong,inOpen,inHigh,inLow,inClose); sp->ringPos_BodyLongTrailingIdx = sp->ringPos_BodyLongTrailingIdx + 1; if( sp->ringPos_BodyLongTrailingIdx >= sp->ringCap_BodyLongTrailingIdx ) { sp->ringPos_BodyLongTrailingIdx = 0; } sp->ringPos_BodyShortTrailingIdx = sp->ringPos_BodyShortTrailingIdx + 1; if( sp->ringPos_BodyShortTrailingIdx >= sp->ringCap_BodyShortTrailingIdx ) { sp->ringPos_BodyShortTrailingIdx = 0; } } static TA_RetCode TA_CDLMORNINGSTAR_OpenImpl( struct TA_CDLMORNINGSTAR_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int startIdx, int historyLen, double optInPenetration, int *outBegIdx, int *outNBElement, int outInteger[], int outStride ) { struct TA_CDLMORNINGSTAR_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_MAX_INDEX + 1 ) return TA_OUT_OF_RANGE_END_INDEX; if( !inOpen || !inHigh || !inLow || !inClose || !outInteger ) return TA_BAD_PARAM; if( optInPenetration == TA_REAL_DEFAULT ) optInPenetration = 0.3; else if( !(optInPenetration >= 0e0 && optInPenetration <= TA_REAL_MAX) ) return TA_BAD_PARAM; if( startIdx > historyLen - 1 ) { *outBegIdx = 0; *outNBElement = 0; return TA_INSUFFICIENT_HISTORY; } endIdx = historyLen - 1; { int BodyLong_avgPeriod = TA_Globals->candleSettings[TA_BodyLong].avgPeriod; int BodyShort_avgPeriod = TA_Globals->candleSettings[TA_BodyShort].avgPeriod; double BodyShortPeriodTotal = 0.0; double BodyLongPeriodTotal = 0.0; double BodyShortPeriodTotal2 = 0.0; int i; int outIdx; int BodyShortTrailingIdx; int BodyLongTrailingIdx; int lookbackTotal; /* Identify the minimum number of price bar needed * to calculate at least one output. */ lookbackTotal = TA_CDLMORNINGSTAR_Lookback(optInPenetration); /* 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. */ BodyLongPeriodTotal = 0; BodyShortPeriodTotal = 0; BodyShortPeriodTotal2 = 0; BodyLongTrailingIdx = startIdx - 2 - BodyLong_avgPeriod; BodyShortTrailingIdx = startIdx - 1 - BodyShort_avgPeriod; i = BodyLongTrailingIdx; while( i < startIdx - 2 ) { BodyLongPeriodTotal += TA_CANDLERANGE(BodyLong,i); i += 1; } i = BodyShortTrailingIdx; while( i < startIdx - 1 ) { BodyShortPeriodTotal += TA_CANDLERANGE(BodyShort,i); BodyShortPeriodTotal2 += TA_CANDLERANGE(BodyShort,i + 1); i += 1; } i = startIdx; /* Proceed with the calculation for the requested range. * Must have: * - first candle: long black real body * - second candle: star (Short real body gapping down) * - third candle: white real body that moves well within the first candle's real body * The meaning of "short" and "long" is specified with TA_SetCandleSettings * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want * it to be relatively long * outInteger is positive (1 to 100): morning star is always bullish; * the user should consider that a morning star is significant when it appears in a downtrend, * while this function does not consider the trend */ outIdx = 0; do { if( ((inClose[i - 2] >= inOpen[i - 2]) ? 1 : 0 - 1) == 0 - 1 && /* black */ ((inClose[i] >= inOpen[i]) ? 1 : 0 - 1) == 1 && /* white real body */ ((max(inOpen[i - 1],inClose[i - 1]) < min(inOpen[i - 2],inClose[i - 2])) ? 1 : 0) && /* gapping down */ inClose[i] > fma(fabs(inClose[i - 2] - inOpen[i - 2]), optInPenetration, inClose[i - 2]) && /* closing well within 1st rb */ fabs(inClose[i - 2] - inOpen[i - 2]) > TA_CANDLEAVERAGE(BodyLong,BodyLongPeriodTotal,i - 2) && /* 1st: long */ fabs(inClose[i - 1] - inOpen[i - 1]) <= TA_CANDLEAVERAGE(BodyShort,BodyShortPeriodTotal,i - 1) && /* 2nd: short */ fabs(inClose[i] - inOpen[i]) > TA_CANDLEAVERAGE(BodyShort,BodyShortPeriodTotal2,i) ) /* 3rd: longer than short */ { outInteger[outIdx++ * outStride] = 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) */ BodyLongPeriodTotal += TA_CANDLERANGE(BodyLong,i - 2) - TA_CANDLERANGE(BodyLong,BodyLongTrailingIdx); BodyShortPeriodTotal += TA_CANDLERANGE(BodyShort,i - 1) - TA_CANDLERANGE(BodyShort,BodyShortTrailingIdx); BodyShortPeriodTotal2 += TA_CANDLERANGE(BodyShort,i) - TA_CANDLERANGE(BodyShort,BodyShortTrailingIdx + 1); i += 1; BodyLongTrailingIdx += 1; BodyShortTrailingIdx += 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_CDLMORNINGSTAR_Stream *)TA_Malloc( sizeof(*sp) ); if( !sp ) { return TA_ALLOC_ERR; } memset( sp, 0, sizeof(*sp) ); sp->optInPenetration = optInPenetration; sp->BodyShortPeriodTotal = BodyShortPeriodTotal; sp->BodyLongPeriodTotal = BodyLongPeriodTotal; sp->BodyShortPeriodTotal2 = BodyShortPeriodTotal2; sp->ringCap_BodyLongTrailingIdx = (int)(i - BodyLongTrailingIdx); if( sp->ringCap_BodyLongTrailingIdx < 0 || sp->ringCap_BodyLongTrailingIdx > historyLen ) { TA_CDLMORNINGSTAR_ReleaseImpl( sp ); return TA_INTERNAL_ERROR(279); } { size_t allocN = (size_t)(sp->ringCap_BodyLongTrailingIdx > 0 ? sp->ringCap_BodyLongTrailingIdx : 1); sp->ring_BodyLongTrailingIdx_derived = (double *)TA_Malloc( sizeof(double) * allocN ); if( !sp->ring_BodyLongTrailingIdx_derived ) { TA_CDLMORNINGSTAR_ReleaseImpl( sp ); return TA_ALLOC_ERR; } { int fillJ; for( fillJ = historyLen - sp->ringCap_BodyLongTrailingIdx; fillJ < historyLen; fillJ++ ) sp->ring_BodyLongTrailingIdx_derived[fillJ - (historyLen - sp->ringCap_BodyLongTrailingIdx)] = TA_STREAM_CANDLERANGE(BodyLong,inOpen[fillJ],inHigh[fillJ],inLow[fillJ],inClose[fillJ]); } } sp->ringPos_BodyLongTrailingIdx = 0; sp->ringLag_BodyShortTrailingIdx = (int)(i - BodyShortTrailingIdx); sp->ringCap_BodyShortTrailingIdx = sp->ringLag_BodyShortTrailingIdx + 2; if( sp->ringLag_BodyShortTrailingIdx < 1 || sp->ringCap_BodyShortTrailingIdx > historyLen ) { TA_CDLMORNINGSTAR_ReleaseImpl( sp ); return TA_INTERNAL_ERROR(280); } { size_t allocN = (size_t)(sp->ringCap_BodyShortTrailingIdx > 0 ? sp->ringCap_BodyShortTrailingIdx : 1); sp->ring_BodyShortTrailingIdx_derived = (double *)TA_Malloc( sizeof(double) * allocN ); if( !sp->ring_BodyShortTrailingIdx_derived ) { TA_CDLMORNINGSTAR_ReleaseImpl( sp ); return TA_ALLOC_ERR; } { int fillJ; for( fillJ = historyLen - sp->ringCap_BodyShortTrailingIdx; fillJ < historyLen; fillJ++ ) sp->ring_BodyShortTrailingIdx_derived[fillJ % sp->ringCap_BodyShortTrailingIdx] = TA_STREAM_CANDLERANGE(BodyShort,inOpen[fillJ],inHigh[fillJ],inLow[fillJ],inClose[fillJ]); } } sp->ringPos_BodyShortTrailingIdx = historyLen % sp->ringCap_BodyShortTrailingIdx; sp->lag1_inOpen = inOpen[historyLen - 1]; sp->lag2_inOpen = inOpen[historyLen - 2]; sp->lag1_inHigh = inHigh[historyLen - 1]; sp->lag2_inHigh = inHigh[historyLen - 2]; sp->lag1_inLow = inLow[historyLen - 1]; sp->lag2_inLow = inLow[historyLen - 2]; 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_CDLMORNINGSTAR_OpenInternal( struct TA_CDLMORNINGSTAR_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int startIdx, int historyLen, double optInPenetration, int *outInteger ) { TA_RetCode retCode; int dummyBegIdx = 0; int dummyNBElement = 0; int sink_outInteger = 0; retCode = TA_CDLMORNINGSTAR_OpenImpl( stream, inOpen, inHigh, inLow, inClose, startIdx, historyLen, optInPenetration, &dummyBegIdx, &dummyNBElement, &sink_outInteger, 0 ); if( retCode == TA_SUCCESS ) { *outInteger = sink_outInteger; } return retCode; } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_Open( TA_CDLMORNINGSTAR_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int historyLen, double optInPenetration, int *outInteger ) { if( !stream ) return TA_BAD_PARAM; *stream = NULL; if( historyLen < 1 ) return TA_OUT_OF_RANGE_START_INDEX; if( historyLen > TA_MAX_INDEX + 1 ) return TA_OUT_OF_RANGE_END_INDEX; if( !inOpen || !inHigh || !inLow || !inClose || !outInteger ) return TA_BAD_PARAM; return TA_CDLMORNINGSTAR_OpenInternal( stream, inOpen, inHigh, inLow, inClose, 0, historyLen, optInPenetration, outInteger ); } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_OpenAndFill( TA_CDLMORNINGSTAR_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int historyLen, double optInPenetration, 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_MAX_INDEX + 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_CDLMORNINGSTAR_OpenAndFillInternal( stream, inOpen, inHigh, inLow, inClose, 0, historyLen, optInPenetration, outBegIdx, outNBElement, outInteger ); } /* Private function, not in public API. */ TA_RetCode TA_CDLMORNINGSTAR_OpenAndFillInternal( struct TA_CDLMORNINGSTAR_Stream **stream, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int startIdx, int historyLen, double optInPenetration, int *outBegIdx, int *outNBElement, int outInteger[] ) { return TA_CDLMORNINGSTAR_OpenImpl( stream, inOpen, inHigh, inLow, inClose, startIdx, historyLen, optInPenetration, outBegIdx, outNBElement, outInteger, 1 ); } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_Update( TA_CDLMORNINGSTAR_Stream *stream, double inOpen, double inHigh, double inLow, double inClose, int *outInteger ) { if( !stream ) return TA_BAD_PARAM; if( stream->outRangeBegIdx + stream->outRangeCount > TA_MAX_INDEX ) 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_CDLMORNINGSTAR_StepImpl( stream, inOpen, inHigh, inLow, inClose, outInteger ); stream->outRangeCount++; return TA_SUCCESS; } TA_FMA_MULTIVERSION TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_Peek( const TA_CDLMORNINGSTAR_Stream *stream, double inOpen, double inHigh, double inLow, double inClose, int *outInteger ) { const struct TA_CDLMORNINGSTAR_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( ((sp->lag2_inClose >= sp->lag2_inOpen) ? 1 : 0 - 1) == 0 - 1 && /* black */ ((inClose >= inOpen) ? 1 : 0 - 1) == 1 && /* white real body */ ((max(sp->lag1_inOpen,sp->lag1_inClose) < min(sp->lag2_inOpen,sp->lag2_inClose)) ? 1 : 0) && /* gapping down */ inClose > fma(fabs(sp->lag2_inClose - sp->lag2_inOpen), sp->optInPenetration, sp->lag2_inClose) && /* closing well within 1st rb */ fabs(sp->lag2_inClose - sp->lag2_inOpen) > TA_STREAM_CANDLEAVERAGE(BodyLong,sp->BodyLongPeriodTotal,sp->lag2_inOpen,sp->lag2_inHigh,sp->lag2_inLow,sp->lag2_inClose) && /* 1st: long */ fabs(sp->lag1_inClose - sp->lag1_inOpen) <= TA_STREAM_CANDLEAVERAGE(BodyShort,sp->BodyShortPeriodTotal,sp->lag1_inOpen,sp->lag1_inHigh,sp->lag1_inLow,sp->lag1_inClose) && /* 2nd: short */ fabs(inClose - inOpen) > TA_STREAM_CANDLEAVERAGE(BodyShort,sp->BodyShortPeriodTotal2,inOpen,inHigh,inLow,inClose) ) /* 3rd: longer than short */ { *outInteger= 100; } else { *outInteger= 0; } return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_Close( TA_CDLMORNINGSTAR_Stream *stream ) { TA_CDLMORNINGSTAR_ReleaseImpl( stream ); return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_Value( const TA_CDLMORNINGSTAR_Stream *stream, int *outInteger ) { if( !stream || !outInteger ) return TA_BAD_PARAM; *outInteger = stream->cur_outInteger; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_OutRange( const TA_CDLMORNINGSTAR_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_CDLMORNINGSTAR_Advance( TA_CDLMORNINGSTAR_Stream *stream ) { if( !stream ) return TA_BAD_PARAM; if( stream->outRangeBegIdx + stream->outRangeCount > TA_MAX_INDEX ) return TA_OUT_OF_RANGE_END_INDEX; stream->outRangeCount++; return TA_SUCCESS; } TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR_Clone( const TA_CDLMORNINGSTAR_Stream *stream, TA_CDLMORNINGSTAR_Stream **clone ) { struct TA_CDLMORNINGSTAR_Stream *sp; if( !clone ) return TA_BAD_PARAM; *clone = NULL; if( !stream ) return TA_BAD_PARAM; sp = (struct TA_CDLMORNINGSTAR_Stream *)TA_Malloc( sizeof(*sp) ); if( !sp ) return TA_ALLOC_ERR; *sp = *stream; sp->ring_BodyLongTrailingIdx_derived = NULL; sp->ring_BodyShortTrailingIdx_derived = NULL; if( stream->ring_BodyLongTrailingIdx_derived ) { size_t copyN = (size_t)(sp->ringCap_BodyLongTrailingIdx > 0 ? sp->ringCap_BodyLongTrailingIdx : 1); sp->ring_BodyLongTrailingIdx_derived = (double *)TA_Malloc( sizeof(double) * copyN ); if( !sp->ring_BodyLongTrailingIdx_derived ) { TA_CDLMORNINGSTAR_Close( sp ); return TA_ALLOC_ERR; } memcpy( sp->ring_BodyLongTrailingIdx_derived, stream->ring_BodyLongTrailingIdx_derived, sizeof(double) * copyN ); } if( stream->ring_BodyShortTrailingIdx_derived ) { size_t copyN = (size_t)(sp->ringCap_BodyShortTrailingIdx > 0 ? sp->ringCap_BodyShortTrailingIdx : 1); sp->ring_BodyShortTrailingIdx_derived = (double *)TA_Malloc( sizeof(double) * copyN ); if( !sp->ring_BodyShortTrailingIdx_derived ) { TA_CDLMORNINGSTAR_Close( sp ); return TA_ALLOC_ERR; } memcpy( sp->ring_BodyShortTrailingIdx_derived, stream->ring_BodyShortTrailingIdx_derived, sizeof(double) * copyN ); } *clone = sp; return TA_SUCCESS; }