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 * 010802 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 /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
51 /* All code within this section is automatically
52 * generated by gen_code. Any modification will be lost
53 * next time gen_code is run.
54 */
55 /* Generated */
56 /* Generated */ #if defined( _MANAGED )
57 /* Generated */ #include "TA-Lib-Core.h"
58 /* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError)
59 /* Generated */ namespace TicTacTec { namespace TA { namespace Library {
60 /* Generated */ #elif defined( _JAVA )
61 /* Generated */ #include "ta_defs.h"
62 /* Generated */ #include "ta_java_defs.h"
63 /* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError)
64 /* Generated */ #else
65 /* Generated */ #include <string.h>
66 /* Generated */ #include <math.h>
67 /* Generated */ #include "ta_func.h"
68 /* Generated */ #endif
69 /* Generated */
70 /* Generated */ #ifndef TA_UTILITY_H
71 /* Generated */ #include "ta_utility.h"
72 /* Generated */ #endif
73 /* Generated */
74 /* Generated */ #ifndef TA_MEMORY_H
75 /* Generated */ #include "ta_memory.h"
76 /* Generated */ #endif
77 /* Generated */
78 /* Generated */ #define TA_PREFIX(x) TA_##x
79 /* Generated */ #define INPUT_TYPE double
80 /* Generated */
81 /* Generated */ #if defined( _MANAGED )
AvgPriceLookback(void)82 /* Generated */ int Core::AvgPriceLookback( void )
83 /* Generated */
84 /* Generated */ #elif defined( _JAVA )
85 /* Generated */ public int avgPriceLookback( )
86 /* Generated */
87 /* Generated */ #else
88 /* Generated */ int TA_AVGPRICE_Lookback( void )
89 /* Generated */
90 /* Generated */ #endif
91 /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
92 {
93 /* insert local variable here */
94
95 /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
96 /* Generated */ /* No parameters to validate. */
97 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
98
99 /* insert lookback code here. */
100
101 /* This function have no lookback needed. */
102 return 0;
103 }
104
105 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
106 /*
107 * TA_AVGPRICE - Average Price
108 *
109 * Input = Open, High, Low, Close
110 * Output = double
111 *
112 */
113 /* Generated */
114 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
115 /* Generated */ enum class Core::RetCode Core::AvgPrice( int startIdx,
116 /* Generated */ int endIdx,
117 /* Generated */ SubArray^ inOpen,
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::AvgPrice( int startIdx,
126 /* Generated */ int endIdx,
127 /* Generated */ cli::array<double>^ inOpen,
128 /* Generated */ cli::array<double>^ inHigh,
129 /* Generated */ cli::array<double>^ inLow,
130 /* Generated */ cli::array<double>^ inClose,
131 /* Generated */ [Out]int% outBegIdx,
132 /* Generated */ [Out]int% outNBElement,
133 /* Generated */ cli::array<double>^ outReal )
134 /* Generated */ #elif defined( _JAVA )
135 /* Generated */ public RetCode avgPrice( int startIdx,
136 /* Generated */ int endIdx,
137 /* Generated */ double inOpen[],
138 /* Generated */ double inHigh[],
139 /* Generated */ double inLow[],
140 /* Generated */ double inClose[],
141 /* Generated */ MInteger outBegIdx,
142 /* Generated */ MInteger outNBElement,
143 /* Generated */ double outReal[] )
144 /* Generated */ #else
145 /* Generated */ TA_RetCode TA_AVGPRICE( int startIdx,
146 /* Generated */ int endIdx,
147 /* Generated */ const double inOpen[],
148 /* Generated */ const double inHigh[],
149 /* Generated */ const double inLow[],
150 /* Generated */ const double inClose[],
151 /* Generated */ int *outBegIdx,
152 /* Generated */ int *outNBElement,
153 /* Generated */ double outReal[] )
154 /* Generated */ #endif
155 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
156 {
157 /* insert local variable here */
158 int outIdx, i;
159
160 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
161 /* Generated */
162 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
163 /* Generated */
164 /* Generated */ /* Validate the requested output range. */
165 /* Generated */ if( startIdx < 0 )
166 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
167 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
168 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
169 /* Generated */
170 /* Generated */ #if !defined(_JAVA)
171 /* Generated */ /* Verify required price component. */
172 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
173 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
174 /* Generated */
175 /* Generated */ #endif /* !defined(_JAVA)*/
176 /* Generated */ #if !defined(_JAVA)
177 /* Generated */ if( !outReal )
178 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
179 /* Generated */
180 /* Generated */ #endif /* !defined(_JAVA) */
181 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
182 /* Generated */
183 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
184
185 /* Insert TA function code here. */
186
187 /* Average price = (High + Low + Open + Close) / 4 */
188
189 outIdx = 0;
190
191 for( i=startIdx; i <= endIdx; i++ )
192 {
193 outReal[outIdx++] = ( inHigh [i] +
194 inLow [i] +
195 inClose[i] +
196 inOpen [i]) / 4;
197 }
198
199 VALUE_HANDLE_DEREF(outNBElement) = outIdx;
200 VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
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::AvgPrice( int startIdx,
216 /* Generated */ int endIdx,
217 /* Generated */ cli::array<float>^ inOpen,
218 /* Generated */ cli::array<float>^ inHigh,
219 /* Generated */ cli::array<float>^ inLow,
220 /* Generated */ cli::array<float>^ inClose,
221 /* Generated */ [Out]int% outBegIdx,
222 /* Generated */ [Out]int% outNBElement,
223 /* Generated */ cli::array<double>^ outReal )
224 /* Generated */ #elif defined( _JAVA )
225 /* Generated */ public RetCode avgPrice( int startIdx,
226 /* Generated */ int endIdx,
227 /* Generated */ float inOpen[],
228 /* Generated */ float inHigh[],
229 /* Generated */ float inLow[],
230 /* Generated */ float inClose[],
231 /* Generated */ MInteger outBegIdx,
232 /* Generated */ MInteger outNBElement,
233 /* Generated */ double outReal[] )
234 /* Generated */ #else
235 /* Generated */ TA_RetCode TA_S_AVGPRICE( int startIdx,
236 /* Generated */ int endIdx,
237 /* Generated */ const float inOpen[],
238 /* Generated */ const float inHigh[],
239 /* Generated */ const float inLow[],
240 /* Generated */ const float inClose[],
241 /* Generated */ int *outBegIdx,
242 /* Generated */ int *outNBElement,
243 /* Generated */ double outReal[] )
244 /* Generated */ #endif
245 /* Generated */ {
246 /* Generated */ int outIdx, i;
247 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
248 /* Generated */ if( startIdx < 0 )
249 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
250 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
251 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
252 /* Generated */ #if !defined(_JAVA)
253 /* Generated */ if(!inOpen||!inHigh||!inLow||!inClose)
254 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
255 /* Generated */ #endif
256 /* Generated */ #if !defined(_JAVA)
257 /* Generated */ if( !outReal )
258 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
259 /* Generated */ #endif
260 /* Generated */ #endif
261 /* Generated */ outIdx = 0;
262 /* Generated */ for( i=startIdx; i <= endIdx; i++ )
263 /* Generated */ {
264 /* Generated */ outReal[outIdx++] = ( inHigh [i] +
265 /* Generated */ inLow [i] +
266 /* Generated */ inClose[i] +
267 /* Generated */ inOpen [i]) / 4;
268 /* Generated */ }
269 /* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx;
270 /* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx;
271 /* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success);
272 /* Generated */ }
273 /* Generated */
274 /* Generated */ #if defined( _MANAGED )
275 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
276 /* Generated */ #endif
277 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
278
279