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 * 100304 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 )
CdlMorningDojiStarLookback(double optInPenetration)81 /* Generated */ int Core::CdlMorningDojiStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlMorningDojiStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLMORNINGDOJISTAR_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */
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 */ #ifndef TA_FUNC_NO_RANGE_CHECK
96 /* Generated */ if( optInPenetration == TA_REAL_DEFAULT )
97 /* Generated */ optInPenetration = 3.000000e-1;
98 /* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) )
99 /* Generated */ return -1;
100 /* Generated */
101 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
102 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
103
104 /* insert lookback code here. */
105 UNUSED_VARIABLE(optInPenetration);
106 return max( max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(BodyLong) ),
107 TA_CANDLEAVGPERIOD(BodyShort)
108 ) + 2;
109 }
110
111 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
112 /*
113 * TA_CDLMORNINGDOJISTAR - Morning Doji Star
114 *
115 * Input = Open, High, Low, Close
116 * Output = int
117 *
118 * Optional Parameters
119 * -------------------
120 * optInPenetration:(From 0 to TA_REAL_MAX)
121 * Percentage of penetration of a candle within another candle
122 *
123 *
124 */
125 /* Generated */
126 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
127 /* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx,
128 /* Generated */ int endIdx,
129 /* Generated */ SubArray^ inOpen,
130 /* Generated */ SubArray^ inHigh,
131 /* Generated */ SubArray^ inLow,
132 /* Generated */ SubArray^ inClose,
133 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
134 /* Generated */ [Out]int% outBegIdx,
135 /* Generated */ [Out]int% outNBElement,
136 /* Generated */ cli::array<int>^ outInteger )
137 /* Generated */ #elif defined( _MANAGED )
138 /* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx,
139 /* Generated */ int endIdx,
140 /* Generated */ cli::array<double>^ inOpen,
141 /* Generated */ cli::array<double>^ inHigh,
142 /* Generated */ cli::array<double>^ inLow,
143 /* Generated */ cli::array<double>^ inClose,
144 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
145 /* Generated */ [Out]int% outBegIdx,
146 /* Generated */ [Out]int% outNBElement,
147 /* Generated */ cli::array<int>^ outInteger )
148 /* Generated */ #elif defined( _JAVA )
149 /* Generated */ public RetCode cdlMorningDojiStar( int startIdx,
150 /* Generated */ int endIdx,
151 /* Generated */ double inOpen[],
152 /* Generated */ double inHigh[],
153 /* Generated */ double inLow[],
154 /* Generated */ double inClose[],
155 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
156 /* Generated */ MInteger outBegIdx,
157 /* Generated */ MInteger outNBElement,
158 /* Generated */ int outInteger[] )
159 /* Generated */ #else
160 /* Generated */ TA_RetCode TA_CDLMORNINGDOJISTAR( int startIdx,
161 /* Generated */ int endIdx,
162 /* Generated */ const double inOpen[],
163 /* Generated */ const double inHigh[],
164 /* Generated */ const double inLow[],
165 /* Generated */ const double inClose[],
166 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
167 /* Generated */ int *outBegIdx,
168 /* Generated */ int *outNBElement,
169 /* Generated */ int outInteger[] )
170 /* Generated */ #endif
171 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
172 {
173 /* Insert local variables here. */
174 double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal;
175 int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal;
176
177 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
178 /* Generated */
179 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
180 /* Generated */
181 /* Generated */ /* Validate the requested output range. */
182 /* Generated */ if( startIdx < 0 )
183 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
184 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
185 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
186 /* Generated */
187 /* Generated */ #if !defined(_JAVA)
188 /* Generated */ /* Verify required price component. */
189 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
190 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
191 /* Generated */
192 /* Generated */ #endif /* !defined(_JAVA)*/
193 /* Generated */ if( optInPenetration == TA_REAL_DEFAULT )
194 /* Generated */ optInPenetration = 3.000000e-1;
195 /* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) )
196 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
197 /* Generated */
198 /* Generated */ #if !defined(_JAVA)
199 /* Generated */ if( !outInteger )
200 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
201 /* Generated */
202 /* Generated */ #endif /* !defined(_JAVA) */
203 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
204 /* Generated */
205 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
206
207 /* Identify the minimum number of price bar needed
208 * to calculate at least one output.
209 */
210
211 lookbackTotal = LOOKBACK_CALL(CDLMORNINGDOJISTAR)(optInPenetration);
212
213 /* Move up the start index if there is not
214 * enough initial data.
215 */
216 if( startIdx < lookbackTotal )
217 startIdx = lookbackTotal;
218
219 /* Make sure there is still something to evaluate. */
220 if( startIdx > endIdx )
221 {
222 VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
223 VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
224 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
225 }
226
227 /* Do the calculation using tight loops. */
228 /* Add-up the initial period, except for the last value. */
229 BodyLongPeriodTotal = 0;
230 BodyDojiPeriodTotal = 0;
231 BodyShortPeriodTotal = 0;
232 BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong);
233 BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji);
234 BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort);
235
236 i = BodyLongTrailingIdx;
237 while( i < startIdx-2 ) {
238 BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i );
239 i++;
240 }
241 i = BodyDojiTrailingIdx;
242 while( i < startIdx-1 ) {
243 BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i );
244 i++;
245 }
246 i = BodyShortTrailingIdx;
247 while( i < startIdx ) {
248 BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i );
249 i++;
250 }
251 i = startIdx;
252
253 /* Proceed with the calculation for the requested range.
254 * Must have:
255 * - first candle: long black real body
256 * - second candle: doji gapping down
257 * - third candle: white real body that moves well within the first candle's real body
258 * The meaning of "doji" and "long" is specified with TA_SetCandleSettings
259 * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should
260 * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want
261 * it to be relatively long
262 * outInteger is positive (1 to 100): morning doji star is always bullish;
263 * the user should consider that a morning star is significant when it appears in a downtrend,
264 * while this function does not consider the trend
265 */
266 outIdx = 0;
267 do
268 {
269 if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long
270 TA_CANDLECOLOR(i-2) == -1 && // black
271 TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji
272 TA_REALBODYGAPDOWN(i-1,i-2) && // gapping down
273 TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short
274 TA_CANDLECOLOR(i) == 1 && // white real body
275 inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb
276 )
277 outInteger[outIdx++] = 100;
278 else
279 outInteger[outIdx++] = 0;
280 /* add the current range and subtract the first range: this is done after the pattern recognition
281 * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
282 */
283 BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx );
284 BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx );
285 BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx );
286 i++;
287 BodyLongTrailingIdx++;
288 BodyDojiTrailingIdx++;
289 BodyShortTrailingIdx++;
290 } while( i <= endIdx );
291
292 /* All done. Indicate the output limits and return. */
293 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
294 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
295
296 return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
297 }
298
299 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
300 /* Generated */
301 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
302 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
303 /* Generated */ #undef TA_PREFIX
304 /* Generated */ #define TA_PREFIX(x) TA_S_##x
305 /* Generated */ #endif
306 /* Generated */ #undef INPUT_TYPE
307 /* Generated */ #define INPUT_TYPE float
308 /* Generated */ #if defined( _MANAGED )
309 /* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx,
310 /* Generated */ int endIdx,
311 /* Generated */ cli::array<float>^ inOpen,
312 /* Generated */ cli::array<float>^ inHigh,
313 /* Generated */ cli::array<float>^ inLow,
314 /* Generated */ cli::array<float>^ inClose,
315 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
316 /* Generated */ [Out]int% outBegIdx,
317 /* Generated */ [Out]int% outNBElement,
318 /* Generated */ cli::array<int>^ outInteger )
319 /* Generated */ #elif defined( _JAVA )
320 /* Generated */ public RetCode cdlMorningDojiStar( int startIdx,
321 /* Generated */ int endIdx,
322 /* Generated */ float inOpen[],
323 /* Generated */ float inHigh[],
324 /* Generated */ float inLow[],
325 /* Generated */ float inClose[],
326 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
327 /* Generated */ MInteger outBegIdx,
328 /* Generated */ MInteger outNBElement,
329 /* Generated */ int outInteger[] )
330 /* Generated */ #else
331 /* Generated */ TA_RetCode TA_S_CDLMORNINGDOJISTAR( int startIdx,
332 /* Generated */ int endIdx,
333 /* Generated */ const float inOpen[],
334 /* Generated */ const float inHigh[],
335 /* Generated */ const float inLow[],
336 /* Generated */ const float inClose[],
337 /* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */
338 /* Generated */ int *outBegIdx,
339 /* Generated */ int *outNBElement,
340 /* Generated */ int outInteger[] )
341 /* Generated */ #endif
342 /* Generated */ {
343 /* Generated */ double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal;
344 /* Generated */ int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal;
345 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
346 /* Generated */ if( startIdx < 0 )
347 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
348 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
349 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
350 /* Generated */ #if !defined(_JAVA)
351 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
352 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
353 /* Generated */ #endif
354 /* Generated */ if( optInPenetration == TA_REAL_DEFAULT )
355 /* Generated */ optInPenetration = 3.000000e-1;
356 /* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) )
357 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
358 /* Generated */ #if !defined(_JAVA)
359 /* Generated */ if( !outInteger )
360 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
361 /* Generated */ #endif
362 /* Generated */ #endif
363 /* Generated */ lookbackTotal = LOOKBACK_CALL(CDLMORNINGDOJISTAR)(optInPenetration);
364 /* Generated */ if( startIdx < lookbackTotal )
365 /* Generated */ startIdx = lookbackTotal;
366 /* Generated */ if( startIdx > endIdx )
367 /* Generated */ {
368 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
369 /* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
370 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
371 /* Generated */ }
372 /* Generated */ BodyLongPeriodTotal = 0;
373 /* Generated */ BodyDojiPeriodTotal = 0;
374 /* Generated */ BodyShortPeriodTotal = 0;
375 /* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong);
376 /* Generated */ BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji);
377 /* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort);
378 /* Generated */ i = BodyLongTrailingIdx;
379 /* Generated */ while( i < startIdx-2 ) {
380 /* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i );
381 /* Generated */ i++;
382 /* Generated */ }
383 /* Generated */ i = BodyDojiTrailingIdx;
384 /* Generated */ while( i < startIdx-1 ) {
385 /* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i );
386 /* Generated */ i++;
387 /* Generated */ }
388 /* Generated */ i = BodyShortTrailingIdx;
389 /* Generated */ while( i < startIdx ) {
390 /* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i );
391 /* Generated */ i++;
392 /* Generated */ }
393 /* Generated */ i = startIdx;
394 /* Generated */ outIdx = 0;
395 /* Generated */ do
396 /* Generated */ {
397 /* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long
398 /* Generated */ TA_CANDLECOLOR(i-2) == -1 && // black
399 /* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji
400 /* Generated */ TA_REALBODYGAPDOWN(i-1,i-2) && // gapping down
401 /* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short
402 /* Generated */ TA_CANDLECOLOR(i) == 1 && // white real body
403 /* Generated */ inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb
404 /* Generated */ )
405 /* Generated */ outInteger[outIdx++] = 100;
406 /* Generated */ else
407 /* Generated */ outInteger[outIdx++] = 0;
408 /* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx );
409 /* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx );
410 /* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx );
411 /* Generated */ i++;
412 /* Generated */ BodyLongTrailingIdx++;
413 /* Generated */ BodyDojiTrailingIdx++;
414 /* Generated */ BodyShortTrailingIdx++;
415 /* Generated */ } while( i <= endIdx );
416 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
417 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
418 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
419 /* Generated */ }
420 /* Generated */
421 /* Generated */ #if defined( _MANAGED )
422 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
423 /* Generated */ #endif
424 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
425
426