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 )
CdlRickshawManLookback(void)81 /* Generated */ int Core::CdlRickshawManLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlRickshawManLookback( )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLRICKSHAWMAN_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(ShadowLong) ),
100 TA_CANDLEAVGPERIOD(Near)
101 );
102 }
103
104 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
105 /*
106 * TA_CDLRICKSHAWMAN - Rickshaw Man
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::CdlRickshawMan( 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::CdlRickshawMan( 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 cdlRickshawMan( 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_CDLRICKSHAWMAN( 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, ShadowLongPeriodTotal, NearPeriodTotal;
158 int i, outIdx, BodyDojiTrailingIdx, ShadowLongTrailingIdx, NearTrailingIdx, 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(CDLRICKSHAWMAN)();
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 ShadowLongPeriodTotal = 0;
210 ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong);
211 NearPeriodTotal = 0;
212 NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near);
213
214 i = BodyDojiTrailingIdx;
215 while( i < startIdx ) {
216 BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i );
217 i++;
218 }
219 i = ShadowLongTrailingIdx;
220 while( i < startIdx ) {
221 ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i );
222 i++;
223 }
224 i = NearTrailingIdx;
225 while( i < startIdx ) {
226 NearPeriodTotal += TA_CANDLERANGE( Near, i );
227 i++;
228 }
229
230 /* Proceed with the calculation for the requested range.
231 *
232 * Must have:
233 * - doji body
234 * - two long shadows
235 * - body near the midpoint of the high-low range
236 * The meaning of "doji" and "near" is specified with TA_SetCandleSettings
237 * outInteger is always positive (1 to 100) but this does not mean it is bullish: rickshaw man shows uncertainty
238 */
239 outIdx = 0;
240 do
241 {
242 if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && // doji
243 TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow
244 TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow
245 ( // body near midpoint
246 min( inOpen[i], inClose[i] )
247 <= inLow[i] + TA_HIGHLOWRANGE(i) / 2 + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i )
248 &&
249 max( inOpen[i], inClose[i] )
250 >= inLow[i] + TA_HIGHLOWRANGE(i) / 2 - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i )
251 )
252 )
253 outInteger[outIdx++] = 100;
254 else
255 outInteger[outIdx++] = 0;
256 /* add the current range and subtract the first range: this is done after the pattern recognition
257 * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
258 */
259 BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx );
260 ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx );
261 NearPeriodTotal += TA_CANDLERANGE( Near, i ) - TA_CANDLERANGE( Near, NearTrailingIdx );
262 i++;
263 BodyDojiTrailingIdx++;
264 ShadowLongTrailingIdx++;
265 NearTrailingIdx++;
266 } while( i <= endIdx );
267
268 /* All done. Indicate the output limits and return. */
269 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
270 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
271
272 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
273 }
274
275 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
276 /* Generated */
277 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
278 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
279 /* Generated */ #undef TA_PREFIX
280 /* Generated */ #define TA_PREFIX(x) TA_S_##x
281 /* Generated */ #endif
282 /* Generated */ #undef INPUT_TYPE
283 /* Generated */ #define INPUT_TYPE float
284 /* Generated */ #if defined( _MANAGED )
285 /* Generated */ enum class Core::RetCode Core::CdlRickshawMan( int startIdx,
286 /* Generated */ int endIdx,
287 /* Generated */ cli::array<float>^ inOpen,
288 /* Generated */ cli::array<float>^ inHigh,
289 /* Generated */ cli::array<float>^ inLow,
290 /* Generated */ cli::array<float>^ inClose,
291 /* Generated */ [Out]int% outBegIdx,
292 /* Generated */ [Out]int% outNBElement,
293 /* Generated */ cli::array<int>^ outInteger )
294 /* Generated */ #elif defined( _JAVA )
295 /* Generated */ public RetCode cdlRickshawMan( int startIdx,
296 /* Generated */ int endIdx,
297 /* Generated */ float inOpen[],
298 /* Generated */ float inHigh[],
299 /* Generated */ float inLow[],
300 /* Generated */ float inClose[],
301 /* Generated */ MInteger outBegIdx,
302 /* Generated */ MInteger outNBElement,
303 /* Generated */ int outInteger[] )
304 /* Generated */ #else
305 /* Generated */ TA_RetCode TA_S_CDLRICKSHAWMAN( int startIdx,
306 /* Generated */ int endIdx,
307 /* Generated */ const float inOpen[],
308 /* Generated */ const float inHigh[],
309 /* Generated */ const float inLow[],
310 /* Generated */ const float inClose[],
311 /* Generated */ int *outBegIdx,
312 /* Generated */ int *outNBElement,
313 /* Generated */ int outInteger[] )
314 /* Generated */ #endif
315 /* Generated */ {
316 /* Generated */ double BodyDojiPeriodTotal, ShadowLongPeriodTotal, NearPeriodTotal;
317 /* Generated */ int i, outIdx, BodyDojiTrailingIdx, ShadowLongTrailingIdx, NearTrailingIdx, lookbackTotal;
318 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
319 /* Generated */ if( startIdx < 0 )
320 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
321 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
322 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
323 /* Generated */ #if !defined(_JAVA)
324 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
325 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
326 /* Generated */ #endif
327 /* Generated */ #if !defined(_JAVA)
328 /* Generated */ if( !outInteger )
329 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
330 /* Generated */ #endif
331 /* Generated */ #endif
332 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLRICKSHAWMAN)();
333 /* Generated */ if( startIdx < lookbackTotal )
334 /* Generated */ startIdx = lookbackTotal;
335 /* Generated */ if( startIdx > endIdx )
336 /* Generated */ {
337 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
338 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
339 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
340 /* Generated */ }
341 /* Generated */ BodyDojiPeriodTotal = 0;
342 /* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji);
343 /* Generated */ ShadowLongPeriodTotal = 0;
344 /* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong);
345 /* Generated */ NearPeriodTotal = 0;
346 /* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near);
347 /* Generated */ i = BodyDojiTrailingIdx;
348 /* Generated */ while( i < startIdx ) {
349 /* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i );
350 /* Generated */ i++;
351 /* Generated */ }
352 /* Generated */ i = ShadowLongTrailingIdx;
353 /* Generated */ while( i < startIdx ) {
354 /* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i );
355 /* Generated */ i++;
356 /* Generated */ }
357 /* Generated */ i = NearTrailingIdx;
358 /* Generated */ while( i < startIdx ) {
359 /* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i );
360 /* Generated */ i++;
361 /* Generated */ }
362 /* Generated */ outIdx = 0;
363 /* Generated */ do
364 /* Generated */ {
365 /* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && // doji
366 /* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow
367 /* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow
368 /* Generated */ ( // body near midpoint
369 /* Generated */ min( inOpen[i], inClose[i] )
370 /* Generated */ <= inLow[i] + TA_HIGHLOWRANGE(i) / 2 + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i )
371 /* Generated */ &&
372 /* Generated */ max( inOpen[i], inClose[i] )
373 /* Generated */ >= inLow[i] + TA_HIGHLOWRANGE(i) / 2 - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i )
374 /* Generated */ )
375 /* Generated */ )
376 /* Generated */ outInteger[outIdx++] = 100;
377 /* Generated */ else
378 /* Generated */ outInteger[outIdx++] = 0;
379 /* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx );
380 /* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx );
381 /* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i ) - TA_CANDLERANGE( Near, NearTrailingIdx );
382 /* Generated */ i++;
383 /* Generated */ BodyDojiTrailingIdx++;
384 /* Generated */ ShadowLongTrailingIdx++;
385 /* Generated */ NearTrailingIdx++;
386 /* Generated */ } while( i <= endIdx );
387 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
388 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
389 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
390 /* Generated */ }
391 /* Generated */
392 /* Generated */ #if defined( _MANAGED )
393 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
394 /* Generated */ #endif
395 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
396
397