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 )
CdlTakuriLookback(void)81 /* Generated */ int Core::CdlTakuriLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlTakuriLookback(  )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLTAKURI_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(BodyDoji), TA_CANDLEAVGPERIOD(ShadowVeryShort) ),
100                 TA_CANDLEAVGPERIOD(ShadowVeryLong)
101             );
102 }
103 
104 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
105 /*
106  * TA_CDLTAKURI - Takuri (Dragonfly Doji with very long lower shadow)
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::CdlTakuri( 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::CdlTakuri( 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 cdlTakuri( 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_CDLTAKURI( 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 BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal, ShadowVeryLongPeriodTotal;
158     int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, ShadowVeryLongTrailingIdx, 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(CDLTAKURI)();
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    BodyDojiPeriodTotal = 0;
208    BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji);
209    ShadowVeryShortPeriodTotal = 0;
210    ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
211    ShadowVeryLongPeriodTotal = 0;
212    ShadowVeryLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryLong);
213 
214    i = BodyDojiTrailingIdx;
215    while( i < startIdx ) {
216         BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i );
217         i++;
218    }
219    i = ShadowVeryShortTrailingIdx;
220    while( i < startIdx ) {
221         ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i );
222         i++;
223    }
224    i = ShadowVeryLongTrailingIdx;
225    while( i < startIdx ) {
226         ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i );
227         i++;
228    }
229 
230    /* Proceed with the calculation for the requested range.
231     *
232     * Must have:
233     * - doji body
234     * - open and close at the high of the day = no or very short upper shadow
235     * - very long lower shadow
236     * The meaning of "doji", "very short" and "very long" is specified with TA_SetCandleSettings
237     * outInteger is always positive (1 to 100) but this does not mean it is bullish: takuri must be considered
238     * relatively to the trend
239     */
240    outIdx = 0;
241    do
242    {
243         if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) &&
244             TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) &&
245             TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowVeryLongPeriodTotal, i )
246           )
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         BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx );
254         ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i )
255                                     - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx );
256         ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i )
257                                    - TA_CANDLERANGE( ShadowVeryLong, ShadowVeryLongTrailingIdx );
258         i++;
259         BodyDojiTrailingIdx++;
260         ShadowVeryShortTrailingIdx++;
261         ShadowVeryLongTrailingIdx++;
262    } while( i <= endIdx );
263 
264    /* All done. Indicate the output limits and return. */
265    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
266    VALUE_HANDLE_DEREF(outBegIdx)    = startIdx;
267 
268    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
269 }
270 
271 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
272 /* Generated */
273 /* Generated */ #define  USE_SINGLE_PRECISION_INPUT
274 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
275 /* Generated */    #undef   TA_PREFIX
276 /* Generated */    #define  TA_PREFIX(x) TA_S_##x
277 /* Generated */ #endif
278 /* Generated */ #undef   INPUT_TYPE
279 /* Generated */ #define  INPUT_TYPE float
280 /* Generated */ #if defined( _MANAGED )
281 /* Generated */ enum class Core::RetCode Core::CdlTakuri( int    startIdx,
282 /* Generated */                                           int    endIdx,
283 /* Generated */                                           cli::array<float>^ inOpen,
284 /* Generated */                                           cli::array<float>^ inHigh,
285 /* Generated */                                           cli::array<float>^ inLow,
286 /* Generated */                                           cli::array<float>^ inClose,
287 /* Generated */                                           [Out]int%    outBegIdx,
288 /* Generated */                                           [Out]int%    outNBElement,
289 /* Generated */                                           cli::array<int>^  outInteger )
290 /* Generated */ #elif defined( _JAVA )
291 /* Generated */ public RetCode cdlTakuri( int    startIdx,
292 /* Generated */                           int    endIdx,
293 /* Generated */                           float        inOpen[],
294 /* Generated */                           float        inHigh[],
295 /* Generated */                           float        inLow[],
296 /* Generated */                           float        inClose[],
297 /* Generated */                           MInteger     outBegIdx,
298 /* Generated */                           MInteger     outNBElement,
299 /* Generated */                           int           outInteger[] )
300 /* Generated */ #else
301 /* Generated */ TA_RetCode TA_S_CDLTAKURI( int    startIdx,
302 /* Generated */                            int    endIdx,
303 /* Generated */                            const float  inOpen[],
304 /* Generated */                            const float  inHigh[],
305 /* Generated */                            const float  inLow[],
306 /* Generated */                            const float  inClose[],
307 /* Generated */                            int          *outBegIdx,
308 /* Generated */                            int          *outNBElement,
309 /* Generated */                            int           outInteger[] )
310 /* Generated */ #endif
311 /* Generated */ {
312 /* Generated */     double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal, ShadowVeryLongPeriodTotal;
313 /* Generated */     int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, ShadowVeryLongTrailingIdx, lookbackTotal;
314 /* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
315 /* Generated */     if( startIdx < 0 )
316 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
317 /* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
318 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
319 /* Generated */     #if !defined(_JAVA)
320 /* Generated */     if(!inOpen||!inHigh||!inLow||!inClose)
321 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
322 /* Generated */     #endif
323 /* Generated */     #if !defined(_JAVA)
324 /* Generated */     if( !outInteger )
325 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
326 /* Generated */     #endif
327 /* Generated */  #endif
328 /* Generated */    lookbackTotal = LOOKBACK_CALL(CDLTAKURI)();
329 /* Generated */    if( startIdx < lookbackTotal )
330 /* Generated */       startIdx = lookbackTotal;
331 /* Generated */    if( startIdx > endIdx )
332 /* Generated */    {
333 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
334 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
335 /* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
336 /* Generated */    }
337 /* Generated */    BodyDojiPeriodTotal = 0;
338 /* Generated */    BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji);
339 /* Generated */    ShadowVeryShortPeriodTotal = 0;
340 /* Generated */    ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort);
341 /* Generated */    ShadowVeryLongPeriodTotal = 0;
342 /* Generated */    ShadowVeryLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryLong);
343 /* Generated */    i = BodyDojiTrailingIdx;
344 /* Generated */    while( i < startIdx ) {
345 /* Generated */         BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i );
346 /* Generated */         i++;
347 /* Generated */    }
348 /* Generated */    i = ShadowVeryShortTrailingIdx;
349 /* Generated */    while( i < startIdx ) {
350 /* Generated */         ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i );
351 /* Generated */         i++;
352 /* Generated */    }
353 /* Generated */    i = ShadowVeryLongTrailingIdx;
354 /* Generated */    while( i < startIdx ) {
355 /* Generated */         ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i );
356 /* Generated */         i++;
357 /* Generated */    }
358 /* Generated */    outIdx = 0;
359 /* Generated */    do
360 /* Generated */    {
361 /* Generated */         if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) &&
362 /* Generated */             TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) &&
363 /* Generated */             TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowVeryLongPeriodTotal, i )
364 /* Generated */           )
365 /* Generated */             outInteger[outIdx++] = 100;
366 /* Generated */         else
367 /* Generated */             outInteger[outIdx++] = 0;
368 /* Generated */         BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx );
369 /* Generated */         ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i )
370 /* Generated */                                     - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx );
371 /* Generated */         ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i )
372 /* Generated */                                    - TA_CANDLERANGE( ShadowVeryLong, ShadowVeryLongTrailingIdx );
373 /* Generated */         i++;
374 /* Generated */         BodyDojiTrailingIdx++;
375 /* Generated */         ShadowVeryShortTrailingIdx++;
376 /* Generated */         ShadowVeryLongTrailingIdx++;
377 /* Generated */    } while( i <= endIdx );
378 /* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
379 /* Generated */    VALUE_HANDLE_DEREF(outBegIdx)    = startIdx;
380 /* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
381 /* Generated */ }
382 /* Generated */
383 /* Generated */ #if defined( _MANAGED )
384 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
385 /* Generated */ #endif
386 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
387 
388