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 * 011505 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 )
CdlKickingByLengthLookback(void)81 /* Generated */ int Core::CdlKickingByLengthLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlKickingByLengthLookback( )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLKICKINGBYLENGTH_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(BodyLong)
100 ) + 1;
101 }
102
103 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
104 /*
105 * TA_CDLKICKINGBYLENGTH - Kicking - bull/bear determined by the longer marubozu
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::CdlKickingByLength( 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::CdlKickingByLength( 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 cdlKickingByLength( 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_CDLKICKINGBYLENGTH( 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,2);
157 ARRAY_LOCAL(BodyLongPeriodTotal,2);
158 int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, 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(CDLKICKINGBYLENGTH)();
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[1] = 0;
208 ShadowVeryShortPeriodTotal[0] = 0;
209 ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
210 BodyLongPeriodTotal[1] = 0;
211 BodyLongPeriodTotal[0] = 0;
212 BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong);
213
214 i = ShadowVeryShortTrailingIdx;
215 while( i < startIdx ) {
216 ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 );
217 ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i );
218 i++;
219 }
220 i = BodyLongTrailingIdx;
221 while( i < startIdx ) {
222 BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 );
223 BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i );
224 i++;
225 }
226 i = startIdx;
227
228 /* Proceed with the calculation for the requested range.
229 * Must have:
230 * - first candle: marubozu
231 * - second candle: opposite color marubozu
232 * - gap between the two candles: upside gap if black then white, downside gap if white then black
233 * The meaning of "long body" and "very short shadow" is specified with TA_SetCandleSettings
234 * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; the longer of the two
235 * marubozu determines the bullishness or bearishness of this pattern
236 */
237 outIdx = 0;
238 do
239 {
240 if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles
241 // 1st marubozu
242 TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) &&
243 TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) &&
244 TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) &&
245 // 2nd marubozu
246 TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) &&
247 TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) &&
248 TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) &&
249 // gap
250 (
251 ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLEGAPUP(i,i-1) )
252 ||
253 ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLEGAPDOWN(i,i-1) )
254 )
255 )
256 outInteger[outIdx++] = TA_CANDLECOLOR( ( TA_REALBODY(i) > TA_REALBODY(i-1) ? i : i-1 ) ) * 100;
257 else
258 outInteger[outIdx++] = 0;
259 /* add the current range and subtract the first range: this is done after the pattern recognition
260 * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
261 */
262 for (totIdx = 1; totIdx >= 0; --totIdx) {
263 BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx )
264 - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx );
265 ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx )
266 - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx );
267 }
268 i++;
269 ShadowVeryShortTrailingIdx++;
270 BodyLongTrailingIdx++;
271 } while( i <= endIdx );
272
273 /* All done. Indicate the output limits and return. */
274 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
275 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
276
277 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
278 }
279
280 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
281 /* Generated */
282 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
283 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
284 /* Generated */ #undef TA_PREFIX
285 /* Generated */ #define TA_PREFIX(x) TA_S_##x
286 /* Generated */ #endif
287 /* Generated */ #undef INPUT_TYPE
288 /* Generated */ #define INPUT_TYPE float
289 /* Generated */ #if defined( _MANAGED )
290 /* Generated */ enum class Core::RetCode Core::CdlKickingByLength( int startIdx,
291 /* Generated */ int endIdx,
292 /* Generated */ cli::array<float>^ inOpen,
293 /* Generated */ cli::array<float>^ inHigh,
294 /* Generated */ cli::array<float>^ inLow,
295 /* Generated */ cli::array<float>^ inClose,
296 /* Generated */ [Out]int% outBegIdx,
297 /* Generated */ [Out]int% outNBElement,
298 /* Generated */ cli::array<int>^ outInteger )
299 /* Generated */ #elif defined( _JAVA )
300 /* Generated */ public RetCode cdlKickingByLength( int startIdx,
301 /* Generated */ int endIdx,
302 /* Generated */ float inOpen[],
303 /* Generated */ float inHigh[],
304 /* Generated */ float inLow[],
305 /* Generated */ float inClose[],
306 /* Generated */ MInteger outBegIdx,
307 /* Generated */ MInteger outNBElement,
308 /* Generated */ int outInteger[] )
309 /* Generated */ #else
310 /* Generated */ TA_RetCode TA_S_CDLKICKINGBYLENGTH( int startIdx,
311 /* Generated */ int endIdx,
312 /* Generated */ const float inOpen[],
313 /* Generated */ const float inHigh[],
314 /* Generated */ const float inLow[],
315 /* Generated */ const float inClose[],
316 /* Generated */ int *outBegIdx,
317 /* Generated */ int *outNBElement,
318 /* Generated */ int outInteger[] )
319 /* Generated */ #endif
320 /* Generated */ {
321 /* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2);
322 /* Generated */ ARRAY_LOCAL(BodyLongPeriodTotal,2);
323 /* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal;
324 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
325 /* Generated */ if( startIdx < 0 )
326 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
327 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
328 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
329 /* Generated */ #if !defined(_JAVA)
330 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
331 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
332 /* Generated */ #endif
333 /* Generated */ #if !defined(_JAVA)
334 /* Generated */ if( !outInteger )
335 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
336 /* Generated */ #endif
337 /* Generated */ #endif
338 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLKICKINGBYLENGTH)();
339 /* Generated */ if( startIdx < lookbackTotal )
340 /* Generated */ startIdx = lookbackTotal;
341 /* Generated */ if( startIdx > endIdx )
342 /* Generated */ {
343 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
344 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
345 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
346 /* Generated */ }
347 /* Generated */ ShadowVeryShortPeriodTotal[1] = 0;
348 /* Generated */ ShadowVeryShortPeriodTotal[0] = 0;
349 /* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
350 /* Generated */ BodyLongPeriodTotal[1] = 0;
351 /* Generated */ BodyLongPeriodTotal[0] = 0;
352 /* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong);
353 /* Generated */ i = ShadowVeryShortTrailingIdx;
354 /* Generated */ while( i < startIdx ) {
355 /* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 );
356 /* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i );
357 /* Generated */ i++;
358 /* Generated */ }
359 /* Generated */ i = BodyLongTrailingIdx;
360 /* Generated */ while( i < startIdx ) {
361 /* Generated */ BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 );
362 /* Generated */ BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i );
363 /* Generated */ i++;
364 /* Generated */ }
365 /* Generated */ i = startIdx;
366 /* Generated */ outIdx = 0;
367 /* Generated */ do
368 /* Generated */ {
369 /* Generated */ if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles
370 /* Generated */ // 1st marubozu
371 /* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) &&
372 /* Generated */ TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) &&
373 /* Generated */ TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) &&
374 /* Generated */ // 2nd marubozu
375 /* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) &&
376 /* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) &&
377 /* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) &&
378 /* Generated */ // gap
379 /* Generated */ (
380 /* Generated */ ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLEGAPUP(i,i-1) )
381 /* Generated */ ||
382 /* Generated */ ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLEGAPDOWN(i,i-1) )
383 /* Generated */ )
384 /* Generated */ )
385 /* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR( ( TA_REALBODY(i) > TA_REALBODY(i-1) ? i : i-1 ) ) * 100;
386 /* Generated */ else
387 /* Generated */ outInteger[outIdx++] = 0;
388 /* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) {
389 /* Generated */ BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx )
390 /* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx );
391 /* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx )
392 /* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx );
393 /* Generated */ }
394 /* Generated */ i++;
395 /* Generated */ ShadowVeryShortTrailingIdx++;
396 /* Generated */ BodyLongTrailingIdx++;
397 /* Generated */ } while( i <= endIdx );
398 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
399 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
400 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
401 /* Generated */ }
402 /* Generated */
403 /* Generated */ #if defined( _MANAGED )
404 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
405 /* Generated */ #endif
406 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
407
408