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