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 * AA Andrew Atkinson
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 * 020605 AA Fix #1117666 Lookback bug.
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 )
PpoLookback(int optInFastPeriod,int optInSlowPeriod,MAType optInMAType)83 /* Generated */ int Core::PpoLookback( int optInFastPeriod, /* From 2 to 100000 */
84 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
85 /* Generated */ MAType optInMAType ) /* Generated */
86 /* Generated */ #elif defined( _JAVA )
87 /* Generated */ public int ppoLookback( int optInFastPeriod, /* From 2 to 100000 */
88 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
89 /* Generated */ MAType optInMAType ) /* Generated */
90 /* Generated */ #else
91 /* Generated */ int TA_PPO_Lookback( int optInFastPeriod, /* From 2 to 100000 */
92 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
93 /* Generated */ TA_MAType optInMAType ) /* Generated */
94 /* Generated */ #endif
95 /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/
96 {
97 /* insert local variable here */
98
99 /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
100 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
101 /* Generated */ /* min/max are checked for optInFastPeriod. */
102 /* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT )
103 /* Generated */ optInFastPeriod = 12;
104 /* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) )
105 /* Generated */ return -1;
106 /* Generated */
107 /* Generated */ /* min/max are checked for optInSlowPeriod. */
108 /* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT )
109 /* Generated */ optInSlowPeriod = 26;
110 /* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) )
111 /* Generated */ return -1;
112 /* Generated */
113 /* Generated */ #if !defined(_MANAGED) && !defined(_JAVA)
114 /* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT )
115 /* Generated */ optInMAType = (TA_MAType)0;
116 /* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )
117 /* Generated */ return -1;
118 /* Generated */
119 /* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/
120 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
121 /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/
122
123 /* insert lookback code here. */
124
125 /* Lookback is driven by the slowest MA. */
126 return LOOKBACK_CALL(MA)( max(optInSlowPeriod,optInFastPeriod), optInMAType );
127 }
128
129 /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
130 /*
131 * TA_PPO - Percentage Price Oscillator
132 *
133 * Input = double
134 * Output = double
135 *
136 * Optional Parameters
137 * -------------------
138 * optInFastPeriod:(From 2 to 100000)
139 * Number of period for the fast MA
140 *
141 * optInSlowPeriod:(From 2 to 100000)
142 * Number of period for the slow MA
143 *
144 * optInMAType:
145 * Type of Moving Average
146 *
147 *
148 */
149 /* Generated */
150 /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
151 /* Generated */ enum class Core::RetCode Core::Ppo( int startIdx,
152 /* Generated */ int endIdx,
153 /* Generated */ SubArray^ inReal,
154 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
155 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
156 /* Generated */ MAType optInMAType,
157 /* Generated */ [Out]int% outBegIdx,
158 /* Generated */ [Out]int% outNBElement,
159 /* Generated */ cli::array<double>^ outReal )
160 /* Generated */ #elif defined( _MANAGED )
161 /* Generated */ enum class Core::RetCode Core::Ppo( int startIdx,
162 /* Generated */ int endIdx,
163 /* Generated */ cli::array<double>^ inReal,
164 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
165 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
166 /* Generated */ MAType optInMAType,
167 /* Generated */ [Out]int% outBegIdx,
168 /* Generated */ [Out]int% outNBElement,
169 /* Generated */ cli::array<double>^ outReal )
170 /* Generated */ #elif defined( _JAVA )
171 /* Generated */ public RetCode ppo( int startIdx,
172 /* Generated */ int endIdx,
173 /* Generated */ double inReal[],
174 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
175 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
176 /* Generated */ MAType optInMAType,
177 /* Generated */ MInteger outBegIdx,
178 /* Generated */ MInteger outNBElement,
179 /* Generated */ double outReal[] )
180 /* Generated */ #else
181 /* Generated */ TA_RetCode TA_PPO( int startIdx,
182 /* Generated */ int endIdx,
183 /* Generated */ const double inReal[],
184 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
185 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
186 /* Generated */ TA_MAType optInMAType,
187 /* Generated */ int *outBegIdx,
188 /* Generated */ int *outNBElement,
189 /* Generated */ double outReal[] )
190 /* Generated */ #endif
191 /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/
192 {
193 /* Insert local variables here. */
194 ARRAY_REF(tempBuffer);
195 ENUM_DECLARATION(RetCode) retCode;
196
197 /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
198 /* Generated */
199 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
200 /* Generated */
201 /* Generated */ /* Validate the requested output range. */
202 /* Generated */ if( startIdx < 0 )
203 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
204 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
205 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
206 /* Generated */
207 /* Generated */ #if !defined(_JAVA)
208 /* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
209 /* Generated */ #endif /* !defined(_JAVA)*/
210 /* Generated */ /* min/max are checked for optInFastPeriod. */
211 /* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT )
212 /* Generated */ optInFastPeriod = 12;
213 /* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) )
214 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
215 /* Generated */
216 /* Generated */ /* min/max are checked for optInSlowPeriod. */
217 /* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT )
218 /* Generated */ optInSlowPeriod = 26;
219 /* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) )
220 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
221 /* Generated */
222 /* Generated */ #if !defined(_MANAGED) && !defined(_JAVA)
223 /* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT )
224 /* Generated */ optInMAType = (TA_MAType)0;
225 /* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )
226 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
227 /* Generated */
228 /* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/
229 /* Generated */ #if !defined(_JAVA)
230 /* Generated */ if( !outReal )
231 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
232 /* Generated */
233 /* Generated */ #endif /* !defined(_JAVA) */
234 /* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */
235 /* Generated */
236 /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/
237
238 /* Insert TA function code here. */
239
240 /* Allocate an intermediate buffer. */
241 ARRAY_ALLOC( tempBuffer, endIdx-startIdx+1 );
242 #if !defined( _JAVA )
243 if( !tempBuffer )
244 return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr);
245 #endif
246
247 retCode = FUNCTION_CALL(INT_PO)( startIdx, endIdx, inReal,
248 optInFastPeriod,
249 optInSlowPeriod,
250 optInMAType,
251 outBegIdx,
252 outNBElement,
253 outReal,
254 tempBuffer,
255 1 /* Do percentage processing. */ );
256
257 ARRAY_FREE( tempBuffer );
258
259 return retCode;
260 }
261
262 /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
263 /* Generated */
264 /* Generated */ #define USE_SINGLE_PRECISION_INPUT
265 /* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA )
266 /* Generated */ #undef TA_PREFIX
267 /* Generated */ #define TA_PREFIX(x) TA_S_##x
268 /* Generated */ #endif
269 /* Generated */ #undef INPUT_TYPE
270 /* Generated */ #define INPUT_TYPE float
271 /* Generated */ #if defined( _MANAGED )
272 /* Generated */ enum class Core::RetCode Core::Ppo( int startIdx,
273 /* Generated */ int endIdx,
274 /* Generated */ cli::array<float>^ inReal,
275 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
276 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
277 /* Generated */ MAType optInMAType,
278 /* Generated */ [Out]int% outBegIdx,
279 /* Generated */ [Out]int% outNBElement,
280 /* Generated */ cli::array<double>^ outReal )
281 /* Generated */ #elif defined( _JAVA )
282 /* Generated */ public RetCode ppo( int startIdx,
283 /* Generated */ int endIdx,
284 /* Generated */ float inReal[],
285 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
286 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
287 /* Generated */ MAType optInMAType,
288 /* Generated */ MInteger outBegIdx,
289 /* Generated */ MInteger outNBElement,
290 /* Generated */ double outReal[] )
291 /* Generated */ #else
292 /* Generated */ TA_RetCode TA_S_PPO( int startIdx,
293 /* Generated */ int endIdx,
294 /* Generated */ const float inReal[],
295 /* Generated */ int optInFastPeriod, /* From 2 to 100000 */
296 /* Generated */ int optInSlowPeriod, /* From 2 to 100000 */
297 /* Generated */ TA_MAType optInMAType,
298 /* Generated */ int *outBegIdx,
299 /* Generated */ int *outNBElement,
300 /* Generated */ double outReal[] )
301 /* Generated */ #endif
302 /* Generated */ {
303 /* Generated */ ARRAY_REF(tempBuffer);
304 /* Generated */ ENUM_DECLARATION(RetCode) retCode;
305 /* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK
306 /* Generated */ if( startIdx < 0 )
307 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex);
308 /* Generated */ if( (endIdx < 0) || (endIdx < startIdx))
309 /* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex);
310 /* Generated */ #if !defined(_JAVA)
311 /* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
312 /* Generated */ #endif
313 /* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT )
314 /* Generated */ optInFastPeriod = 12;
315 /* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) )
316 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
317 /* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT )
318 /* Generated */ optInSlowPeriod = 26;
319 /* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) )
320 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
321 /* Generated */ #if !defined(_MANAGED) && !defined(_JAVA)
322 /* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT )
323 /* Generated */ optInMAType = (TA_MAType)0;
324 /* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) )
325 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
326 /* Generated */ #endif
327 /* Generated */ #if !defined(_JAVA)
328 /* Generated */ if( !outReal )
329 /* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam);
330 /* Generated */ #endif
331 /* Generated */ #endif
332 /* Generated */ ARRAY_ALLOC( tempBuffer, endIdx-startIdx+1 );
333 /* Generated */ #if !defined( _JAVA )
334 /* Generated */ if( !tempBuffer )
335 /* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr);
336 /* Generated */ #endif
337 /* Generated */ retCode = FUNCTION_CALL(INT_PO)( startIdx, endIdx, inReal,
338 /* Generated */ optInFastPeriod,
339 /* Generated */ optInSlowPeriod,
340 /* Generated */ optInMAType,
341 /* Generated */ outBegIdx,
342 /* Generated */ outNBElement,
343 /* Generated */ outReal,
344 /* Generated */ tempBuffer,
345 /* Generated */ 1 );
346 /* Generated */ ARRAY_FREE( tempBuffer );
347 /* Generated */ return retCode;
348 /* Generated */ }
349 /* Generated */
350 /* Generated */ #if defined( _MANAGED )
351 /* Generated */ }}} // Close namespace TicTacTec.TA.Lib
352 /* Generated */ #endif
353 /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/
354
355