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  *  MF       Mario Fortier
39  *  CF       Christo Fogelberg
40  *
41  * Change history:
42  *
43  *  MMDDYY BY     Description
44  *  -------------------------------------------------------------------
45  *  010802 MF     Template creation.
46  *  052603 MF     Adapt code to compile with .NET Managed C++
47  *  122104 MF,CF  Fix#1089506 for when optInTimePeriod is 1.
48  *
49  */
50 
51 /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
52 /* All code within this section is automatically
53  * generated by gen_code. Any modification will be lost
54  * next time gen_code is run.
55  */
56 /* Generated */
57 /* Generated */ #if defined( _MANAGED )
58 /* Generated */    #include "TA-Lib-Core.h"
59 /* Generated */    #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError)
60 /* Generated */    namespace TicTacTec { namespace TA { namespace Library {
61 /* Generated */ #elif defined( _JAVA )
62 /* Generated */    #include "ta_defs.h"
63 /* Generated */    #include "ta_java_defs.h"
64 /* Generated */    #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError)
65 /* Generated */ #else
66 /* Generated */    #include <string.h>
67 /* Generated */    #include <math.h>
68 /* Generated */    #include "ta_func.h"
69 /* Generated */ #endif
70 /* Generated */
71 /* Generated */ #ifndef TA_UTILITY_H
72 /* Generated */    #include "ta_utility.h"
73 /* Generated */ #endif
74 /* Generated */
75 /* Generated */ #ifndef TA_MEMORY_H
76 /* Generated */    #include "ta_memory.h"
77 /* Generated */ #endif
78 /* Generated */
79 /* Generated */ #define TA_PREFIX(x) TA_##x
80 /* Generated */ #define INPUT_TYPE   double
81 /* Generated */
82 /* Generated */ #if defined( _MANAGED )
PlusDMLookback(int optInTimePeriod)83 /* Generated */ int Core::PlusDMLookback( int           optInTimePeriod )  /* From 1 to 100000 */
84 /* Generated */
85 /* Generated */ #elif defined( _JAVA )
86 /* Generated */ public int plusDMLookback( int           optInTimePeriod )  /* From 1 to 100000 */
87 /* Generated */
88 /* Generated */ #else
89 /* Generated */ int TA_PLUS_DM_Lookback( int           optInTimePeriod )  /* From 1 to 100000 */
90 /* Generated */
91 /* Generated */ #endif
92 /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
93 {
94    /* insert local variable here */
95 
96 /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
97 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
98 /* Generated */    /* min/max are checked for optInTimePeriod. */
99 /* Generated */    if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
100 /* Generated */       optInTimePeriod = 14;
101 /* Generated */    else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) )
102 /* Generated */       return -1;
103 /* Generated */
104 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
105 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
106 
107    /* insert lookback code here. */
108    if( optInTimePeriod > 1 )
109       return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM) - 1;
110    else
111       return 1;
112 }
113 
114 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
115 /*
116  * TA_PLUS_DM - Plus Directional Movement
117  *
118  * Input  = High, Low
119  * Output = double
120  *
121  * Optional Parameters
122  * -------------------
123  * optInTimePeriod:(From 1 to 100000)
124  *    Number of period
125  *
126  *
127  */
128 /* Generated */
129 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
130 /* Generated */ enum class Core::RetCode Core::PlusDM( int    startIdx,
131 /* Generated */                                        int    endIdx,
132 /* Generated */                                        SubArray^    inHigh,
133 /* Generated */                                        SubArray^    inLow,
134 /* Generated */                                        int           optInTimePeriod, /* From 1 to 100000 */
135 /* Generated */                                        [Out]int%    outBegIdx,
136 /* Generated */                                        [Out]int%    outNBElement,
137 /* Generated */                                        cli::array<double>^  outReal )
138 /* Generated */ #elif defined( _MANAGED )
139 /* Generated */ enum class Core::RetCode Core::PlusDM( int    startIdx,
140 /* Generated */                                        int    endIdx,
141 /* Generated */                                        cli::array<double>^ inHigh,
142 /* Generated */                                        cli::array<double>^ inLow,
143 /* Generated */                                        int           optInTimePeriod, /* From 1 to 100000 */
144 /* Generated */                                        [Out]int%    outBegIdx,
145 /* Generated */                                        [Out]int%    outNBElement,
146 /* Generated */                                        cli::array<double>^  outReal )
147 /* Generated */ #elif defined( _JAVA )
148 /* Generated */ public RetCode plusDM( int    startIdx,
149 /* Generated */                        int    endIdx,
150 /* Generated */                        double       inHigh[],
151 /* Generated */                        double       inLow[],
152 /* Generated */                        int           optInTimePeriod, /* From 1 to 100000 */
153 /* Generated */                        MInteger     outBegIdx,
154 /* Generated */                        MInteger     outNBElement,
155 /* Generated */                        double        outReal[] )
156 /* Generated */ #else
157 /* Generated */ TA_RetCode TA_PLUS_DM( int    startIdx,
158 /* Generated */                        int    endIdx,
159 /* Generated */                        const double inHigh[],
160 /* Generated */                        const double inLow[],
161 /* Generated */                        int           optInTimePeriod, /* From 1 to 100000 */
162 /* Generated */                        int          *outBegIdx,
163 /* Generated */                        int          *outNBElement,
164 /* Generated */                        double        outReal[] )
165 /* Generated */ #endif
166 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
167 {
168 	/* insert local variable here */
169    int today, lookbackTotal, outIdx;
170    double prevHigh, prevLow, tempReal;
171    double prevPlusDM;
172    double diffP, diffM;
173    int i;
174 
175 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
176 /* Generated */
177 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
178 /* Generated */
179 /* Generated */    /* Validate the requested output range. */
180 /* Generated */    if( startIdx < 0 )
181 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
182 /* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
183 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
184 /* Generated */
185 /* Generated */    #if !defined(_JAVA)
186 /* Generated */    /* Verify required price component. */
187 /* Generated */    if(!inHigh||!inLow)
188 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
189 /* Generated */
190 /* Generated */    #endif /* !defined(_JAVA)*/
191 /* Generated */    /* min/max are checked for optInTimePeriod. */
192 /* Generated */    if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
193 /* Generated */       optInTimePeriod = 14;
194 /* Generated */    else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) )
195 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
196 /* Generated */
197 /* Generated */    #if !defined(_JAVA)
198 /* Generated */    if( !outReal )
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    /* Insert TA function code here. */
207 
208    /*
209     * The DM1 (one period) is base on the largest part of
210     * today's range that is outside of yesterdays range.
211     *
212     * The following 7 cases explain how the +DM and -DM are
213     * calculated on one period:
214     *
215     * Case 1:                       Case 2:
216     *    C|                        A|
217     *     |                         | C|
218     *     | +DM1 = (C-A)           B|  | +DM1 = 0
219     *     | -DM1 = 0                   | -DM1 = (B-D)
220     * A|  |                           D|
221     *  | D|
222     * B|
223     *
224     * Case 3:                       Case 4:
225     *    C|                           C|
226     *     |                        A|  |
227     *     | +DM1 = (C-A)            |  | +DM1 = 0
228     *     | -DM1 = 0               B|  | -DM1 = (B-D)
229     * A|  |                            |
230     *  |  |                           D|
231     * B|  |
232     *    D|
233     *
234     * Case 5:                      Case 6:
235     * A|                           A| C|
236     *  | C| +DM1 = 0                |  |  +DM1 = 0
237     *  |  | -DM1 = 0                |  |  -DM1 = 0
238     *  | D|                         |  |
239     * B|                           B| D|
240     *
241     *
242     * Case 7:
243     *
244     *    C|
245     * A|  |
246     *  |  | +DM=0
247     * B|  | -DM=0
248     *    D|
249     *
250     * In case 3 and 4, the rule is that the smallest delta between
251     * (C-A) and (B-D) determine which of +DM or -DM is zero.
252     *
253     * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are
254     * zero.
255     *
256     * The rules remain the same when A=B and C=D (when the highs
257     * equal the lows).
258     *
259     * When calculating the DM over a period > 1, the one-period DM
260     * for the desired period are initialy sum. In other word,
261     * for a +DM14, sum the +DM1 for the first 14 days (that's
262     * 13 values because there is no DM for the first day!)
263     * Subsequent DM are calculated using the Wilder's
264     * smoothing approach:
265     *
266     *                                    Previous +DM14
267     *  Today's +DM14 = Previous +DM14 -  -------------- + Today's +DM1
268     *                                         14
269     *
270     * Reference:
271     *    New Concepts In Technical Trading Systems, J. Welles Wilder Jr
272     */
273 
274    if( optInTimePeriod > 1 )
275       lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM) - 1;
276    else
277       lookbackTotal = 1;
278 
279    /* Adjust startIdx to account for the lookback period. */
280    if( startIdx < lookbackTotal )
281       startIdx = lookbackTotal;
282 
283    /* Make sure there is still something to evaluate. */
284    if( startIdx > endIdx )
285    {
286       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
287       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
288       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
289    }
290 
291    /* Indicate where the next output should be put
292     * in the outReal.
293     */
294    outIdx = 0;
295 
296    /* Trap the case where no smoothing is needed. */
297    if( optInTimePeriod <= 1 )
298    {
299       /* No smoothing needed. Just do a simple DM1
300        * for each price bar.
301        */
302       VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
303       today = startIdx-1;
304       prevHigh = inHigh[today];
305       prevLow  = inLow[today];
306       while( today < endIdx )
307       {
308          today++;
309          tempReal = inHigh[today];
310          diffP    = tempReal-prevHigh; /* Plus Delta */
311          prevHigh = tempReal;
312          tempReal = inLow[today];
313          diffM    = prevLow-tempReal;   /* Minus Delta */
314          prevLow  = tempReal;
315          if( (diffP > 0) && (diffP > diffM) )
316          {
317             /* Case 1 and 3: +DM=diffP,-DM=0 */
318             outReal[outIdx++] = diffP;
319          }
320          else
321             outReal[outIdx++] = 0;
322       }
323 
324       VALUE_HANDLE_DEREF(outNBElement) = outIdx;
325       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
326    }
327 
328    /* Process the initial DM */
329    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
330 
331    prevPlusDM  = 0.0;
332    today       = startIdx - lookbackTotal;
333    prevHigh    = inHigh[today];
334    prevLow     = inLow[today];
335    i           = optInTimePeriod-1;
336    while( i-- > 0 )
337    {
338       today++;
339       tempReal = inHigh[today];
340       diffP    = tempReal-prevHigh; /* Plus Delta */
341       prevHigh = tempReal;
342       tempReal = inLow[today];
343       diffM    = prevLow-tempReal;   /* Minus Delta */
344       prevLow  = tempReal;
345 
346       if( (diffP > 0) && (diffP > diffM) )
347       {
348          /* Case 1 and 3: +DM=diffP,-DM=0 */
349          prevPlusDM += diffP;
350       }
351    }
352 
353    /* Process subsequent DM */
354 
355    /* Skip the unstable period. */
356    i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM);
357    while( i-- != 0 )
358    {
359       today++;
360       tempReal = inHigh[today];
361       diffP    = tempReal-prevHigh; /* Plus Delta */
362       prevHigh = tempReal;
363       tempReal = inLow[today];
364       diffM    = prevLow-tempReal;   /* Minus Delta */
365       prevLow  = tempReal;
366       if( (diffP > 0) && (diffP > diffM) )
367       {
368          /* Case 1 and 3: +DM=diffP,-DM=0 */
369          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP;
370       }
371       else
372       {
373          /* Case 2,4,5 and 7 */
374          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod);
375       }
376    }
377 
378    /* Now start to write the output in
379     * the caller provided outReal.
380     */
381    outReal[0] = prevPlusDM;
382    outIdx = 1;
383 
384    while( today < endIdx )
385    {
386       today++;
387       tempReal = inHigh[today];
388       diffP    = tempReal-prevHigh; /* Plus Delta */
389       prevHigh = tempReal;
390       tempReal = inLow[today];
391       diffM    = prevLow-tempReal;   /* Minus Delta */
392       prevLow  = tempReal;
393 
394       if( (diffP > 0) && (diffP > diffM) )
395       {
396          /* Case 1 and 3: +DM=diffP,-DM=0 */
397          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP;
398       }
399       else
400       {
401          /* Case 2,4,5 and 7 */
402          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod);
403       }
404 
405       outReal[outIdx++] = prevPlusDM;
406    }
407 
408    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
409 
410    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
411 }
412 
413 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
414 /* Generated */
415 /* Generated */ #define  USE_SINGLE_PRECISION_INPUT
416 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
417 /* Generated */    #undef   TA_PREFIX
418 /* Generated */    #define  TA_PREFIX(x) TA_S_##x
419 /* Generated */ #endif
420 /* Generated */ #undef   INPUT_TYPE
421 /* Generated */ #define  INPUT_TYPE float
422 /* Generated */ #if defined( _MANAGED )
423 /* Generated */ enum class Core::RetCode Core::PlusDM( int    startIdx,
424 /* Generated */                                        int    endIdx,
425 /* Generated */                                        cli::array<float>^ inHigh,
426 /* Generated */                                        cli::array<float>^ inLow,
427 /* Generated */                                        int           optInTimePeriod, /* From 1 to 100000 */
428 /* Generated */                                        [Out]int%    outBegIdx,
429 /* Generated */                                        [Out]int%    outNBElement,
430 /* Generated */                                        cli::array<double>^  outReal )
431 /* Generated */ #elif defined( _JAVA )
432 /* Generated */ public RetCode plusDM( int    startIdx,
433 /* Generated */                        int    endIdx,
434 /* Generated */                        float        inHigh[],
435 /* Generated */                        float        inLow[],
436 /* Generated */                        int           optInTimePeriod, /* From 1 to 100000 */
437 /* Generated */                        MInteger     outBegIdx,
438 /* Generated */                        MInteger     outNBElement,
439 /* Generated */                        double        outReal[] )
440 /* Generated */ #else
441 /* Generated */ TA_RetCode TA_S_PLUS_DM( int    startIdx,
442 /* Generated */                          int    endIdx,
443 /* Generated */                          const float  inHigh[],
444 /* Generated */                          const float  inLow[],
445 /* Generated */                          int           optInTimePeriod, /* From 1 to 100000 */
446 /* Generated */                          int          *outBegIdx,
447 /* Generated */                          int          *outNBElement,
448 /* Generated */                          double        outReal[] )
449 /* Generated */ #endif
450 /* Generated */ {
451 /* Generated */    int today, lookbackTotal, outIdx;
452 /* Generated */    double prevHigh, prevLow, tempReal;
453 /* Generated */    double prevPlusDM;
454 /* Generated */    double diffP, diffM;
455 /* Generated */    int i;
456 /* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
457 /* Generated */     if( startIdx < 0 )
458 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
459 /* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
460 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
461 /* Generated */     #if !defined(_JAVA)
462 /* Generated */     if(!inHigh||!inLow)
463 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
464 /* Generated */     #endif
465 /* Generated */     if( (int)optInTimePeriod == TA_INTEGER_DEFAULT )
466 /* Generated */        optInTimePeriod = 14;
467 /* Generated */     else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) )
468 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
469 /* Generated */     #if !defined(_JAVA)
470 /* Generated */     if( !outReal )
471 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
472 /* Generated */     #endif
473 /* Generated */  #endif
474 /* Generated */    if( optInTimePeriod > 1 )
475 /* Generated */       lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM) - 1;
476 /* Generated */    else
477 /* Generated */       lookbackTotal = 1;
478 /* Generated */    if( startIdx < lookbackTotal )
479 /* Generated */       startIdx = lookbackTotal;
480 /* Generated */    if( startIdx > endIdx )
481 /* Generated */    {
482 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx);
483 /* Generated */       VALUE_HANDLE_DEREF_TO_ZERO(outNBElement);
484 /* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
485 /* Generated */    }
486 /* Generated */    outIdx = 0;
487 /* Generated */    if( optInTimePeriod <= 1 )
488 /* Generated */    {
489 /* Generated */       VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
490 /* Generated */       today = startIdx-1;
491 /* Generated */       prevHigh = inHigh[today];
492 /* Generated */       prevLow  = inLow[today];
493 /* Generated */       while( today < endIdx )
494 /* Generated */       {
495 /* Generated */          today++;
496 /* Generated */          tempReal = inHigh[today];
497 /* Generated */          diffP    = tempReal-prevHigh;
498 /* Generated */          prevHigh = tempReal;
499 /* Generated */          tempReal = inLow[today];
500 /* Generated */          diffM    = prevLow-tempReal;
501 /* Generated */          prevLow  = tempReal;
502 /* Generated */          if( (diffP > 0) && (diffP > diffM) )
503 /* Generated */          {
504 /* Generated */             outReal[outIdx++] = diffP;
505 /* Generated */          }
506 /* Generated */          else
507 /* Generated */             outReal[outIdx++] = 0;
508 /* Generated */       }
509 /* Generated */       VALUE_HANDLE_DEREF(outNBElement) = outIdx;
510 /* Generated */       return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
511 /* Generated */    }
512 /* Generated */    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
513 /* Generated */    prevPlusDM  = 0.0;
514 /* Generated */    today       = startIdx - lookbackTotal;
515 /* Generated */    prevHigh    = inHigh[today];
516 /* Generated */    prevLow     = inLow[today];
517 /* Generated */    i           = optInTimePeriod-1;
518 /* Generated */    while( i-- > 0 )
519 /* Generated */    {
520 /* Generated */       today++;
521 /* Generated */       tempReal = inHigh[today];
522 /* Generated */       diffP    = tempReal-prevHigh;
523 /* Generated */       prevHigh = tempReal;
524 /* Generated */       tempReal = inLow[today];
525 /* Generated */       diffM    = prevLow-tempReal;
526 /* Generated */       prevLow  = tempReal;
527 /* Generated */       if( (diffP > 0) && (diffP > diffM) )
528 /* Generated */       {
529 /* Generated */          prevPlusDM += diffP;
530 /* Generated */       }
531 /* Generated */    }
532 /* Generated */    i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM);
533 /* Generated */    while( i-- != 0 )
534 /* Generated */    {
535 /* Generated */       today++;
536 /* Generated */       tempReal = inHigh[today];
537 /* Generated */       diffP    = tempReal-prevHigh;
538 /* Generated */       prevHigh = tempReal;
539 /* Generated */       tempReal = inLow[today];
540 /* Generated */       diffM    = prevLow-tempReal;
541 /* Generated */       prevLow  = tempReal;
542 /* Generated */       if( (diffP > 0) && (diffP > diffM) )
543 /* Generated */       {
544 /* Generated */          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP;
545 /* Generated */       }
546 /* Generated */       else
547 /* Generated */       {
548 /* Generated */          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod);
549 /* Generated */       }
550 /* Generated */    }
551 /* Generated */    outReal[0] = prevPlusDM;
552 /* Generated */    outIdx = 1;
553 /* Generated */    while( today < endIdx )
554 /* Generated */    {
555 /* Generated */       today++;
556 /* Generated */       tempReal = inHigh[today];
557 /* Generated */       diffP    = tempReal-prevHigh;
558 /* Generated */       prevHigh = tempReal;
559 /* Generated */       tempReal = inLow[today];
560 /* Generated */       diffM    = prevLow-tempReal;
561 /* Generated */       prevLow  = tempReal;
562 /* Generated */       if( (diffP > 0) && (diffP > diffM) )
563 /* Generated */       {
564 /* Generated */          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP;
565 /* Generated */       }
566 /* Generated */       else
567 /* Generated */       {
568 /* Generated */          prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod);
569 /* Generated */       }
570 /* Generated */       outReal[outIdx++] = prevPlusDM;
571 /* Generated */    }
572 /* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
573 /* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
574 /* Generated */ }
575 /* Generated */
576 /* Generated */ #if defined( _MANAGED )
577 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
578 /* Generated */ #endif
579 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
580 
581