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 * 103104 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 )
CdlIdentical3CrowsLookback(void)81 /* Generated */ int Core::CdlIdentical3CrowsLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlIdentical3CrowsLookback( )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLIDENTICAL3CROWS_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(ShadowVeryShort), TA_CANDLEAVGPERIOD(Equal)
100 ) + 2;
101 }
102
103 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
104 /*
105 * TA_CDLIDENTICAL3CROWS - Identical Three Crows
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::CdlIdentical3Crows( 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::CdlIdentical3Crows( 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 cdlIdentical3Crows( 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_CDLIDENTICAL3CROWS( 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 ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3);
157 ARRAY_LOCAL(EqualPeriodTotal,3);
158 int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, EqualTrailingIdx, lookbackTotal;
159
160 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
161 /* Generated */
162 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
163 /* Generated */
164 /* Generated */ /* Validate the requested output range. */
165 /* Generated */ if( startIdx < 0 )
166 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
167 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
168 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
169 /* Generated */
170 /* Generated */ #if !defined(_JAVA)
171 /* Generated */ /* Verify required price component. */
172 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
173 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
174 /* Generated */
175 /* Generated */ #endif /* !defined(_JAVA)*/
176 /* Generated */ #if !defined(_JAVA)
177 /* Generated */ if( !outInteger )
178 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
179 /* Generated */
180 /* Generated */ #endif /* !defined(_JAVA) */
181 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
182 /* Generated */
183 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
184
185 /* Identify the minimum number of price bar needed
186 * to calculate at least one output.
187 */
188
189 lookbackTotal = LOOKBACK_CALL(CDLIDENTICAL3CROWS)();
190
191 /* Move up the start index if there is not
192 * enough initial data.
193 */
194 if( startIdx < lookbackTotal )
195 startIdx = lookbackTotal;
196
197 /* Make sure there is still something to evaluate. */
198 if( startIdx > endIdx )
199 {
200 VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
201 VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
202 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
203 }
204
205 /* Do the calculation using tight loops. */
206 /* Add-up the initial period, except for the last value. */
207 ShadowVeryShortPeriodTotal[2] = 0;
208 ShadowVeryShortPeriodTotal[1] = 0;
209 ShadowVeryShortPeriodTotal[0] = 0;
210 ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
211 EqualPeriodTotal[2] = 0;
212 EqualPeriodTotal[1] = 0;
213 EqualPeriodTotal[0] = 0;
214 EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal);
215
216 i = ShadowVeryShortTrailingIdx;
217 while( i < startIdx ) {
218 ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 );
219 ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 );
220 ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i );
221 i++;
222 }
223 i = EqualTrailingIdx;
224 while( i < startIdx ) {
225 EqualPeriodTotal[2] += TA_CANDLERANGE( Equal, i-2 );
226 EqualPeriodTotal[1] += TA_CANDLERANGE( Equal, i-1 );
227 i++;
228 }
229 i = startIdx;
230
231 /* Proceed with the calculation for the requested range.
232 * Must have:
233 * - three consecutive and declining black candlesticks
234 * - each candle must have no or very short lower shadow
235 * - each candle after the first must open at or very close to the prior candle's close
236 * The meaning of "very short" is specified with TA_SetCandleSettings;
237 * the meaning of "very close" is specified with TA_SetCandleSettings (Equal);
238 * outInteger is negative (-1 to -100): identical three crows is always bearish;
239 * the user should consider that identical 3 crows is significant when it appears after a mature advance or at high levels,
240 * while this function does not consider it
241 */
242 outIdx = 0;
243 do
244 {
245 if( TA_CANDLECOLOR(i-2) == -1 && // 1st black
246 // very short lower shadow
247 TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) &&
248 TA_CANDLECOLOR(i-1) == -1 && // 2nd black
249 // very short lower shadow
250 TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) &&
251 TA_CANDLECOLOR(i) == -1 && // 3rd black
252 // very short lower shadow
253 TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) &&
254 inClose[i-2] > inClose[i-1] && // three declining
255 inClose[i-1] > inClose[i] &&
256 // 2nd black opens very close to 1st close
257 inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) &&
258 inOpen[i-1] >= inClose[i-2] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) &&
259 // 3rd black opens very close to 2nd close
260 inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 ) &&
261 inOpen[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 )
262 )
263 outInteger[outIdx++] = -100;
264 else
265 outInteger[outIdx++] = 0;
266 /* add the current range and subtract the first range: this is done after the pattern recognition
267 * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
268 */
269 for (totIdx = 2; totIdx >= 0; --totIdx)
270 ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx )
271 - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx );
272 for (totIdx = 2; totIdx >= 1; --totIdx)
273 EqualPeriodTotal[totIdx] += TA_CANDLERANGE( Equal, i-totIdx )
274 - TA_CANDLERANGE( Equal, EqualTrailingIdx-totIdx );
275 i++;
276 ShadowVeryShortTrailingIdx++;
277 EqualTrailingIdx++;
278 } while( i <= endIdx );
279
280 /* All done. Indicate the output limits and return. */
281 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
282 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
283
284 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
285 }
286
287 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
288 /* Generated */
289 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
290 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
291 /* Generated */ #undef TA_PREFIX
292 /* Generated */ #define TA_PREFIX(x) TA_S_##x
293 /* Generated */ #endif
294 /* Generated */ #undef INPUT_TYPE
295 /* Generated */ #define INPUT_TYPE float
296 /* Generated */ #if defined( _MANAGED )
297 /* Generated */ enum class Core::RetCode Core::CdlIdentical3Crows( int startIdx,
298 /* Generated */ int endIdx,
299 /* Generated */ cli::array<float>^ inOpen,
300 /* Generated */ cli::array<float>^ inHigh,
301 /* Generated */ cli::array<float>^ inLow,
302 /* Generated */ cli::array<float>^ inClose,
303 /* Generated */ [Out]int% outBegIdx,
304 /* Generated */ [Out]int% outNBElement,
305 /* Generated */ cli::array<int>^ outInteger )
306 /* Generated */ #elif defined( _JAVA )
307 /* Generated */ public RetCode cdlIdentical3Crows( int startIdx,
308 /* Generated */ int endIdx,
309 /* Generated */ float inOpen[],
310 /* Generated */ float inHigh[],
311 /* Generated */ float inLow[],
312 /* Generated */ float inClose[],
313 /* Generated */ MInteger outBegIdx,
314 /* Generated */ MInteger outNBElement,
315 /* Generated */ int outInteger[] )
316 /* Generated */ #else
317 /* Generated */ TA_RetCode TA_S_CDLIDENTICAL3CROWS( int startIdx,
318 /* Generated */ int endIdx,
319 /* Generated */ const float inOpen[],
320 /* Generated */ const float inHigh[],
321 /* Generated */ const float inLow[],
322 /* Generated */ const float inClose[],
323 /* Generated */ int *outBegIdx,
324 /* Generated */ int *outNBElement,
325 /* Generated */ int outInteger[] )
326 /* Generated */ #endif
327 /* Generated */ {
328 /* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3);
329 /* Generated */ ARRAY_LOCAL(EqualPeriodTotal,3);
330 /* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, EqualTrailingIdx, lookbackTotal;
331 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
332 /* Generated */ if( startIdx < 0 )
333 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
334 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
335 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
336 /* Generated */ #if !defined(_JAVA)
337 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
338 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
339 /* Generated */ #endif
340 /* Generated */ #if !defined(_JAVA)
341 /* Generated */ if( !outInteger )
342 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
343 /* Generated */ #endif
344 /* Generated */ #endif
345 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLIDENTICAL3CROWS)();
346 /* Generated */ if( startIdx < lookbackTotal )
347 /* Generated */ startIdx = lookbackTotal;
348 /* Generated */ if( startIdx > endIdx )
349 /* Generated */ {
350 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
351 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
352 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
353 /* Generated */ }
354 /* Generated */ ShadowVeryShortPeriodTotal[2] = 0;
355 /* Generated */ ShadowVeryShortPeriodTotal[1] = 0;
356 /* Generated */ ShadowVeryShortPeriodTotal[0] = 0;
357 /* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
358 /* Generated */ EqualPeriodTotal[2] = 0;
359 /* Generated */ EqualPeriodTotal[1] = 0;
360 /* Generated */ EqualPeriodTotal[0] = 0;
361 /* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal);
362 /* Generated */ i = ShadowVeryShortTrailingIdx;
363 /* Generated */ while( i < startIdx ) {
364 /* Generated */ ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 );
365 /* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 );
366 /* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i );
367 /* Generated */ i++;
368 /* Generated */ }
369 /* Generated */ i = EqualTrailingIdx;
370 /* Generated */ while( i < startIdx ) {
371 /* Generated */ EqualPeriodTotal[2] += TA_CANDLERANGE( Equal, i-2 );
372 /* Generated */ EqualPeriodTotal[1] += TA_CANDLERANGE( Equal, i-1 );
373 /* Generated */ i++;
374 /* Generated */ }
375 /* Generated */ i = startIdx;
376 /* Generated */ outIdx = 0;
377 /* Generated */ do
378 /* Generated */ {
379 /* Generated */ if( TA_CANDLECOLOR(i-2) == -1 && // 1st black
380 /* Generated */ // very short lower shadow
381 /* Generated */ TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) &&
382 /* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd black
383 /* Generated */ // very short lower shadow
384 /* Generated */ TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) &&
385 /* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd black
386 /* Generated */ // very short lower shadow
387 /* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) &&
388 /* Generated */ inClose[i-2] > inClose[i-1] && // three declining
389 /* Generated */ inClose[i-1] > inClose[i] &&
390 /* Generated */ // 2nd black opens very close to 1st close
391 /* Generated */ inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) &&
392 /* Generated */ inOpen[i-1] >= inClose[i-2] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) &&
393 /* Generated */ // 3rd black opens very close to 2nd close
394 /* Generated */ inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 ) &&
395 /* Generated */ inOpen[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 )
396 /* Generated */ )
397 /* Generated */ outInteger[outIdx++] = -100;
398 /* Generated */ else
399 /* Generated */ outInteger[outIdx++] = 0;
400 /* Generated */ for (totIdx = 2; totIdx >= 0; --totIdx)
401 /* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx )
402 /* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx );
403 /* Generated */ for (totIdx = 2; totIdx >= 1; --totIdx)
404 /* Generated */ EqualPeriodTotal[totIdx] += TA_CANDLERANGE( Equal, i-totIdx )
405 /* Generated */ - TA_CANDLERANGE( Equal, EqualTrailingIdx-totIdx );
406 /* Generated */ i++;
407 /* Generated */ ShadowVeryShortTrailingIdx++;
408 /* Generated */ EqualTrailingIdx++;
409 /* Generated */ } while( i <= endIdx );
410 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
411 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
412 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
413 /* Generated */ }
414 /* Generated */
415 /* Generated */ #if defined( _MANAGED )
416 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
417 /* Generated */ #endif
418 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
419
420