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 * 120305 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 )
CdlHikkakeLookback(void)81 /* Generated */ int Core::CdlHikkakeLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlHikkakeLookback( )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLHIKKAKE_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 5;
100 }
101
102 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
103 /*
104 * TA_CDLHIKKAKE - Hikkake Pattern
105 *
106 * Input = Open, High, Low, Close
107 * Output = int
108 *
109 */
110 /* Generated */
111 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
112 /* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx,
113 /* Generated */ int endIdx,
114 /* Generated */ SubArray^ inOpen,
115 /* Generated */ SubArray^ inHigh,
116 /* Generated */ SubArray^ inLow,
117 /* Generated */ SubArray^ inClose,
118 /* Generated */ [Out]int% outBegIdx,
119 /* Generated */ [Out]int% outNBElement,
120 /* Generated */ cli::array<int>^ outInteger )
121 /* Generated */ #elif defined( _MANAGED )
122 /* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx,
123 /* Generated */ int endIdx,
124 /* Generated */ cli::array<double>^ inOpen,
125 /* Generated */ cli::array<double>^ inHigh,
126 /* Generated */ cli::array<double>^ inLow,
127 /* Generated */ cli::array<double>^ inClose,
128 /* Generated */ [Out]int% outBegIdx,
129 /* Generated */ [Out]int% outNBElement,
130 /* Generated */ cli::array<int>^ outInteger )
131 /* Generated */ #elif defined( _JAVA )
132 /* Generated */ public RetCode cdlHikkake( int startIdx,
133 /* Generated */ int endIdx,
134 /* Generated */ double inOpen[],
135 /* Generated */ double inHigh[],
136 /* Generated */ double inLow[],
137 /* Generated */ double inClose[],
138 /* Generated */ MInteger outBegIdx,
139 /* Generated */ MInteger outNBElement,
140 /* Generated */ int outInteger[] )
141 /* Generated */ #else
142 /* Generated */ TA_RetCode TA_CDLHIKKAKE( int startIdx,
143 /* Generated */ int endIdx,
144 /* Generated */ const double inOpen[],
145 /* Generated */ const double inHigh[],
146 /* Generated */ const double inLow[],
147 /* Generated */ const double inClose[],
148 /* Generated */ int *outBegIdx,
149 /* Generated */ int *outNBElement,
150 /* Generated */ int outInteger[] )
151 /* Generated */ #endif
152 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
153 {
154 /* Insert local variables here. */
155 int i, outIdx, lookbackTotal, patternIdx, patternResult;
156
157 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
158 /* Generated */
159 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
160 /* Generated */
161 /* Generated */ /* Validate the requested output range. */
162 /* Generated */ if( startIdx < 0 )
163 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
164 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
165 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
166 /* Generated */
167 /* Generated */ #if !defined(_JAVA)
168 /* Generated */ /* Verify required price component. */
169 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
170 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
171 /* Generated */
172 /* Generated */ #endif /* !defined(_JAVA)*/
173 /* Generated */ #if !defined(_JAVA)
174 /* Generated */ if( !outInteger )
175 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
176 /* Generated */
177 /* Generated */ #endif /* !defined(_JAVA) */
178 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
179 /* Generated */
180 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
181
182 /* Identify the minimum number of price bar needed
183 * to calculate at least one output.
184 */
185
186 lookbackTotal = LOOKBACK_CALL(CDLHIKKAKE)();
187
188 /* Move up the start index if there is not
189 * enough initial data.
190 */
191 if( startIdx < lookbackTotal )
192 startIdx = lookbackTotal;
193
194 /* Make sure there is still something to evaluate. */
195 if( startIdx > endIdx )
196 {
197 VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
198 VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
199 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
200 }
201
202 /* Do the calculation using tight loops. */
203 /* Add-up the initial period, except for the last value. */
204 patternIdx = 0;
205 patternResult = 0;
206
207 i = startIdx - 3;
208 while( i < startIdx ) {
209 /* copy here the pattern recognition code below */
210 if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low
211 ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low
212 ||
213 ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low
214 )
215 ) {
216 patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 );
217 patternIdx = i;
218 } else
219 /* search for confirmation if hikkake was no more than 3 bars ago */
220 if( i <= patternIdx+3 &&
221 ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd
222 ||
223 ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd
224 )
225 )
226 patternIdx = 0;
227 i++;
228 }
229
230 i = startIdx;
231
232 /* Proceed with the calculation for the requested range.
233 * Must have:
234 * - first and second candle: inside bar (2nd has lower high and higher low than 1st)
235 * - third candle: lower high and lower low than 2nd (higher high and higher low than 2nd)
236 * outInteger[hikkakebar] is positive (1 to 100) or negative (-1 to -100) meaning bullish or bearish hikkake
237 * Confirmation could come in the next 3 days with:
238 * - a day that closes higher than the high (lower than the low) of the 2nd candle
239 * outInteger[confirmationbar] is equal to 100 + the bullish hikkake result or -100 - the bearish hikkake result
240 * Note: if confirmation and a new hikkake come at the same bar, only the new hikkake is reported (the new hikkake
241 * overwrites the confirmation of the old hikkake)
242 */
243 outIdx = 0;
244 do
245 {
246 if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low
247 ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low
248 ||
249 ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low
250 )
251 ) {
252 patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 );
253 patternIdx = i;
254 outInteger[outIdx++] = patternResult;
255 } else
256 /* search for confirmation if hikkake was no more than 3 bars ago */
257 if( i <= patternIdx+3 &&
258 ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd
259 ||
260 ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd
261 )
262 ) {
263 outInteger[outIdx++] = patternResult + 100 * ( patternResult > 0 ? 1 : -1 );
264 patternIdx = 0;
265 } else
266 outInteger[outIdx++] = 0;
267 i++;
268 } while( i <= endIdx );
269
270 /* All done. Indicate the output limits and return. */
271 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
272 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
273
274 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
275 }
276
277 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
278 /* Generated */
279 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
280 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
281 /* Generated */ #undef TA_PREFIX
282 /* Generated */ #define TA_PREFIX(x) TA_S_##x
283 /* Generated */ #endif
284 /* Generated */ #undef INPUT_TYPE
285 /* Generated */ #define INPUT_TYPE float
286 /* Generated */ #if defined( _MANAGED )
287 /* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx,
288 /* Generated */ int endIdx,
289 /* Generated */ cli::array<float>^ inOpen,
290 /* Generated */ cli::array<float>^ inHigh,
291 /* Generated */ cli::array<float>^ inLow,
292 /* Generated */ cli::array<float>^ inClose,
293 /* Generated */ [Out]int% outBegIdx,
294 /* Generated */ [Out]int% outNBElement,
295 /* Generated */ cli::array<int>^ outInteger )
296 /* Generated */ #elif defined( _JAVA )
297 /* Generated */ public RetCode cdlHikkake( int startIdx,
298 /* Generated */ int endIdx,
299 /* Generated */ float inOpen[],
300 /* Generated */ float inHigh[],
301 /* Generated */ float inLow[],
302 /* Generated */ float inClose[],
303 /* Generated */ MInteger outBegIdx,
304 /* Generated */ MInteger outNBElement,
305 /* Generated */ int outInteger[] )
306 /* Generated */ #else
307 /* Generated */ TA_RetCode TA_S_CDLHIKKAKE( int startIdx,
308 /* Generated */ int endIdx,
309 /* Generated */ const float inOpen[],
310 /* Generated */ const float inHigh[],
311 /* Generated */ const float inLow[],
312 /* Generated */ const float inClose[],
313 /* Generated */ int *outBegIdx,
314 /* Generated */ int *outNBElement,
315 /* Generated */ int outInteger[] )
316 /* Generated */ #endif
317 /* Generated */ {
318 /* Generated */ int i, outIdx, lookbackTotal, patternIdx, patternResult;
319 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
320 /* Generated */ if( startIdx < 0 )
321 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
322 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
323 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
324 /* Generated */ #if !defined(_JAVA)
325 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
326 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
327 /* Generated */ #endif
328 /* Generated */ #if !defined(_JAVA)
329 /* Generated */ if( !outInteger )
330 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
331 /* Generated */ #endif
332 /* Generated */ #endif
333 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHIKKAKE)();
334 /* Generated */ if( startIdx < lookbackTotal )
335 /* Generated */ startIdx = lookbackTotal;
336 /* Generated */ if( startIdx > endIdx )
337 /* Generated */ {
338 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
339 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
340 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
341 /* Generated */ }
342 /* Generated */ patternIdx = 0;
343 /* Generated */ patternResult = 0;
344 /* Generated */ i = startIdx - 3;
345 /* Generated */ while( i < startIdx ) {
346 /* Generated */ if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low
347 /* Generated */ ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low
348 /* Generated */ ||
349 /* Generated */ ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low
350 /* Generated */ )
351 /* Generated */ ) {
352 /* Generated */ patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 );
353 /* Generated */ patternIdx = i;
354 /* Generated */ } else
355 /* Generated */ if( i <= patternIdx+3 &&
356 /* Generated */ ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd
357 /* Generated */ ||
358 /* Generated */ ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd
359 /* Generated */ )
360 /* Generated */ )
361 /* Generated */ patternIdx = 0;
362 /* Generated */ i++;
363 /* Generated */ }
364 /* Generated */ i = startIdx;
365 /* Generated */ outIdx = 0;
366 /* Generated */ do
367 /* Generated */ {
368 /* Generated */ if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low
369 /* Generated */ ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low
370 /* Generated */ ||
371 /* Generated */ ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low
372 /* Generated */ )
373 /* Generated */ ) {
374 /* Generated */ patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 );
375 /* Generated */ patternIdx = i;
376 /* Generated */ outInteger[outIdx++] = patternResult;
377 /* Generated */ } else
378 /* Generated */ if( i <= patternIdx+3 &&
379 /* Generated */ ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd
380 /* Generated */ ||
381 /* Generated */ ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd
382 /* Generated */ )
383 /* Generated */ ) {
384 /* Generated */ outInteger[outIdx++] = patternResult + 100 * ( patternResult > 0 ? 1 : -1 );
385 /* Generated */ patternIdx = 0;
386 /* Generated */ } else
387 /* Generated */ outInteger[outIdx++] = 0;
388 /* Generated */ i++;
389 /* Generated */ } while( i <= endIdx );
390 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
391 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
392 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
393 /* Generated */ }
394 /* Generated */
395 /* Generated */ #if defined( _MANAGED )
396 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
397 /* Generated */ #endif
398 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
399
400