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 * 103004 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 )
CdlInvertedHammerLookback(void)81 /* Generated */ int Core::CdlInvertedHammerLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlInvertedHammerLookback( )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLINVERTEDHAMMER_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( max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowLong) ),
100 TA_CANDLEAVGPERIOD(ShadowVeryShort)
101 ) + 1;
102 }
103
104 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
105 /*
106 * TA_CDLINVERTEDHAMMER - Inverted Hammer
107 *
108 * Input = Open, High, Low, Close
109 * Output = int
110 *
111 */
112 /* Generated */
113 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
114 /* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx,
115 /* Generated */ int endIdx,
116 /* Generated */ SubArray^ inOpen,
117 /* Generated */ SubArray^ inHigh,
118 /* Generated */ SubArray^ inLow,
119 /* Generated */ SubArray^ inClose,
120 /* Generated */ [Out]int% outBegIdx,
121 /* Generated */ [Out]int% outNBElement,
122 /* Generated */ cli::array<int>^ outInteger )
123 /* Generated */ #elif defined( _MANAGED )
124 /* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx,
125 /* Generated */ int endIdx,
126 /* Generated */ cli::array<double>^ inOpen,
127 /* Generated */ cli::array<double>^ inHigh,
128 /* Generated */ cli::array<double>^ inLow,
129 /* Generated */ cli::array<double>^ inClose,
130 /* Generated */ [Out]int% outBegIdx,
131 /* Generated */ [Out]int% outNBElement,
132 /* Generated */ cli::array<int>^ outInteger )
133 /* Generated */ #elif defined( _JAVA )
134 /* Generated */ public RetCode cdlInvertedHammer( int startIdx,
135 /* Generated */ int endIdx,
136 /* Generated */ double inOpen[],
137 /* Generated */ double inHigh[],
138 /* Generated */ double inLow[],
139 /* Generated */ double inClose[],
140 /* Generated */ MInteger outBegIdx,
141 /* Generated */ MInteger outNBElement,
142 /* Generated */ int outInteger[] )
143 /* Generated */ #else
144 /* Generated */ TA_RetCode TA_CDLINVERTEDHAMMER( int startIdx,
145 /* Generated */ int endIdx,
146 /* Generated */ const double inOpen[],
147 /* Generated */ const double inHigh[],
148 /* Generated */ const double inLow[],
149 /* Generated */ const double inClose[],
150 /* Generated */ int *outBegIdx,
151 /* Generated */ int *outNBElement,
152 /* Generated */ int outInteger[] )
153 /* Generated */ #endif
154 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
155 {
156 /* Insert local variables here. */
157 double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal;
158 int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, 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(CDLINVERTEDHAMMER)();
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 BodyPeriodTotal = 0;
208 BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort);
209 ShadowLongPeriodTotal = 0;
210 ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong);
211 ShadowVeryShortPeriodTotal = 0;
212 ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
213
214 i = BodyTrailingIdx;
215 while( i < startIdx ) {
216 BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i );
217 i++;
218 }
219 i = ShadowLongTrailingIdx;
220 while( i < startIdx ) {
221 ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i );
222 i++;
223 }
224 i = ShadowVeryShortTrailingIdx;
225 while( i < startIdx ) {
226 ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i );
227 i++;
228 }
229
230 /* Proceed with the calculation for the requested range.
231 * Must have:
232 * - small real body
233 * - long upper shadow
234 * - no, or very short, lower shadow
235 * - gap down
236 * The meaning of "short", "very short" and "long" is specified with TA_SetCandleSettings;
237 * outInteger is positive (1 to 100): inverted hammer is always bullish;
238 * the user should consider that an inverted hammer must appear in a downtrend, while this function does not consider it
239 */
240 outIdx = 0;
241 do
242 {
243 if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb
244 TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long upper shadow
245 TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short lower shadow
246 TA_REALBODYGAPDOWN(i, i-1) ) // gap down
247 outInteger[outIdx++] = 100;
248 else
249 outInteger[outIdx++] = 0;
250 /* add the current range and subtract the first range: this is done after the pattern recognition
251 * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
252 */
253 BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i )
254 - TA_CANDLERANGE( BodyShort, BodyTrailingIdx );
255 ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i )
256 - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx );
257 ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i )
258 - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx );
259 i++;
260 BodyTrailingIdx++;
261 ShadowLongTrailingIdx++;
262 ShadowVeryShortTrailingIdx++;
263 } while( i <= endIdx );
264
265 /* All done. Indicate the output limits and return. */
266 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
267 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
268
269 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
270 }
271
272 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
273 /* Generated */
274 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
275 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
276 /* Generated */ #undef TA_PREFIX
277 /* Generated */ #define TA_PREFIX(x) TA_S_##x
278 /* Generated */ #endif
279 /* Generated */ #undef INPUT_TYPE
280 /* Generated */ #define INPUT_TYPE float
281 /* Generated */ #if defined( _MANAGED )
282 /* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx,
283 /* Generated */ int endIdx,
284 /* Generated */ cli::array<float>^ inOpen,
285 /* Generated */ cli::array<float>^ inHigh,
286 /* Generated */ cli::array<float>^ inLow,
287 /* Generated */ cli::array<float>^ inClose,
288 /* Generated */ [Out]int% outBegIdx,
289 /* Generated */ [Out]int% outNBElement,
290 /* Generated */ cli::array<int>^ outInteger )
291 /* Generated */ #elif defined( _JAVA )
292 /* Generated */ public RetCode cdlInvertedHammer( int startIdx,
293 /* Generated */ int endIdx,
294 /* Generated */ float inOpen[],
295 /* Generated */ float inHigh[],
296 /* Generated */ float inLow[],
297 /* Generated */ float inClose[],
298 /* Generated */ MInteger outBegIdx,
299 /* Generated */ MInteger outNBElement,
300 /* Generated */ int outInteger[] )
301 /* Generated */ #else
302 /* Generated */ TA_RetCode TA_S_CDLINVERTEDHAMMER( int startIdx,
303 /* Generated */ int endIdx,
304 /* Generated */ const float inOpen[],
305 /* Generated */ const float inHigh[],
306 /* Generated */ const float inLow[],
307 /* Generated */ const float inClose[],
308 /* Generated */ int *outBegIdx,
309 /* Generated */ int *outNBElement,
310 /* Generated */ int outInteger[] )
311 /* Generated */ #endif
312 /* Generated */ {
313 /* Generated */ double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal;
314 /* Generated */ int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal;
315 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
316 /* Generated */ if( startIdx < 0 )
317 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
318 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
319 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
320 /* Generated */ #if !defined(_JAVA)
321 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
322 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
323 /* Generated */ #endif
324 /* Generated */ #if !defined(_JAVA)
325 /* Generated */ if( !outInteger )
326 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
327 /* Generated */ #endif
328 /* Generated */ #endif
329 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLINVERTEDHAMMER)();
330 /* Generated */ if( startIdx < lookbackTotal )
331 /* Generated */ startIdx = lookbackTotal;
332 /* Generated */ if( startIdx > endIdx )
333 /* Generated */ {
334 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
335 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
336 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
337 /* Generated */ }
338 /* Generated */ BodyPeriodTotal = 0;
339 /* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort);
340 /* Generated */ ShadowLongPeriodTotal = 0;
341 /* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong);
342 /* Generated */ ShadowVeryShortPeriodTotal = 0;
343 /* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
344 /* Generated */ i = BodyTrailingIdx;
345 /* Generated */ while( i < startIdx ) {
346 /* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i );
347 /* Generated */ i++;
348 /* Generated */ }
349 /* Generated */ i = ShadowLongTrailingIdx;
350 /* Generated */ while( i < startIdx ) {
351 /* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i );
352 /* Generated */ i++;
353 /* Generated */ }
354 /* Generated */ i = ShadowVeryShortTrailingIdx;
355 /* Generated */ while( i < startIdx ) {
356 /* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i );
357 /* Generated */ i++;
358 /* Generated */ }
359 /* Generated */ outIdx = 0;
360 /* Generated */ do
361 /* Generated */ {
362 /* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb
363 /* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long upper shadow
364 /* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short lower shadow
365 /* Generated */ TA_REALBODYGAPDOWN(i, i-1) ) // gap down
366 /* Generated */ outInteger[outIdx++] = 100;
367 /* Generated */ else
368 /* Generated */ outInteger[outIdx++] = 0;
369 /* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i )
370 /* Generated */ - TA_CANDLERANGE( BodyShort, BodyTrailingIdx );
371 /* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i )
372 /* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx );
373 /* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i )
374 /* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx );
375 /* Generated */ i++;
376 /* Generated */ BodyTrailingIdx++;
377 /* Generated */ ShadowLongTrailingIdx++;
378 /* Generated */ ShadowVeryShortTrailingIdx++;
379 /* Generated */ } while( i <= endIdx );
380 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
381 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
382 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
383 /* Generated */ }
384 /* Generated */
385 /* Generated */ #if defined( _MANAGED )
386 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
387 /* Generated */ #endif
388 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
389
390