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  *  AC       Angelo Ciceri
40  *
41  *
42  * Change history:
43  *
44  *  MMDDYY BY   Description
45  *  -------------------------------------------------------------------
46  *  010802 MF   Template creation.
47  *  052603 MF   Adapt code to compile with .NET Managed C++
48  *  110206 AC   Change volume and open interest to double
49  *
50  */
51 
52 /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
53 /* All code within this section is automatically
54  * generated by gen_code. Any modification will be lost
55  * next time gen_code is run.
56  */
57 /* Generated */
58 /* Generated */ #if defined( _MANAGED )
59 /* Generated */    #include "TA-Lib-Core.h"
60 /* Generated */    #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError)
61 /* Generated */    namespace TicTacTec { namespace TA { namespace Library {
62 /* Generated */ #elif defined( _JAVA )
63 /* Generated */    #include "ta_defs.h"
64 /* Generated */    #include "ta_java_defs.h"
65 /* Generated */    #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError)
66 /* Generated */ #else
67 /* Generated */    #include <string.h>
68 /* Generated */    #include <math.h>
69 /* Generated */    #include "ta_func.h"
70 /* Generated */ #endif
71 /* Generated */
72 /* Generated */ #ifndef TA_UTILITY_H
73 /* Generated */    #include "ta_utility.h"
74 /* Generated */ #endif
75 /* Generated */
76 /* Generated */ #ifndef TA_MEMORY_H
77 /* Generated */    #include "ta_memory.h"
78 /* Generated */ #endif
79 /* Generated */
80 /* Generated */ #define TA_PREFIX(x) TA_##x
81 /* Generated */ #define INPUT_TYPE   double
82 /* Generated */
83 /* Generated */ #if defined( _MANAGED )
ObvLookback(void)84 /* Generated */ int Core::ObvLookback( void )
85 /* Generated */
86 /* Generated */ #elif defined( _JAVA )
87 /* Generated */ public int obvLookback(  )
88 /* Generated */
89 /* Generated */ #else
90 /* Generated */ int TA_OBV_Lookback( void )
91 /* Generated */
92 /* Generated */ #endif
93 /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
94 {
95    /* insert local variable here */
96 
97 /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
98 /* Generated */ /* No parameters to validate. */
99 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
100 
101    /* insert lookback code here. */
102 
103    /* This function have no lookback needed. */
104    return 0;
105 }
106 
107 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
108 /*
109  * TA_OBV - On Balance Volume
110  *
111  * Input  = double, Volume
112  * Output = double
113  *
114  */
115 /* Generated */
116 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
117 /* Generated */ enum class Core::RetCode Core::Obv( int    startIdx,
118 /* Generated */                                     int    endIdx,
119 /* Generated */                                     SubArray^    inReal,
120 /* Generated */                                     SubArray^    inVolume,
121 /* Generated */                                     [Out]int%    outBegIdx,
122 /* Generated */                                     [Out]int%    outNBElement,
123 /* Generated */                                     cli::array<double>^  outReal )
124 /* Generated */ #elif defined( _MANAGED )
125 /* Generated */ enum class Core::RetCode Core::Obv( int    startIdx,
126 /* Generated */                                     int    endIdx,
127 /* Generated */                                     cli::array<double>^ inReal,
128 /* Generated */                                     cli::array<double>^ inVolume,
129 /* Generated */                                     [Out]int%    outBegIdx,
130 /* Generated */                                     [Out]int%    outNBElement,
131 /* Generated */                                     cli::array<double>^  outReal )
132 /* Generated */ #elif defined( _JAVA )
133 /* Generated */ public RetCode obv( int    startIdx,
134 /* Generated */                     int    endIdx,
135 /* Generated */                     double       inReal[],
136 /* Generated */                     double       inVolume[],
137 /* Generated */                     MInteger     outBegIdx,
138 /* Generated */                     MInteger     outNBElement,
139 /* Generated */                     double        outReal[] )
140 /* Generated */ #else
141 /* Generated */ TA_RetCode TA_OBV( int    startIdx,
142 /* Generated */                    int    endIdx,
143 /* Generated */                    const double inReal[],
144 /* Generated */                    const double inVolume[],
145 /* Generated */                    int          *outBegIdx,
146 /* Generated */                    int          *outNBElement,
147 /* Generated */                    double        outReal[] )
148 /* Generated */ #endif
149 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
150 {
151 	/* insert local variable here */
152    int i;
153    int outIdx;
154    double prevReal, tempReal, prevOBV;
155 
156 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
157 /* Generated */
158 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
159 /* Generated */
160 /* Generated */    /* Validate the requested output range. */
161 /* Generated */    if( startIdx < 0 )
162 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
163 /* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
164 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
165 /* Generated */
166 /* Generated */    #if !defined(_JAVA)
167 /* Generated */    if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
168 /* Generated */    /* Verify required price component. */
169 /* Generated */    if(!inVolume)
170 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
171 /* Generated */
172 /* Generated */    #endif /* !defined(_JAVA)*/
173 /* Generated */    #if !defined(_JAVA)
174 /* Generated */    if( !outReal )
175 /* Generated */       return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
176 /* Generated */
177 /* Generated */    #endif /* !defined(_JAVA) */
178 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
179 /* Generated */
180 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
181 
182    /* Insert TA function code here. */
183    prevOBV  = inVolume[startIdx];
184    prevReal = inReal[startIdx];
185    outIdx = 0;
186 
187    for(i=startIdx; i <= endIdx; i++ )
188    {
189       tempReal = inReal[i];
190       if( tempReal > prevReal )
191          prevOBV += inVolume[i];
192       else if( tempReal < prevReal )
193          prevOBV -= inVolume[i];
194 
195       outReal[outIdx++] = prevOBV;
196       prevReal = tempReal;
197    }
198 
199    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
200    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
201 
202    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
203 }
204 
205 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
206 /* Generated */
207 /* Generated */ #define  USE_SINGLE_PRECISION_INPUT
208 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
209 /* Generated */    #undef   TA_PREFIX
210 /* Generated */    #define  TA_PREFIX(x) TA_S_##x
211 /* Generated */ #endif
212 /* Generated */ #undef   INPUT_TYPE
213 /* Generated */ #define  INPUT_TYPE float
214 /* Generated */ #if defined( _MANAGED )
215 /* Generated */ enum class Core::RetCode Core::Obv( int    startIdx,
216 /* Generated */                                     int    endIdx,
217 /* Generated */                                     cli::array<float>^ inReal,
218 /* Generated */                                     cli::array<float>^ inVolume,
219 /* Generated */                                     [Out]int%    outBegIdx,
220 /* Generated */                                     [Out]int%    outNBElement,
221 /* Generated */                                     cli::array<double>^  outReal )
222 /* Generated */ #elif defined( _JAVA )
223 /* Generated */ public RetCode obv( int    startIdx,
224 /* Generated */                     int    endIdx,
225 /* Generated */                     float        inReal[],
226 /* Generated */                     float        inVolume[],
227 /* Generated */                     MInteger     outBegIdx,
228 /* Generated */                     MInteger     outNBElement,
229 /* Generated */                     double        outReal[] )
230 /* Generated */ #else
231 /* Generated */ TA_RetCode TA_S_OBV( int    startIdx,
232 /* Generated */                      int    endIdx,
233 /* Generated */                      const float  inReal[],
234 /* Generated */                      const float  inVolume[],
235 /* Generated */                      int          *outBegIdx,
236 /* Generated */                      int          *outNBElement,
237 /* Generated */                      double        outReal[] )
238 /* Generated */ #endif
239 /* Generated */ {
240 /* Generated */    int i;
241 /* Generated */    int outIdx;
242 /* Generated */    double prevReal, tempReal, prevOBV;
243 /* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
244 /* Generated */     if( startIdx < 0 )
245 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
246 /* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
247 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
248 /* Generated */     #if !defined(_JAVA)
249 /* Generated */     if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
250 /* Generated */     if(!inVolume)
251 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
252 /* Generated */     #endif
253 /* Generated */     #if !defined(_JAVA)
254 /* Generated */     if( !outReal )
255 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
256 /* Generated */     #endif
257 /* Generated */  #endif
258 /* Generated */    prevOBV  = inVolume[startIdx];
259 /* Generated */    prevReal = inReal[startIdx];
260 /* Generated */    outIdx = 0;
261 /* Generated */    for(i=startIdx; i <= endIdx; i++ )
262 /* Generated */    {
263 /* Generated */       tempReal = inReal[i];
264 /* Generated */       if( tempReal > prevReal )
265 /* Generated */          prevOBV += inVolume[i];
266 /* Generated */       else if( tempReal < prevReal )
267 /* Generated */          prevOBV -= inVolume[i];
268 /* Generated */       outReal[outIdx++] = prevOBV;
269 /* Generated */       prevReal = tempReal;
270 /* Generated */    }
271 /* Generated */    VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
272 /* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
273 /* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
274 /* Generated */ }
275 /* Generated */
276 /* Generated */ #if defined( _MANAGED )
277 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
278 /* Generated */ #endif
279 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
280 
281