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  *
40  *
41  * Change history:
42  *
43  *  MMDDYY BY   Description
44  *  -------------------------------------------------------------------
45  *  112400 MF   Template creation.
46  *  052603 MF   Adapt code to compile with .NET Managed C++
47  *  112605 MF   Fix outBegIdx when startIdx != 0
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 )
WclPriceLookback(void)83 /* Generated */ int Core::WclPriceLookback( void )
84 /* Generated */
85 /* Generated */ #elif defined( _JAVA )
86 /* Generated */ public int wclPriceLookback(  )
87 /* Generated */
88 /* Generated */ #else
89 /* Generated */ int TA_WCLPRICE_Lookback( void )
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 */ /* No parameters to validate. */
98 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
99 
100    /* insert lookback code here. */
101 
102    /* This function have no lookback needed. */
103    return 0;
104 }
105 
106 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
107 /*
108  * TA_WCLPRICE - Weighted Close Price
109  *
110  * Input  = High, Low, Close
111  * Output = double
112  *
113  */
114 /* Generated */
115 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
116 /* Generated */ enum class Core::RetCode Core::WclPrice( int    startIdx,
117 /* Generated */                                          int    endIdx,
118 /* Generated */                                          SubArray^    inHigh,
119 /* Generated */                                          SubArray^    inLow,
120 /* Generated */                                          SubArray^    inClose,
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::WclPrice( int    startIdx,
126 /* Generated */                                          int    endIdx,
127 /* Generated */                                          cli::array<double>^ inHigh,
128 /* Generated */                                          cli::array<double>^ inLow,
129 /* Generated */                                          cli::array<double>^ inClose,
130 /* Generated */                                          [Out]int%    outBegIdx,
131 /* Generated */                                          [Out]int%    outNBElement,
132 /* Generated */                                          cli::array<double>^  outReal )
133 /* Generated */ #elif defined( _JAVA )
134 /* Generated */ public RetCode wclPrice( int    startIdx,
135 /* Generated */                          int    endIdx,
136 /* Generated */                          double       inHigh[],
137 /* Generated */                          double       inLow[],
138 /* Generated */                          double       inClose[],
139 /* Generated */                          MInteger     outBegIdx,
140 /* Generated */                          MInteger     outNBElement,
141 /* Generated */                          double        outReal[] )
142 /* Generated */ #else
143 /* Generated */ TA_RetCode TA_WCLPRICE( int    startIdx,
144 /* Generated */                         int    endIdx,
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 */                         double        outReal[] )
151 /* Generated */ #endif
152 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
153 {
154    /* Insert local variables here. */
155    int outIdx, i;
156 
157 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
158 /* Generated */
159 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
160 /* Generated */
161 /* Generated */    /* Validate the requested output range. */
162 /* Generated */    if( startIdx < 0 )
163 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
164 /* Generated */    if( (endIdx < 0) || (endIdx < startIdx))
165 /* Generated */       return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
166 /* Generated */
167 /* Generated */    #if !defined(_JAVA)
168 /* Generated */    /* Verify required price component. */
169 /* Generated */    if(!inHigh||!inLow||!inClose)
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 
184    /* Weighted Close Price = (High + Low + (Close*2) ) / 4 */
185 
186    outIdx = 0;
187 
188    for( i= startIdx; i <= endIdx; i++ )
189    {
190       outReal[outIdx++] = ( inHigh [i] +
191 		                    inLow  [i] +
192 		                   (inClose[i]*2.0) ) / 4.0;
193    }
194 
195    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
196    VALUE_HANDLE_DEREF(outBegIdx)    = startIdx;
197 
198    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
199 }
200 
201 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
202 /* Generated */
203 /* Generated */ #define  USE_SINGLE_PRECISION_INPUT
204 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
205 /* Generated */    #undef   TA_PREFIX
206 /* Generated */    #define  TA_PREFIX(x) TA_S_##x
207 /* Generated */ #endif
208 /* Generated */ #undef   INPUT_TYPE
209 /* Generated */ #define  INPUT_TYPE float
210 /* Generated */ #if defined( _MANAGED )
211 /* Generated */ enum class Core::RetCode Core::WclPrice( int    startIdx,
212 /* Generated */                                          int    endIdx,
213 /* Generated */                                          cli::array<float>^ inHigh,
214 /* Generated */                                          cli::array<float>^ inLow,
215 /* Generated */                                          cli::array<float>^ inClose,
216 /* Generated */                                          [Out]int%    outBegIdx,
217 /* Generated */                                          [Out]int%    outNBElement,
218 /* Generated */                                          cli::array<double>^  outReal )
219 /* Generated */ #elif defined( _JAVA )
220 /* Generated */ public RetCode wclPrice( int    startIdx,
221 /* Generated */                          int    endIdx,
222 /* Generated */                          float        inHigh[],
223 /* Generated */                          float        inLow[],
224 /* Generated */                          float        inClose[],
225 /* Generated */                          MInteger     outBegIdx,
226 /* Generated */                          MInteger     outNBElement,
227 /* Generated */                          double        outReal[] )
228 /* Generated */ #else
229 /* Generated */ TA_RetCode TA_S_WCLPRICE( int    startIdx,
230 /* Generated */                           int    endIdx,
231 /* Generated */                           const float  inHigh[],
232 /* Generated */                           const float  inLow[],
233 /* Generated */                           const float  inClose[],
234 /* Generated */                           int          *outBegIdx,
235 /* Generated */                           int          *outNBElement,
236 /* Generated */                           double        outReal[] )
237 /* Generated */ #endif
238 /* Generated */ {
239 /* Generated */    int outIdx, i;
240 /* Generated */  #ifndef TA_FUNC_NO_RANGE_CHECK
241 /* Generated */     if( startIdx < 0 )
242 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
243 /* Generated */     if( (endIdx < 0) || (endIdx < startIdx))
244 /* Generated */        return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
245 /* Generated */     #if !defined(_JAVA)
246 /* Generated */     if(!inHigh||!inLow||!inClose)
247 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
248 /* Generated */     #endif
249 /* Generated */     #if !defined(_JAVA)
250 /* Generated */     if( !outReal )
251 /* Generated */        return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
252 /* Generated */     #endif
253 /* Generated */  #endif
254 /* Generated */    outIdx = 0;
255 /* Generated */    for( i= startIdx; i <= endIdx; i++ )
256 /* Generated */    {
257 /* Generated */       outReal[outIdx++] = ( inHigh [i] +
258 /* Generated */ 		                    inLow  [i] +
259 /* Generated */ 		                   (inClose[i]*2.0) ) / 4.0;
260 /* Generated */    }
261 /* Generated */    VALUE_HANDLE_DEREF(outNBElement) = outIdx;
262 /* Generated */    VALUE_HANDLE_DEREF(outBegIdx)    = startIdx;
263 /* Generated */    return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
264 /* Generated */ }
265 /* Generated */
266 /* Generated */ #if defined( _MANAGED )
267 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
268 /* Generated */ #endif
269 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
270 
271