1 /* TA-LIB Copyright (c) 1999-2007, Mario Fortier
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
6 * conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * - Neither name of author nor the names of its contributors
17 * may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /* List of contributors:
35 *
36 * Initial Name/description
37 * -------------------------------------------------------------------
38 * AC Angelo Ciceri
39 *
40 *
41 * Change history:
42 *
43 * MMDDYY BY Description
44 * -------------------------------------------------------------------
45 * 121104 AC Creation
46 *
47 */
48
49 /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
50 /* All code within this section is automatically
51 * generated by gen_code. Any modification will be lost
52 * next time gen_code is run.
53 */
54 /* Generated */
55 /* Generated */ #if defined( _MANAGED )
56 /* Generated */ #include "TA-Lib-Core.h"
57 /* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError)
58 /* Generated */ namespace TicTacTec { namespace TA { namespace Library {
59 /* Generated */ #elif defined( _JAVA )
60 /* Generated */ #include "ta_defs.h"
61 /* Generated */ #include "ta_java_defs.h"
62 /* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError)
63 /* Generated */ #else
64 /* Generated */ #include <string.h>
65 /* Generated */ #include <math.h>
66 /* Generated */ #include "ta_func.h"
67 /* Generated */ #endif
68 /* Generated */
69 /* Generated */ #ifndef TA_UTILITY_H
70 /* Generated */ #include "ta_utility.h"
71 /* Generated */ #endif
72 /* Generated */
73 /* Generated */ #ifndef TA_MEMORY_H
74 /* Generated */ #include "ta_memory.h"
75 /* Generated */ #endif
76 /* Generated */
77 /* Generated */ #define TA_PREFIX(x) TA_##x
78 /* Generated */ #define INPUT_TYPE double
79 /* Generated */
80 /* Generated */ #if defined( _MANAGED )
CdlInNeckLookback(void)81 /* Generated */ int Core::CdlInNeckLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlInNeckLookback( )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLINNECK_Lookback( void )
88 /* Generated */
89 /* Generated */ #endif
90 /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
91 {
92 /* insert local variable here */
93
94 /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
95 /* Generated */ /* No parameters to validate. */
96 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
97
98 /* insert lookback code here. */
99 return max( TA_CANDLEAVGPERIOD(Equal), TA_CANDLEAVGPERIOD(BodyLong)
100 ) + 1;
101 }
102
103 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
104 /*
105 * TA_CDLINNECK - In-Neck Pattern
106 *
107 * Input = Open, High, Low, Close
108 * Output = int
109 *
110 */
111 /* Generated */
112 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
113 /* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx,
114 /* Generated */ int endIdx,
115 /* Generated */ SubArray^ inOpen,
116 /* Generated */ SubArray^ inHigh,
117 /* Generated */ SubArray^ inLow,
118 /* Generated */ SubArray^ inClose,
119 /* Generated */ [Out]int% outBegIdx,
120 /* Generated */ [Out]int% outNBElement,
121 /* Generated */ cli::array<int>^ outInteger )
122 /* Generated */ #elif defined( _MANAGED )
123 /* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx,
124 /* Generated */ int endIdx,
125 /* Generated */ cli::array<double>^ inOpen,
126 /* Generated */ cli::array<double>^ inHigh,
127 /* Generated */ cli::array<double>^ inLow,
128 /* Generated */ cli::array<double>^ inClose,
129 /* Generated */ [Out]int% outBegIdx,
130 /* Generated */ [Out]int% outNBElement,
131 /* Generated */ cli::array<int>^ outInteger )
132 /* Generated */ #elif defined( _JAVA )
133 /* Generated */ public RetCode cdlInNeck( int startIdx,
134 /* Generated */ int endIdx,
135 /* Generated */ double inOpen[],
136 /* Generated */ double inHigh[],
137 /* Generated */ double inLow[],
138 /* Generated */ double inClose[],
139 /* Generated */ MInteger outBegIdx,
140 /* Generated */ MInteger outNBElement,
141 /* Generated */ int outInteger[] )
142 /* Generated */ #else
143 /* Generated */ TA_RetCode TA_CDLINNECK( int startIdx,
144 /* Generated */ int endIdx,
145 /* Generated */ const double inOpen[],
146 /* Generated */ const double inHigh[],
147 /* Generated */ const double inLow[],
148 /* Generated */ const double inClose[],
149 /* Generated */ int *outBegIdx,
150 /* Generated */ int *outNBElement,
151 /* Generated */ int outInteger[] )
152 /* Generated */ #endif
153 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
154 {
155 /* Insert local variables here. */
156 double EqualPeriodTotal, BodyLongPeriodTotal;
157 int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal;
158
159 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
160 /* Generated */
161 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
162 /* Generated */
163 /* Generated */ /* Validate the requested output range. */
164 /* Generated */ if( startIdx < 0 )
165 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
166 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
167 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
168 /* Generated */
169 /* Generated */ #if !defined(_JAVA)
170 /* Generated */ /* Verify required price component. */
171 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
172 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
173 /* Generated */
174 /* Generated */ #endif /* !defined(_JAVA)*/
175 /* Generated */ #if !defined(_JAVA)
176 /* Generated */ if( !outInteger )
177 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
178 /* Generated */
179 /* Generated */ #endif /* !defined(_JAVA) */
180 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
181 /* Generated */
182 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
183
184 /* Identify the minimum number of price bar needed
185 * to calculate at least one output.
186 */
187
188 lookbackTotal = LOOKBACK_CALL(CDLINNECK)();
189
190 /* Move up the start index if there is not
191 * enough initial data.
192 */
193 if( startIdx < lookbackTotal )
194 startIdx = lookbackTotal;
195
196 /* Make sure there is still something to evaluate. */
197 if( startIdx > endIdx )
198 {
199 VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
200 VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
201 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
202 }
203
204 /* Do the calculation using tight loops. */
205 /* Add-up the initial period, except for the last value. */
206 EqualPeriodTotal = 0;
207 EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal);
208 BodyLongPeriodTotal = 0;
209 BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong);
210
211 i = EqualTrailingIdx;
212 while( i < startIdx ) {
213 EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 );
214 i++;
215 }
216 i = BodyLongTrailingIdx;
217 while( i < startIdx ) {
218 BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 );
219 i++;
220 }
221 i = startIdx;
222
223 /* Proceed with the calculation for the requested range.
224 * Must have:
225 * - first candle: long black candle
226 * - second candle: white candle with open below previous day low and close slightly into previous day body
227 * The meaning of "equal" is specified with TA_SetCandleSettings
228 * outInteger is negative (-1 to -100): in-neck is always bearish
229 * the user should consider that in-neck is significant when it appears in a downtrend, while this function
230 * does not consider it
231 */
232 outIdx = 0;
233 do
234 {
235 if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black
236 TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long
237 TA_CANDLECOLOR(i) == 1 && // 2nd: white
238 inOpen[i] < inLow[i-1] && // open below prior low
239 inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close slightly into prior body
240 inClose[i] >= inClose[i-1]
241 )
242 outInteger[outIdx++] = -100;
243 else
244 outInteger[outIdx++] = 0;
245 /* add the current range and subtract the first range: this is done after the pattern recognition
246 * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
247 */
248 EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 );
249 BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 )
250 - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 );
251 i++;
252 EqualTrailingIdx++;
253 BodyLongTrailingIdx++;
254 } while( i <= endIdx );
255
256 /* All done. Indicate the output limits and return. */
257 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
258 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
259
260 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
261 }
262
263 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
264 /* Generated */
265 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
266 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
267 /* Generated */ #undef TA_PREFIX
268 /* Generated */ #define TA_PREFIX(x) TA_S_##x
269 /* Generated */ #endif
270 /* Generated */ #undef INPUT_TYPE
271 /* Generated */ #define INPUT_TYPE float
272 /* Generated */ #if defined( _MANAGED )
273 /* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx,
274 /* Generated */ int endIdx,
275 /* Generated */ cli::array<float>^ inOpen,
276 /* Generated */ cli::array<float>^ inHigh,
277 /* Generated */ cli::array<float>^ inLow,
278 /* Generated */ cli::array<float>^ inClose,
279 /* Generated */ [Out]int% outBegIdx,
280 /* Generated */ [Out]int% outNBElement,
281 /* Generated */ cli::array<int>^ outInteger )
282 /* Generated */ #elif defined( _JAVA )
283 /* Generated */ public RetCode cdlInNeck( int startIdx,
284 /* Generated */ int endIdx,
285 /* Generated */ float inOpen[],
286 /* Generated */ float inHigh[],
287 /* Generated */ float inLow[],
288 /* Generated */ float inClose[],
289 /* Generated */ MInteger outBegIdx,
290 /* Generated */ MInteger outNBElement,
291 /* Generated */ int outInteger[] )
292 /* Generated */ #else
293 /* Generated */ TA_RetCode TA_S_CDLINNECK( int startIdx,
294 /* Generated */ int endIdx,
295 /* Generated */ const float inOpen[],
296 /* Generated */ const float inHigh[],
297 /* Generated */ const float inLow[],
298 /* Generated */ const float inClose[],
299 /* Generated */ int *outBegIdx,
300 /* Generated */ int *outNBElement,
301 /* Generated */ int outInteger[] )
302 /* Generated */ #endif
303 /* Generated */ {
304 /* Generated */ double EqualPeriodTotal, BodyLongPeriodTotal;
305 /* Generated */ int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal;
306 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
307 /* Generated */ if( startIdx < 0 )
308 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
309 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
310 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
311 /* Generated */ #if !defined(_JAVA)
312 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
313 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
314 /* Generated */ #endif
315 /* Generated */ #if !defined(_JAVA)
316 /* Generated */ if( !outInteger )
317 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
318 /* Generated */ #endif
319 /* Generated */ #endif
320 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLINNECK)();
321 /* Generated */ if( startIdx < lookbackTotal )
322 /* Generated */ startIdx = lookbackTotal;
323 /* Generated */ if( startIdx > endIdx )
324 /* Generated */ {
325 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
326 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
327 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
328 /* Generated */ }
329 /* Generated */ EqualPeriodTotal = 0;
330 /* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal);
331 /* Generated */ BodyLongPeriodTotal = 0;
332 /* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong);
333 /* Generated */ i = EqualTrailingIdx;
334 /* Generated */ while( i < startIdx ) {
335 /* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 );
336 /* Generated */ i++;
337 /* Generated */ }
338 /* Generated */ i = BodyLongTrailingIdx;
339 /* Generated */ while( i < startIdx ) {
340 /* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 );
341 /* Generated */ i++;
342 /* Generated */ }
343 /* Generated */ i = startIdx;
344 /* Generated */ outIdx = 0;
345 /* Generated */ do
346 /* Generated */ {
347 /* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black
348 /* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long
349 /* Generated */ TA_CANDLECOLOR(i) == 1 && // 2nd: white
350 /* Generated */ inOpen[i] < inLow[i-1] && // open below prior low
351 /* Generated */ inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close slightly into prior body
352 /* Generated */ inClose[i] >= inClose[i-1]
353 /* Generated */ )
354 /* Generated */ outInteger[outIdx++] = -100;
355 /* Generated */ else
356 /* Generated */ outInteger[outIdx++] = 0;
357 /* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 );
358 /* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 )
359 /* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 );
360 /* Generated */ i++;
361 /* Generated */ EqualTrailingIdx++;
362 /* Generated */ BodyLongTrailingIdx++;
363 /* Generated */ } while( i <= endIdx );
364 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
365 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
366 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
367 /* Generated */ }
368 /* Generated */
369 /* Generated */ #if defined( _MANAGED )
370 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
371 /* Generated */ #endif
372 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
373
374