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  *  020605 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 )
CdlGapSideSideWhiteLookback(void)81 /* Generated */ int Core::CdlGapSideSideWhiteLookback( void )
82 /* Generated */
83 /* Generated */ #elif defined( _JAVA )
84 /* Generated */ public int cdlGapSideSideWhiteLookback(  )
85 /* Generated */
86 /* Generated */ #else
87 /* Generated */ int TA_CDLGAPSIDESIDEWHITE_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( TA_CANDLEAVGPERIOD(Near), TA_CANDLEAVGPERIOD(Equal) ) + 2;
100 }
101 
102 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
103 /*
104  * TA_CDLGAPSIDESIDEWHITE - Up/Down-gap side-by-side white lines
105  *
106  * Input  = Open, High, Low, Close
107  * Output = int
108  *
109  */
110 /* Generated */
111 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
112 /* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int    startIdx,
113 /* Generated */                                                     int    endIdx,
114 /* Generated */                                                     SubArray^    inOpen,
115 /* Generated */                                                     SubArray^    inHigh,
116 /* Generated */                                                     SubArray^    inLow,
117 /* Generated */                                                     SubArray^    inClose,
118 /* Generated */                                                     [Out]int%    outBegIdx,
119 /* Generated */                                                     [Out]int%    outNBElement,
120 /* Generated */                                                     cli::array<int>^  outInteger )
121 /* Generated */ #elif defined( _MANAGED )
122 /* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int    startIdx,
123 /* Generated */                                                     int    endIdx,
124 /* Generated */                                                     cli::array<double>^ inOpen,
125 /* Generated */                                                     cli::array<double>^ inHigh,
126 /* Generated */                                                     cli::array<double>^ inLow,
127 /* Generated */                                                     cli::array<double>^ inClose,
128 /* Generated */                                                     [Out]int%    outBegIdx,
129 /* Generated */                                                     [Out]int%    outNBElement,
130 /* Generated */                                                     cli::array<int>^  outInteger )
131 /* Generated */ #elif defined( _JAVA )
132 /* Generated */ public RetCode cdlGapSideSideWhite( int    startIdx,
133 /* Generated */                                     int    endIdx,
134 /* Generated */                                     double       inOpen[],
135 /* Generated */                                     double       inHigh[],
136 /* Generated */                                     double       inLow[],
137 /* Generated */                                     double       inClose[],
138 /* Generated */                                     MInteger     outBegIdx,
139 /* Generated */                                     MInteger     outNBElement,
140 /* Generated */                                     int           outInteger[] )
141 /* Generated */ #else
142 /* Generated */ TA_RetCode TA_CDLGAPSIDESIDEWHITE( int    startIdx,
143 /* Generated */                                    int    endIdx,
144 /* Generated */                                    const double inOpen[],
145 /* Generated */                                    const double inHigh[],
146 /* Generated */                                    const double inLow[],
147 /* Generated */                                    const double inClose[],
148 /* Generated */                                    int          *outBegIdx,
149 /* Generated */                                    int          *outNBElement,
150 /* Generated */                                    int           outInteger[] )
151 /* Generated */ #endif
152 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
153 {
154    /* Insert local variables here. */
155     double NearPeriodTotal, EqualPeriodTotal;
156     int i, outIdx, NearTrailingIdx, EqualTrailingIdx, lookbackTotal;
157 
158 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
159 /* Generated */
160 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
161 /* Generated */
162 /* Generated */    /* Validate the requested output range. */
163 /* Generated */    if( startIdx < 0 )
164 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
165 /* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
166 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
167 /* Generated */
168 /* Generated */    #if !defined(_JAVA)
169 /* Generated */    /* Verify required price component. */
170 /* Generated */    if(!inOpen||!inHigh||!inLow||!inClose)
171 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
172 /* Generated */
173 /* Generated */    #endif /* !defined(_JAVA)*/
174 /* Generated */    #if !defined(_JAVA)
175 /* Generated */    if( !outInteger )
176 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
177 /* Generated */
178 /* Generated */    #endif /* !defined(_JAVA) */
179 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
180 /* Generated */
181 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
182 
183    /* Identify the minimum number of price bar needed
184     * to calculate at least one output.
185     */
186 
187    lookbackTotal = LOOKBACK_CALL(CDLGAPSIDESIDEWHITE)();
188 
189    /* Move up the start index if there is not
190     * enough initial data.
191     */
192    if( startIdx < lookbackTotal )
193       startIdx = lookbackTotal;
194 
195    /* Make sure there is still something to evaluate. */
196    if( startIdx > endIdx )
197    {
198       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
199       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
200       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
201    }
202 
203    /* Do the calculation using tight loops. */
204    /* Add-up the initial period, except for the last value. */
205    NearPeriodTotal = 0;
206    EqualPeriodTotal = 0;
207    NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near);
208    EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal);
209 
210    i = NearTrailingIdx;
211    while( i < startIdx ) {
212         NearPeriodTotal += TA_CANDLERANGE( Near, i-1 );
213         i++;
214    }
215    i = EqualTrailingIdx;
216    while( i < startIdx ) {
217         EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 );
218         i++;
219    }
220    i = startIdx;
221 
222    /* Proceed with the calculation for the requested range.
223     * Must have:
224     * - upside or downside gap (between the bodies)
225     * - first candle after the window: white candlestick
226     * - second candle after the window: white candlestick with similar size (near the same) and about the same
227     *   open (equal) of the previous candle
228     * - the second candle does not close the window
229     * The meaning of "near" and "equal" is specified with TA_SetCandleSettings
230     * outInteger is positive (1 to 100) or negative (-1 to -100): the user should consider that upside
231     * or downside gap side-by-side white lines is significant when it appears in a trend, while this function
232     * does not consider the trend
233     */
234    outIdx = 0;
235    do
236    {
237         if(
238             ( // upside or downside gap between the 1st candle and both the next 2 candles
239               ( TA_REALBODYGAPUP(i-1,i-2) && TA_REALBODYGAPUP(i,i-2) )
240               ||
241               ( TA_REALBODYGAPDOWN(i-1,i-2) && TA_REALBODYGAPDOWN(i,i-2) )
242             ) &&
243             TA_CANDLECOLOR(i-1) == 1 &&                                                                 // 2nd: white
244             TA_CANDLECOLOR(i) == 1 &&                                                                   // 3rd: white
245             TA_REALBODY(i) >= TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) &&   // same size 2 and 3
246             TA_REALBODY(i) <= TA_REALBODY(i-1) + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) &&
247             inOpen[i] >= inOpen[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) &&           // same open 2 and 3
248             inOpen[i] <= inOpen[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 )
249           )
250             outInteger[outIdx++] = ( TA_REALBODYGAPUP(i-1,i-2) ? 100 : -100 );
251         else
252             outInteger[outIdx++] = 0;
253         /* add the current range and subtract the first range: this is done after the pattern recognition
254          * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
255          */
256         NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) - TA_CANDLERANGE( Near, NearTrailingIdx-1 );
257         EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 );
258         i++;
259         NearTrailingIdx++;
260         EqualTrailingIdx++;
261    } while( i <= endIdx );
262 
263    /* All done. Indicate the output limits and return. */
264    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
265    VALUE_HANDLE_DEREF(outBegIdx)    = startIdx;
266 
267    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
268 }
269 
270 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
271 /* Generated */
272 /* Generated */ #define  USE_SINGLE_PRECISION_INPUT
273 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
274 /* Generated */    #undef   TA_PREFIX
275 /* Generated */    #define  TA_PREFIX(x) TA_S_##x
276 /* Generated */ #endif
277 /* Generated */ #undef   INPUT_TYPE
278 /* Generated */ #define  INPUT_TYPE float
279 /* Generated */ #if defined( _MANAGED )
280 /* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int    startIdx,
281 /* Generated */                                                     int    endIdx,
282 /* Generated */                                                     cli::array<float>^ inOpen,
283 /* Generated */                                                     cli::array<float>^ inHigh,
284 /* Generated */                                                     cli::array<float>^ inLow,
285 /* Generated */                                                     cli::array<float>^ inClose,
286 /* Generated */                                                     [Out]int%    outBegIdx,
287 /* Generated */                                                     [Out]int%    outNBElement,
288 /* Generated */                                                     cli::array<int>^  outInteger )
289 /* Generated */ #elif defined( _JAVA )
290 /* Generated */ public RetCode cdlGapSideSideWhite( int    startIdx,
291 /* Generated */                                     int    endIdx,
292 /* Generated */                                     float        inOpen[],
293 /* Generated */                                     float        inHigh[],
294 /* Generated */                                     float        inLow[],
295 /* Generated */                                     float        inClose[],
296 /* Generated */                                     MInteger     outBegIdx,
297 /* Generated */                                     MInteger     outNBElement,
298 /* Generated */                                     int           outInteger[] )
299 /* Generated */ #else
300 /* Generated */ TA_RetCode TA_S_CDLGAPSIDESIDEWHITE( int    startIdx,
301 /* Generated */                                      int    endIdx,
302 /* Generated */                                      const float  inOpen[],
303 /* Generated */                                      const float  inHigh[],
304 /* Generated */                                      const float  inLow[],
305 /* Generated */                                      const float  inClose[],
306 /* Generated */                                      int          *outBegIdx,
307 /* Generated */                                      int          *outNBElement,
308 /* Generated */                                      int           outInteger[] )
309 /* Generated */ #endif
310 /* Generated */ {
311 /* Generated */     double NearPeriodTotal, EqualPeriodTotal;
312 /* Generated */     int i, outIdx, NearTrailingIdx, EqualTrailingIdx, lookbackTotal;
313 /* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
314 /* Generated */     if( startIdx < 0 )
315 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
316 /* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
317 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
318 /* Generated */     #if !defined(_JAVA)
319 /* Generated */     if(!inOpen||!inHigh||!inLow||!inClose)
320 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
321 /* Generated */     #endif
322 /* Generated */     #if !defined(_JAVA)
323 /* Generated */     if( !outInteger )
324 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
325 /* Generated */     #endif
326 /* Generated */  #endif
327 /* Generated */    lookbackTotal = LOOKBACK_CALL(CDLGAPSIDESIDEWHITE)();
328 /* Generated */    if( startIdx < lookbackTotal )
329 /* Generated */       startIdx = lookbackTotal;
330 /* Generated */    if( startIdx > endIdx )
331 /* Generated */    {
332 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
333 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
334 /* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
335 /* Generated */    }
336 /* Generated */    NearPeriodTotal = 0;
337 /* Generated */    EqualPeriodTotal = 0;
338 /* Generated */    NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near);
339 /* Generated */    EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal);
340 /* Generated */    i = NearTrailingIdx;
341 /* Generated */    while( i < startIdx ) {
342 /* Generated */         NearPeriodTotal += TA_CANDLERANGE( Near, i-1 );
343 /* Generated */         i++;
344 /* Generated */    }
345 /* Generated */    i = EqualTrailingIdx;
346 /* Generated */    while( i < startIdx ) {
347 /* Generated */         EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 );
348 /* Generated */         i++;
349 /* Generated */    }
350 /* Generated */    i = startIdx;
351 /* Generated */    outIdx = 0;
352 /* Generated */    do
353 /* Generated */    {
354 /* Generated */         if(
355 /* Generated */             ( // upside or downside gap between the 1st candle and both the next 2 candles
356 /* Generated */               ( TA_REALBODYGAPUP(i-1,i-2) && TA_REALBODYGAPUP(i,i-2) )
357 /* Generated */               ||
358 /* Generated */               ( TA_REALBODYGAPDOWN(i-1,i-2) && TA_REALBODYGAPDOWN(i,i-2) )
359 /* Generated */             ) &&
360 /* Generated */             TA_CANDLECOLOR(i-1) == 1 &&                                                                 // 2nd: white
361 /* Generated */             TA_CANDLECOLOR(i) == 1 &&                                                                   // 3rd: white
362 /* Generated */             TA_REALBODY(i) >= TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) &&   // same size 2 and 3
363 /* Generated */             TA_REALBODY(i) <= TA_REALBODY(i-1) + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) &&
364 /* Generated */             inOpen[i] >= inOpen[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) &&           // same open 2 and 3
365 /* Generated */             inOpen[i] <= inOpen[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 )
366 /* Generated */           )
367 /* Generated */             outInteger[outIdx++] = ( TA_REALBODYGAPUP(i-1,i-2) ? 100 : -100 );
368 /* Generated */         else
369 /* Generated */             outInteger[outIdx++] = 0;
370 /* Generated */         NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) - TA_CANDLERANGE( Near, NearTrailingIdx-1 );
371 /* Generated */         EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 );
372 /* Generated */         i++;
373 /* Generated */         NearTrailingIdx++;
374 /* Generated */         EqualTrailingIdx++;
375 /* Generated */    } while( i <= endIdx );
376 /* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
377 /* Generated */    VALUE_HANDLE_DEREF(outBegIdx)    = startIdx;
378 /* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
379 /* Generated */ }
380 /* Generated */
381 /* Generated */ #if defined( _MANAGED )
382 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
383 /* Generated */ #endif
384 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
385 
386