diff --git a/CHANGELOG.md b/CHANGELOG.md index b19255b..bd40372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Change Log +## 2.1.1 + * Figured out how to use .gitattributes to exclude files from the composer package. + * Now I can add the TA-Lib C source files to the repository and not have them show up in the composer package. 🎉 +## 2.1.0 + * Added new functions from TA-Lib v0.6.0. + * [ACCBANDS](https://github.com/TA-Lib/ta-lib/blob/main/src/ta_func/ta_ACCBANDS.c) + * [AVGDEV](https://github.com/TA-Lib/ta-lib/blob/main/src/ta_func/ta_AVGDEV.c) + * [IMI](https://github.com/TA-Lib/ta-lib/blob/main/src/ta_func/ta_IMI.c) +## 2.0.1 + * Fixed [Issue #16](https://github.com/LupeCode/phpTraderNative/issues/16) + * Removed version from composer.json as per their spec. +## 2.0.0 + * Cleaned up git repository. + * Drop support for PHP 7.X and 8.0. + * Updated dependencies. + * Cleaned up the code and use PSR-12 formatting. + * Changed the LICENSE to MIT. + * Updated PHPUnit. + * Added better testing data. +## 1.2.3 + * Small updates and bug fixes. + * Added .deepsource.toml for DeepSource.io. +## 1.2.2 + * GitLab CI and TravisCI no longer build this package +## 1.2.1 + * Added PHP 7.0.x to the CI tests. + * Also various things to get this to work in the CI runners. ## 1.2.0 * Added the static variable to the test. Use this instead of a string just in case the string for the errors change. * Test all of the MA types that stochrsi supports. diff --git a/README.md b/README.md index eceb9a8..4eb8f2e 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,13 @@ cd phpTraderNative composer install --dev ~~~ +### Directory Structure + +* `source` - The source code for the library. +* `tests` - The PHPUnit tests for the library. +* `pecl` - The PECL Trader extension source code. +* `talib` - The TA-LIB source code that the PECL Trader extension uses. + ### Testing Two PHPUnit XML files are included, one for testing and the other for coverage. This is due to the fact that when some tests are run with coverage, PHP hangs and never finishes. diff --git a/pecl/function.tpl b/pecl/function.tpl new file mode 100644 index 0000000..d860881 --- /dev/null +++ b/pecl/function.tpl @@ -0,0 +1,86 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array MY_FUNC_NAME_LOWER(MY_FUNC_DOC_PARAMS) + MY_FUNC_DESC */ +PHP_FUNCTION(MY_FUNC_NAME_LOWER) +{ + int optimalOutAlloc, lookback; + MY_IN_PHP_ARRAY_DEFS + MY_FUNC_ARRAY_PARA_DEFS + MY_FUNC_INT_PARA_DEFS + MY_IN_PHP_LONG_DEFS + MY_IN_PHP_DOUBLE_DEFS + +#if PHP_MAJOR_VERSION >= 7 + MY_ZEND_FAST_ZPP +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), MY_ZEND_PARAMS_STR, MY_ZEND_PARAM_LIST) == FAILURE) { + RETURN_FALSE; + } +#endif + + MY_FUNC_CHECK_MA_TYPES + MY_FUNC_SET_BOUNDABLE + + MY_FUNC_SET_MIN_END_IDX + MY_FUNC_SET_START_IDX + + MY_FUNC_OPTIMAL_OUT_ALLOC + if (optimalOutAlloc > 0) { + MY_FUNC_ARRAY_PARA_ALLOCS + + TRADER_G(last_error) = MY_FUNC_NAME(MY_FUNC_PARAMS); + if (TRADER_G(last_error) != TA_SUCCESS) { + MY_FUNC_ARRAY_PARA_DEALLOCS2 + + RETURN_FALSE; + } + + MY_PHP_MAKE_RETURN + + MY_FUNC_ARRAY_PARA_DEALLOCS1 + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_accbands.c b/pecl/trader_accbands.c new file mode 100644 index 0000000..469b0eb --- /dev/null +++ b/pecl/trader_accbands.c @@ -0,0 +1,111 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_accbands(array high, array low, array close [, int timePeriod]) + Acceleration Bands */ +PHP_FUNCTION(trader_accbands) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outRealUpperBand, *outRealMiddleBand, *outRealLowerBand; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ACCBANDS_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outRealUpperBand = emalloc(sizeof(double)*optimalOutAlloc); + outRealMiddleBand = emalloc(sizeof(double)*optimalOutAlloc); + outRealLowerBand = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_ACCBANDS(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outRealUpperBand, outRealMiddleBand, outRealLowerBand); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outRealUpperBand); + efree(outRealMiddleBand); + efree(outRealLowerBand); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET3(outRealUpperBand, outRealMiddleBand, outRealLowerBand, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outRealUpperBand); + efree(outRealMiddleBand); + efree(outRealLowerBand); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_acos.c b/pecl/trader_acos.c new file mode 100644 index 0000000..d38953c --- /dev/null +++ b/pecl/trader_acos.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_acos(array real) + Vector Trigonometric ACos */ +PHP_FUNCTION(trader_acos) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ACOS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ACOS(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ad.c b/pecl/trader_ad.c new file mode 100644 index 0000000..da48492 --- /dev/null +++ b/pecl/trader_ad.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ad(array high, array low, array close, array volume) + Chaikin A/D Line */ +PHP_FUNCTION(trader_ad) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose, *zinVolume; + double *inHigh, *inLow, *inClose, *inVolume, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_ARRAY(zinVolume) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinHigh, &zinLow, &zinClose, &zinVolume) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose)), + zend_hash_num_elements(Z_ARRVAL_P(zinVolume))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_AD_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + TRADER_DBL_ZARR_TO_ARR(zinVolume, inVolume) + + TRADER_G(last_error) = TA_AD(startIdx, endIdx, inHigh, inLow, inClose, inVolume, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(inVolume); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(inVolume); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_add.c b/pecl/trader_add.c new file mode 100644 index 0000000..013d21a --- /dev/null +++ b/pecl/trader_add.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_add(array real0, array real1) + Vector Arithmetic Add */ +PHP_FUNCTION(trader_add) +{ + int optimalOutAlloc, lookback; + zval *zinReal0, *zinReal1; + double *inReal0, *inReal1, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(zinReal0) + Z_PARAM_ARRAY(zinReal1) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal0, &zinReal1) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), + zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ADD_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) + TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) + + TRADER_G(last_error) = TA_ADD(startIdx, endIdx, inReal0, inReal1, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal0); + efree(inReal1); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal0); + efree(inReal1); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_adosc.c b/pecl/trader_adosc.c new file mode 100644 index 0000000..a36bc62 --- /dev/null +++ b/pecl/trader_adosc.c @@ -0,0 +1,112 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_adosc(array high, array low, array close, array volume [, int fastPeriod [, int slowPeriod]]) + Chaikin A/D Oscillator */ +PHP_FUNCTION(trader_adosc) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose, *zinVolume; + double *inHigh, *inLow, *inClose, *inVolume, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastPeriod = 2, optInSlowPeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 6) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_ARRAY(zinVolume) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastPeriod) + Z_PARAM_LONG(optInSlowPeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|ll", &zinHigh, &zinLow, &zinClose, &zinVolume, &optInFastPeriod, &optInSlowPeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInFastPeriod); + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInSlowPeriod); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose)), + zend_hash_num_elements(Z_ARRVAL_P(zinVolume))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ADOSC_Lookback((int)optInFastPeriod, (int)optInSlowPeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + TRADER_DBL_ZARR_TO_ARR(zinVolume, inVolume) + + TRADER_G(last_error) = TA_ADOSC(startIdx, endIdx, inHigh, inLow, inClose, inVolume, (int)optInFastPeriod, (int)optInSlowPeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(inVolume); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(inVolume); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_adx.c b/pecl/trader_adx.c new file mode 100644 index 0000000..c60a3e9 --- /dev/null +++ b/pecl/trader_adx.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_adx(array high, array low, array close [, int timePeriod]) + Average Directional Movement Index */ +PHP_FUNCTION(trader_adx) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ADX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_ADX(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_adxr.c b/pecl/trader_adxr.c new file mode 100644 index 0000000..ab3a7b4 --- /dev/null +++ b/pecl/trader_adxr.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_adxr(array high, array low, array close [, int timePeriod]) + Average Directional Movement Index Rating */ +PHP_FUNCTION(trader_adxr) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ADXR_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_ADXR(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_apo.c b/pecl/trader_apo.c new file mode 100644 index 0000000..fa4c032 --- /dev/null +++ b/pecl/trader_apo.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_apo(array real [, int fastPeriod [, int slowPeriod [, int mAType]]]) + Absolute Price Oscillator */ +PHP_FUNCTION(trader_apo) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastPeriod = 2, optInSlowPeriod = 2, optInMAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastPeriod) + Z_PARAM_LONG(optInSlowPeriod) + Z_PARAM_LONG(optInMAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|lll", &zinReal, &optInFastPeriod, &optInSlowPeriod, &optInMAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInMAType) + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInFastPeriod); + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInSlowPeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_APO_Lookback((int)optInFastPeriod, (int)optInSlowPeriod, (int)optInMAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_APO(startIdx, endIdx, inReal, (int)optInFastPeriod, (int)optInSlowPeriod, (int)optInMAType, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_aroon.c b/pecl/trader_aroon.c new file mode 100644 index 0000000..f8dd53f --- /dev/null +++ b/pecl/trader_aroon.c @@ -0,0 +1,103 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_aroon(array high, array low [, int timePeriod]) + Aroon */ +PHP_FUNCTION(trader_aroon) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outAroonDown, *outAroonUp; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinHigh, &zinLow, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_AROON_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outAroonDown = emalloc(sizeof(double)*optimalOutAlloc); + outAroonUp = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_AROON(startIdx, endIdx, inHigh, inLow, (int)optInTimePeriod, &outBegIdx, &outNBElement, outAroonDown, outAroonUp); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outAroonDown); + efree(outAroonUp); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outAroonDown, outAroonUp, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outAroonDown); + efree(outAroonUp); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_aroonosc.c b/pecl/trader_aroonosc.c new file mode 100644 index 0000000..604e2b3 --- /dev/null +++ b/pecl/trader_aroonosc.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_aroonosc(array high, array low [, int timePeriod]) + Aroon Oscillator */ +PHP_FUNCTION(trader_aroonosc) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinHigh, &zinLow, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_AROONOSC_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_AROONOSC(startIdx, endIdx, inHigh, inLow, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_asin.c b/pecl/trader_asin.c new file mode 100644 index 0000000..0236a65 --- /dev/null +++ b/pecl/trader_asin.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_asin(array real) + Vector Trigonometric ASin */ +PHP_FUNCTION(trader_asin) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ASIN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ASIN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_atan.c b/pecl/trader_atan.c new file mode 100644 index 0000000..cbe91ed --- /dev/null +++ b/pecl/trader_atan.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_atan(array real) + Vector Trigonometric ATan */ +PHP_FUNCTION(trader_atan) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ATAN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ATAN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_atr.c b/pecl/trader_atr.c new file mode 100644 index 0000000..f4a0960 --- /dev/null +++ b/pecl/trader_atr.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_atr(array high, array low, array close [, int timePeriod]) + Average True Range */ +PHP_FUNCTION(trader_atr) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ATR_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_ATR(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_avgdev.c b/pecl/trader_avgdev.c new file mode 100644 index 0000000..e9cfdc5 --- /dev/null +++ b/pecl/trader_avgdev.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_avgdev(array real [, int timePeriod]) + Average Deviation */ +PHP_FUNCTION(trader_avgdev) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_AVGDEV_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_AVGDEV(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_avgprice.c b/pecl/trader_avgprice.c new file mode 100644 index 0000000..93c0372 --- /dev/null +++ b/pecl/trader_avgprice.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_avgprice(array open, array high, array low, array close) + Average Price */ +PHP_FUNCTION(trader_avgprice) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_AVGPRICE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_AVGPRICE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_bbands.c b/pecl/trader_bbands.c new file mode 100644 index 0000000..65de50b --- /dev/null +++ b/pecl/trader_bbands.c @@ -0,0 +1,106 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_bbands(array real [, int timePeriod [, float nbDevUp [, float nbDevDn [, int mAType]]]]) + Bollinger Bands */ +PHP_FUNCTION(trader_bbands) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outRealUpperBand, *outRealMiddleBand, *outRealLowerBand; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2, optInMAType = 0; + double optInNbDevUp = TA_REAL_MIN, optInNbDevDn = TA_REAL_MIN; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 5) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + Z_PARAM_DOUBLE(optInNbDevUp) + Z_PARAM_DOUBLE(optInNbDevDn) + Z_PARAM_LONG(optInMAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|lddl", &zinReal, &optInTimePeriod, &optInNbDevUp, &optInNbDevDn, &optInMAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInMAType) + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + TRADER_DBL_SET_BOUNDABLE(TA_REAL_MIN, TA_REAL_MAX, optInNbDevUp); + TRADER_DBL_SET_BOUNDABLE(TA_REAL_MIN, TA_REAL_MAX, optInNbDevDn); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_BBANDS_Lookback((int)optInTimePeriod, optInNbDevUp, optInNbDevDn, (int)optInMAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outRealUpperBand = emalloc(sizeof(double)*optimalOutAlloc); + outRealMiddleBand = emalloc(sizeof(double)*optimalOutAlloc); + outRealLowerBand = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_BBANDS(startIdx, endIdx, inReal, (int)optInTimePeriod, optInNbDevUp, optInNbDevDn, (int)optInMAType, &outBegIdx, &outNBElement, outRealUpperBand, outRealMiddleBand, outRealLowerBand); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outRealUpperBand); + efree(outRealMiddleBand); + efree(outRealLowerBand); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET3(outRealUpperBand, outRealMiddleBand, outRealLowerBand, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outRealUpperBand); + efree(outRealMiddleBand); + efree(outRealLowerBand); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_beta.c b/pecl/trader_beta.c new file mode 100644 index 0000000..9836a3b --- /dev/null +++ b/pecl/trader_beta.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_beta(array real0, array real1 [, int timePeriod]) + Beta */ +PHP_FUNCTION(trader_beta) +{ + int optimalOutAlloc, lookback; + zval *zinReal0, *zinReal1; + double *inReal0, *inReal1, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinReal0) + Z_PARAM_ARRAY(zinReal1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinReal0, &zinReal1, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), + zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_BETA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) + TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) + + TRADER_G(last_error) = TA_BETA(startIdx, endIdx, inReal0, inReal1, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal0); + efree(inReal1); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal0); + efree(inReal1); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_bop.c b/pecl/trader_bop.c new file mode 100644 index 0000000..b70c99b --- /dev/null +++ b/pecl/trader_bop.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_bop(array open, array high, array low, array close) + Balance Of Power */ +PHP_FUNCTION(trader_bop) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_BOP_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_BOP(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cci.c b/pecl/trader_cci.c new file mode 100644 index 0000000..5a23301 --- /dev/null +++ b/pecl/trader_cci.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cci(array high, array low, array close [, int timePeriod]) + Commodity Channel Index */ +PHP_FUNCTION(trader_cci) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CCI_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CCI(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl2crows.c b/pecl/trader_cdl2crows.c new file mode 100644 index 0000000..980e840 --- /dev/null +++ b/pecl/trader_cdl2crows.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl2crows(array open, array high, array low, array close) + Two Crows */ +PHP_FUNCTION(trader_cdl2crows) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL2CROWS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL2CROWS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl3blackcrows.c b/pecl/trader_cdl3blackcrows.c new file mode 100644 index 0000000..1e4f13d --- /dev/null +++ b/pecl/trader_cdl3blackcrows.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl3blackcrows(array open, array high, array low, array close) + Three Black Crows */ +PHP_FUNCTION(trader_cdl3blackcrows) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL3BLACKCROWS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL3BLACKCROWS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl3inside.c b/pecl/trader_cdl3inside.c new file mode 100644 index 0000000..edabe47 --- /dev/null +++ b/pecl/trader_cdl3inside.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl3inside(array open, array high, array low, array close) + Three Inside Up/Down */ +PHP_FUNCTION(trader_cdl3inside) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL3INSIDE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL3INSIDE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl3linestrike.c b/pecl/trader_cdl3linestrike.c new file mode 100644 index 0000000..201d909 --- /dev/null +++ b/pecl/trader_cdl3linestrike.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl3linestrike(array open, array high, array low, array close) + Three-Line Strike */ +PHP_FUNCTION(trader_cdl3linestrike) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL3LINESTRIKE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL3LINESTRIKE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl3outside.c b/pecl/trader_cdl3outside.c new file mode 100644 index 0000000..d9c7a03 --- /dev/null +++ b/pecl/trader_cdl3outside.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl3outside(array open, array high, array low, array close) + Three Outside Up/Down */ +PHP_FUNCTION(trader_cdl3outside) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL3OUTSIDE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL3OUTSIDE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl3starsinsouth.c b/pecl/trader_cdl3starsinsouth.c new file mode 100644 index 0000000..0c3f9cb --- /dev/null +++ b/pecl/trader_cdl3starsinsouth.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl3starsinsouth(array open, array high, array low, array close) + Three Stars In The South */ +PHP_FUNCTION(trader_cdl3starsinsouth) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL3STARSINSOUTH_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL3STARSINSOUTH(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdl3whitesoldiers.c b/pecl/trader_cdl3whitesoldiers.c new file mode 100644 index 0000000..8cc8021 --- /dev/null +++ b/pecl/trader_cdl3whitesoldiers.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdl3whitesoldiers(array open, array high, array low, array close) + Three Advancing White Soldiers */ +PHP_FUNCTION(trader_cdl3whitesoldiers) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDL3WHITESOLDIERS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDL3WHITESOLDIERS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlabandonedbaby.c b/pecl/trader_cdlabandonedbaby.c new file mode 100644 index 0000000..84ee9cb --- /dev/null +++ b/pecl/trader_cdlabandonedbaby.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlabandonedbaby(array open, array high, array low, array close [, float penetration]) + Abandoned Baby */ +PHP_FUNCTION(trader_cdlabandonedbaby) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLABANDONEDBABY_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLABANDONEDBABY(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdladvanceblock.c b/pecl/trader_cdladvanceblock.c new file mode 100644 index 0000000..647efef --- /dev/null +++ b/pecl/trader_cdladvanceblock.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdladvanceblock(array open, array high, array low, array close) + Advance Block */ +PHP_FUNCTION(trader_cdladvanceblock) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLADVANCEBLOCK_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLADVANCEBLOCK(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlbelthold.c b/pecl/trader_cdlbelthold.c new file mode 100644 index 0000000..a725583 --- /dev/null +++ b/pecl/trader_cdlbelthold.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlbelthold(array open, array high, array low, array close) + Belt-hold */ +PHP_FUNCTION(trader_cdlbelthold) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLBELTHOLD_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLBELTHOLD(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlbreakaway.c b/pecl/trader_cdlbreakaway.c new file mode 100644 index 0000000..ca1f32f --- /dev/null +++ b/pecl/trader_cdlbreakaway.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlbreakaway(array open, array high, array low, array close) + Breakaway */ +PHP_FUNCTION(trader_cdlbreakaway) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLBREAKAWAY_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLBREAKAWAY(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlclosingmarubozu.c b/pecl/trader_cdlclosingmarubozu.c new file mode 100644 index 0000000..34c62cc --- /dev/null +++ b/pecl/trader_cdlclosingmarubozu.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlclosingmarubozu(array open, array high, array low, array close) + Closing Marubozu */ +PHP_FUNCTION(trader_cdlclosingmarubozu) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLCLOSINGMARUBOZU_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLCLOSINGMARUBOZU(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlconcealbabyswall.c b/pecl/trader_cdlconcealbabyswall.c new file mode 100644 index 0000000..bc5741c --- /dev/null +++ b/pecl/trader_cdlconcealbabyswall.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlconcealbabyswall(array open, array high, array low, array close) + Concealing Baby Swallow */ +PHP_FUNCTION(trader_cdlconcealbabyswall) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLCONCEALBABYSWALL_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLCONCEALBABYSWALL(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlcounterattack.c b/pecl/trader_cdlcounterattack.c new file mode 100644 index 0000000..c2a3283 --- /dev/null +++ b/pecl/trader_cdlcounterattack.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlcounterattack(array open, array high, array low, array close) + Counterattack */ +PHP_FUNCTION(trader_cdlcounterattack) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLCOUNTERATTACK_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLCOUNTERATTACK(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdldarkcloudcover.c b/pecl/trader_cdldarkcloudcover.c new file mode 100644 index 0000000..cef86f6 --- /dev/null +++ b/pecl/trader_cdldarkcloudcover.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdldarkcloudcover(array open, array high, array low, array close [, float penetration]) + Dark Cloud Cover */ +PHP_FUNCTION(trader_cdldarkcloudcover) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLDARKCLOUDCOVER_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLDARKCLOUDCOVER(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdldoji.c b/pecl/trader_cdldoji.c new file mode 100644 index 0000000..ef95a7e --- /dev/null +++ b/pecl/trader_cdldoji.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdldoji(array open, array high, array low, array close) + Doji */ +PHP_FUNCTION(trader_cdldoji) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLDOJI_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLDOJI(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdldojistar.c b/pecl/trader_cdldojistar.c new file mode 100644 index 0000000..5ec5717 --- /dev/null +++ b/pecl/trader_cdldojistar.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdldojistar(array open, array high, array low, array close) + Doji Star */ +PHP_FUNCTION(trader_cdldojistar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLDOJISTAR_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLDOJISTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdldragonflydoji.c b/pecl/trader_cdldragonflydoji.c new file mode 100644 index 0000000..80ef411 --- /dev/null +++ b/pecl/trader_cdldragonflydoji.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdldragonflydoji(array open, array high, array low, array close) + Dragonfly Doji */ +PHP_FUNCTION(trader_cdldragonflydoji) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLDRAGONFLYDOJI_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLDRAGONFLYDOJI(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlengulfing.c b/pecl/trader_cdlengulfing.c new file mode 100644 index 0000000..4d35919 --- /dev/null +++ b/pecl/trader_cdlengulfing.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlengulfing(array open, array high, array low, array close) + Engulfing Pattern */ +PHP_FUNCTION(trader_cdlengulfing) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLENGULFING_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLENGULFING(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdleveningdojistar.c b/pecl/trader_cdleveningdojistar.c new file mode 100644 index 0000000..ca51a90 --- /dev/null +++ b/pecl/trader_cdleveningdojistar.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdleveningdojistar(array open, array high, array low, array close [, float penetration]) + Evening Doji Star */ +PHP_FUNCTION(trader_cdleveningdojistar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLEVENINGDOJISTAR_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLEVENINGDOJISTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdleveningstar.c b/pecl/trader_cdleveningstar.c new file mode 100644 index 0000000..7506dac --- /dev/null +++ b/pecl/trader_cdleveningstar.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdleveningstar(array open, array high, array low, array close [, float penetration]) + Evening Star */ +PHP_FUNCTION(trader_cdleveningstar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLEVENINGSTAR_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLEVENINGSTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlgapsidesidewhite.c b/pecl/trader_cdlgapsidesidewhite.c new file mode 100644 index 0000000..739b4a3 --- /dev/null +++ b/pecl/trader_cdlgapsidesidewhite.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlgapsidesidewhite(array open, array high, array low, array close) + Up/Down-gap side-by-side white lines */ +PHP_FUNCTION(trader_cdlgapsidesidewhite) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLGAPSIDESIDEWHITE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLGAPSIDESIDEWHITE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlgravestonedoji.c b/pecl/trader_cdlgravestonedoji.c new file mode 100644 index 0000000..e0eff63 --- /dev/null +++ b/pecl/trader_cdlgravestonedoji.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlgravestonedoji(array open, array high, array low, array close) + Gravestone Doji */ +PHP_FUNCTION(trader_cdlgravestonedoji) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLGRAVESTONEDOJI_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLGRAVESTONEDOJI(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlhammer.c b/pecl/trader_cdlhammer.c new file mode 100644 index 0000000..fde65c7 --- /dev/null +++ b/pecl/trader_cdlhammer.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlhammer(array open, array high, array low, array close) + Hammer */ +PHP_FUNCTION(trader_cdlhammer) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHAMMER_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHAMMER(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlhangingman.c b/pecl/trader_cdlhangingman.c new file mode 100644 index 0000000..b448f49 --- /dev/null +++ b/pecl/trader_cdlhangingman.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlhangingman(array open, array high, array low, array close) + Hanging Man */ +PHP_FUNCTION(trader_cdlhangingman) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHANGINGMAN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHANGINGMAN(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlharami.c b/pecl/trader_cdlharami.c new file mode 100644 index 0000000..ec6e163 --- /dev/null +++ b/pecl/trader_cdlharami.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlharami(array open, array high, array low, array close) + Harami Pattern */ +PHP_FUNCTION(trader_cdlharami) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHARAMI_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHARAMI(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlharamicross.c b/pecl/trader_cdlharamicross.c new file mode 100644 index 0000000..40402c3 --- /dev/null +++ b/pecl/trader_cdlharamicross.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlharamicross(array open, array high, array low, array close) + Harami Cross Pattern */ +PHP_FUNCTION(trader_cdlharamicross) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHARAMICROSS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHARAMICROSS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlhighwave.c b/pecl/trader_cdlhighwave.c new file mode 100644 index 0000000..56d64cb --- /dev/null +++ b/pecl/trader_cdlhighwave.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlhighwave(array open, array high, array low, array close) + High-Wave Candle */ +PHP_FUNCTION(trader_cdlhighwave) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHIGHWAVE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHIGHWAVE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlhikkake.c b/pecl/trader_cdlhikkake.c new file mode 100644 index 0000000..3219e67 --- /dev/null +++ b/pecl/trader_cdlhikkake.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlhikkake(array open, array high, array low, array close) + Hikkake Pattern */ +PHP_FUNCTION(trader_cdlhikkake) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHIKKAKE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHIKKAKE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlhikkakemod.c b/pecl/trader_cdlhikkakemod.c new file mode 100644 index 0000000..ff36784 --- /dev/null +++ b/pecl/trader_cdlhikkakemod.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlhikkakemod(array open, array high, array low, array close) + Modified Hikkake Pattern */ +PHP_FUNCTION(trader_cdlhikkakemod) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHIKKAKEMOD_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHIKKAKEMOD(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlhomingpigeon.c b/pecl/trader_cdlhomingpigeon.c new file mode 100644 index 0000000..b467eb4 --- /dev/null +++ b/pecl/trader_cdlhomingpigeon.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlhomingpigeon(array open, array high, array low, array close) + Homing Pigeon */ +PHP_FUNCTION(trader_cdlhomingpigeon) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLHOMINGPIGEON_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLHOMINGPIGEON(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlidentical3crows.c b/pecl/trader_cdlidentical3crows.c new file mode 100644 index 0000000..85355df --- /dev/null +++ b/pecl/trader_cdlidentical3crows.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlidentical3crows(array open, array high, array low, array close) + Identical Three Crows */ +PHP_FUNCTION(trader_cdlidentical3crows) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLIDENTICAL3CROWS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLIDENTICAL3CROWS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlinneck.c b/pecl/trader_cdlinneck.c new file mode 100644 index 0000000..fb9f285 --- /dev/null +++ b/pecl/trader_cdlinneck.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlinneck(array open, array high, array low, array close) + In-Neck Pattern */ +PHP_FUNCTION(trader_cdlinneck) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLINNECK_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLINNECK(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlinvertedhammer.c b/pecl/trader_cdlinvertedhammer.c new file mode 100644 index 0000000..7cc8dcf --- /dev/null +++ b/pecl/trader_cdlinvertedhammer.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlinvertedhammer(array open, array high, array low, array close) + Inverted Hammer */ +PHP_FUNCTION(trader_cdlinvertedhammer) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLINVERTEDHAMMER_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLINVERTEDHAMMER(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlkicking.c b/pecl/trader_cdlkicking.c new file mode 100644 index 0000000..ddbe473 --- /dev/null +++ b/pecl/trader_cdlkicking.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlkicking(array open, array high, array low, array close) + Kicking */ +PHP_FUNCTION(trader_cdlkicking) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLKICKING_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLKICKING(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlkickingbylength.c b/pecl/trader_cdlkickingbylength.c new file mode 100644 index 0000000..4392f22 --- /dev/null +++ b/pecl/trader_cdlkickingbylength.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlkickingbylength(array open, array high, array low, array close) + Kicking - bull/bear determined by the longer marubozu */ +PHP_FUNCTION(trader_cdlkickingbylength) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLKICKINGBYLENGTH_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLKICKINGBYLENGTH(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlladderbottom.c b/pecl/trader_cdlladderbottom.c new file mode 100644 index 0000000..8468664 --- /dev/null +++ b/pecl/trader_cdlladderbottom.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlladderbottom(array open, array high, array low, array close) + Ladder Bottom */ +PHP_FUNCTION(trader_cdlladderbottom) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLLADDERBOTTOM_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLLADDERBOTTOM(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdllongleggeddoji.c b/pecl/trader_cdllongleggeddoji.c new file mode 100644 index 0000000..e65a135 --- /dev/null +++ b/pecl/trader_cdllongleggeddoji.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdllongleggeddoji(array open, array high, array low, array close) + Long Legged Doji */ +PHP_FUNCTION(trader_cdllongleggeddoji) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLLONGLEGGEDDOJI_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLLONGLEGGEDDOJI(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdllongline.c b/pecl/trader_cdllongline.c new file mode 100644 index 0000000..b5a7f2b --- /dev/null +++ b/pecl/trader_cdllongline.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdllongline(array open, array high, array low, array close) + Long Line Candle */ +PHP_FUNCTION(trader_cdllongline) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLLONGLINE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLLONGLINE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlmarubozu.c b/pecl/trader_cdlmarubozu.c new file mode 100644 index 0000000..db4c13f --- /dev/null +++ b/pecl/trader_cdlmarubozu.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlmarubozu(array open, array high, array low, array close) + Marubozu */ +PHP_FUNCTION(trader_cdlmarubozu) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLMARUBOZU_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLMARUBOZU(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlmatchinglow.c b/pecl/trader_cdlmatchinglow.c new file mode 100644 index 0000000..fbb5df3 --- /dev/null +++ b/pecl/trader_cdlmatchinglow.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlmatchinglow(array open, array high, array low, array close) + Matching Low */ +PHP_FUNCTION(trader_cdlmatchinglow) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLMATCHINGLOW_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLMATCHINGLOW(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlmathold.c b/pecl/trader_cdlmathold.c new file mode 100644 index 0000000..f725f85 --- /dev/null +++ b/pecl/trader_cdlmathold.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlmathold(array open, array high, array low, array close [, float penetration]) + Mat Hold */ +PHP_FUNCTION(trader_cdlmathold) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLMATHOLD_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLMATHOLD(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlmorningdojistar.c b/pecl/trader_cdlmorningdojistar.c new file mode 100644 index 0000000..7d44c33 --- /dev/null +++ b/pecl/trader_cdlmorningdojistar.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlmorningdojistar(array open, array high, array low, array close [, float penetration]) + Morning Doji Star */ +PHP_FUNCTION(trader_cdlmorningdojistar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLMORNINGDOJISTAR_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLMORNINGDOJISTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlmorningstar.c b/pecl/trader_cdlmorningstar.c new file mode 100644 index 0000000..7e93b01 --- /dev/null +++ b/pecl/trader_cdlmorningstar.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlmorningstar(array open, array high, array low, array close [, float penetration]) + Morning Star */ +PHP_FUNCTION(trader_cdlmorningstar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + double optInPenetration = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInPenetration) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|d", &zinOpen, &zinHigh, &zinLow, &zinClose, &optInPenetration) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInPenetration); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLMORNINGSTAR_Lookback(optInPenetration); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLMORNINGSTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, optInPenetration, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlonneck.c b/pecl/trader_cdlonneck.c new file mode 100644 index 0000000..8e890ed --- /dev/null +++ b/pecl/trader_cdlonneck.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlonneck(array open, array high, array low, array close) + On-Neck Pattern */ +PHP_FUNCTION(trader_cdlonneck) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLONNECK_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLONNECK(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlpiercing.c b/pecl/trader_cdlpiercing.c new file mode 100644 index 0000000..3eba9a6 --- /dev/null +++ b/pecl/trader_cdlpiercing.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlpiercing(array open, array high, array low, array close) + Piercing Pattern */ +PHP_FUNCTION(trader_cdlpiercing) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLPIERCING_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLPIERCING(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlrickshawman.c b/pecl/trader_cdlrickshawman.c new file mode 100644 index 0000000..2730e05 --- /dev/null +++ b/pecl/trader_cdlrickshawman.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlrickshawman(array open, array high, array low, array close) + Rickshaw Man */ +PHP_FUNCTION(trader_cdlrickshawman) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLRICKSHAWMAN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLRICKSHAWMAN(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlrisefall3methods.c b/pecl/trader_cdlrisefall3methods.c new file mode 100644 index 0000000..38804f6 --- /dev/null +++ b/pecl/trader_cdlrisefall3methods.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlrisefall3methods(array open, array high, array low, array close) + Rising/Falling Three Methods */ +PHP_FUNCTION(trader_cdlrisefall3methods) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLRISEFALL3METHODS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLRISEFALL3METHODS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlseparatinglines.c b/pecl/trader_cdlseparatinglines.c new file mode 100644 index 0000000..33814ca --- /dev/null +++ b/pecl/trader_cdlseparatinglines.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlseparatinglines(array open, array high, array low, array close) + Separating Lines */ +PHP_FUNCTION(trader_cdlseparatinglines) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLSEPARATINGLINES_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLSEPARATINGLINES(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlshootingstar.c b/pecl/trader_cdlshootingstar.c new file mode 100644 index 0000000..54f738c --- /dev/null +++ b/pecl/trader_cdlshootingstar.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlshootingstar(array open, array high, array low, array close) + Shooting Star */ +PHP_FUNCTION(trader_cdlshootingstar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLSHOOTINGSTAR_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLSHOOTINGSTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlshortline.c b/pecl/trader_cdlshortline.c new file mode 100644 index 0000000..8aa80b3 --- /dev/null +++ b/pecl/trader_cdlshortline.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlshortline(array open, array high, array low, array close) + Short Line Candle */ +PHP_FUNCTION(trader_cdlshortline) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLSHORTLINE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLSHORTLINE(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlspinningtop.c b/pecl/trader_cdlspinningtop.c new file mode 100644 index 0000000..c65dad1 --- /dev/null +++ b/pecl/trader_cdlspinningtop.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlspinningtop(array open, array high, array low, array close) + Spinning Top */ +PHP_FUNCTION(trader_cdlspinningtop) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLSPINNINGTOP_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLSPINNINGTOP(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlstalledpattern.c b/pecl/trader_cdlstalledpattern.c new file mode 100644 index 0000000..482fb76 --- /dev/null +++ b/pecl/trader_cdlstalledpattern.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlstalledpattern(array open, array high, array low, array close) + Stalled Pattern */ +PHP_FUNCTION(trader_cdlstalledpattern) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLSTALLEDPATTERN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLSTALLEDPATTERN(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlsticksandwich.c b/pecl/trader_cdlsticksandwich.c new file mode 100644 index 0000000..3c839c2 --- /dev/null +++ b/pecl/trader_cdlsticksandwich.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlsticksandwich(array open, array high, array low, array close) + Stick Sandwich */ +PHP_FUNCTION(trader_cdlsticksandwich) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLSTICKSANDWICH_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLSTICKSANDWICH(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdltakuri.c b/pecl/trader_cdltakuri.c new file mode 100644 index 0000000..d13a536 --- /dev/null +++ b/pecl/trader_cdltakuri.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdltakuri(array open, array high, array low, array close) + Takuri (Dragonfly Doji with very long lower shadow) */ +PHP_FUNCTION(trader_cdltakuri) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLTAKURI_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLTAKURI(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdltasukigap.c b/pecl/trader_cdltasukigap.c new file mode 100644 index 0000000..8ee085b --- /dev/null +++ b/pecl/trader_cdltasukigap.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdltasukigap(array open, array high, array low, array close) + Tasuki Gap */ +PHP_FUNCTION(trader_cdltasukigap) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLTASUKIGAP_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLTASUKIGAP(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlthrusting.c b/pecl/trader_cdlthrusting.c new file mode 100644 index 0000000..12a5d29 --- /dev/null +++ b/pecl/trader_cdlthrusting.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlthrusting(array open, array high, array low, array close) + Thrusting Pattern */ +PHP_FUNCTION(trader_cdlthrusting) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLTHRUSTING_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLTHRUSTING(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdltristar.c b/pecl/trader_cdltristar.c new file mode 100644 index 0000000..4bcf3a1 --- /dev/null +++ b/pecl/trader_cdltristar.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdltristar(array open, array high, array low, array close) + Tristar Pattern */ +PHP_FUNCTION(trader_cdltristar) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLTRISTAR_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLTRISTAR(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlunique3river.c b/pecl/trader_cdlunique3river.c new file mode 100644 index 0000000..ad3252c --- /dev/null +++ b/pecl/trader_cdlunique3river.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlunique3river(array open, array high, array low, array close) + Unique 3 River */ +PHP_FUNCTION(trader_cdlunique3river) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLUNIQUE3RIVER_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLUNIQUE3RIVER(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlupsidegap2crows.c b/pecl/trader_cdlupsidegap2crows.c new file mode 100644 index 0000000..30650ad --- /dev/null +++ b/pecl/trader_cdlupsidegap2crows.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlupsidegap2crows(array open, array high, array low, array close) + Upside Gap Two Crows */ +PHP_FUNCTION(trader_cdlupsidegap2crows) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLUPSIDEGAP2CROWS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLUPSIDEGAP2CROWS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cdlxsidegap3methods.c b/pecl/trader_cdlxsidegap3methods.c new file mode 100644 index 0000000..d94a5ab --- /dev/null +++ b/pecl/trader_cdlxsidegap3methods.c @@ -0,0 +1,108 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cdlxsidegap3methods(array open, array high, array low, array close) + Upside/Downside Gap Three Methods */ +PHP_FUNCTION(trader_cdlxsidegap3methods) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinHigh, *zinLow, *zinClose; + double *inOpen, *inHigh, *inLow, *inClose; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 4) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa", &zinOpen, &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CDLXSIDEGAP3METHODS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_CDLXSIDEGAP3METHODS(startIdx, endIdx, inOpen, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ceil.c b/pecl/trader_ceil.c new file mode 100644 index 0000000..4e0addb --- /dev/null +++ b/pecl/trader_ceil.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ceil(array real) + Vector Ceil */ +PHP_FUNCTION(trader_ceil) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CEIL_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_CEIL(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cmo.c b/pecl/trader_cmo.c new file mode 100644 index 0000000..cb877bc --- /dev/null +++ b/pecl/trader_cmo.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cmo(array real [, int timePeriod]) + Chande Momentum Oscillator */ +PHP_FUNCTION(trader_cmo) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CMO_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_CMO(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_correl.c b/pecl/trader_correl.c new file mode 100644 index 0000000..9c1ac73 --- /dev/null +++ b/pecl/trader_correl.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_correl(array real0, array real1 [, int timePeriod]) + Pearson's Correlation Coefficient (r) */ +PHP_FUNCTION(trader_correl) +{ + int optimalOutAlloc, lookback; + zval *zinReal0, *zinReal1; + double *inReal0, *inReal1, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinReal0) + Z_PARAM_ARRAY(zinReal1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinReal0, &zinReal1, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), + zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_CORREL_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) + TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) + + TRADER_G(last_error) = TA_CORREL(startIdx, endIdx, inReal0, inReal1, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal0); + efree(inReal1); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal0); + efree(inReal1); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cos.c b/pecl/trader_cos.c new file mode 100644 index 0000000..d87fbac --- /dev/null +++ b/pecl/trader_cos.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cos(array real) + Vector Trigonometric Cos */ +PHP_FUNCTION(trader_cos) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_COS_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_COS(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_cosh.c b/pecl/trader_cosh.c new file mode 100644 index 0000000..62866c2 --- /dev/null +++ b/pecl/trader_cosh.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_cosh(array real) + Vector Trigonometric Cosh */ +PHP_FUNCTION(trader_cosh) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_COSH_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_COSH(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_dema.c b/pecl/trader_dema.c new file mode 100644 index 0000000..3d1e9e7 --- /dev/null +++ b/pecl/trader_dema.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_dema(array real [, int timePeriod]) + Double Exponential Moving Average */ +PHP_FUNCTION(trader_dema) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_DEMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_DEMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_div.c b/pecl/trader_div.c new file mode 100644 index 0000000..7d8fe9e --- /dev/null +++ b/pecl/trader_div.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_div(array real0, array real1) + Vector Arithmetic Div */ +PHP_FUNCTION(trader_div) +{ + int optimalOutAlloc, lookback; + zval *zinReal0, *zinReal1; + double *inReal0, *inReal1, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(zinReal0) + Z_PARAM_ARRAY(zinReal1) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal0, &zinReal1) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), + zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_DIV_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) + TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) + + TRADER_G(last_error) = TA_DIV(startIdx, endIdx, inReal0, inReal1, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal0); + efree(inReal1); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal0); + efree(inReal1); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_dx.c b/pecl/trader_dx.c new file mode 100644 index 0000000..6dcf547 --- /dev/null +++ b/pecl/trader_dx.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_dx(array high, array low, array close [, int timePeriod]) + Directional Movement Index */ +PHP_FUNCTION(trader_dx) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_DX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_DX(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ema.c b/pecl/trader_ema.c new file mode 100644 index 0000000..192a4eb --- /dev/null +++ b/pecl/trader_ema.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ema(array real [, int timePeriod]) + Exponential Moving Average */ +PHP_FUNCTION(trader_ema) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_EMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_EMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_exp.c b/pecl/trader_exp.c new file mode 100644 index 0000000..d66ad9c --- /dev/null +++ b/pecl/trader_exp.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_exp(array real) + Vector Arithmetic Exp */ +PHP_FUNCTION(trader_exp) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_EXP_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_EXP(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_floor.c b/pecl/trader_floor.c new file mode 100644 index 0000000..b9b5cf9 --- /dev/null +++ b/pecl/trader_floor.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_floor(array real) + Vector Floor */ +PHP_FUNCTION(trader_floor) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_FLOOR_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_FLOOR(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ht_dcperiod.c b/pecl/trader_ht_dcperiod.c new file mode 100644 index 0000000..6cfd478 --- /dev/null +++ b/pecl/trader_ht_dcperiod.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ht_dcperiod(array real) + Hilbert Transform - Dominant Cycle Period */ +PHP_FUNCTION(trader_ht_dcperiod) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_HT_DCPERIOD_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_HT_DCPERIOD(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ht_dcphase.c b/pecl/trader_ht_dcphase.c new file mode 100644 index 0000000..47209d2 --- /dev/null +++ b/pecl/trader_ht_dcphase.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ht_dcphase(array real) + Hilbert Transform - Dominant Cycle Phase */ +PHP_FUNCTION(trader_ht_dcphase) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_HT_DCPHASE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_HT_DCPHASE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ht_phasor.c b/pecl/trader_ht_phasor.c new file mode 100644 index 0000000..234851b --- /dev/null +++ b/pecl/trader_ht_phasor.c @@ -0,0 +1,96 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ht_phasor(array real) + Hilbert Transform - Phasor Components */ +PHP_FUNCTION(trader_ht_phasor) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outInPhase, *outQuadrature; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_HT_PHASOR_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInPhase = emalloc(sizeof(double)*optimalOutAlloc); + outQuadrature = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_HT_PHASOR(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outInPhase, outQuadrature); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outInPhase); + efree(outQuadrature); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outInPhase, outQuadrature, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outInPhase); + efree(outQuadrature); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ht_sine.c b/pecl/trader_ht_sine.c new file mode 100644 index 0000000..000ca41 --- /dev/null +++ b/pecl/trader_ht_sine.c @@ -0,0 +1,96 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ht_sine(array real) + Hilbert Transform - SineWave */ +PHP_FUNCTION(trader_ht_sine) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outSine, *outLeadSine; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_HT_SINE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outSine = emalloc(sizeof(double)*optimalOutAlloc); + outLeadSine = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_HT_SINE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outSine, outLeadSine); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outSine); + efree(outLeadSine); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outSine, outLeadSine, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outSine); + efree(outLeadSine); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ht_trendline.c b/pecl/trader_ht_trendline.c new file mode 100644 index 0000000..e09c0df --- /dev/null +++ b/pecl/trader_ht_trendline.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ht_trendline(array real) + Hilbert Transform - Instantaneous Trendline */ +PHP_FUNCTION(trader_ht_trendline) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_HT_TRENDLINE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_HT_TRENDLINE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ht_trendmode.c b/pecl/trader_ht_trendmode.c new file mode 100644 index 0000000..5aa11d7 --- /dev/null +++ b/pecl/trader_ht_trendmode.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ht_trendmode(array real) + Hilbert Transform - Trend vs Cycle Mode */ +PHP_FUNCTION(trader_ht_trendmode) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_HT_TRENDMODE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_HT_TRENDMODE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_imi.c b/pecl/trader_imi.c new file mode 100644 index 0000000..558d892 --- /dev/null +++ b/pecl/trader_imi.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_imi(array open, array close [, int timePeriod]) + Intraday Momentum Index */ +PHP_FUNCTION(trader_imi) +{ + int optimalOutAlloc, lookback; + zval *zinOpen, *zinClose; + double *inOpen, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinOpen) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinOpen, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinOpen)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_IMI_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinOpen, inOpen) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_IMI(startIdx, endIdx, inOpen, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inOpen); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inOpen); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_kama.c b/pecl/trader_kama.c new file mode 100644 index 0000000..d621e5d --- /dev/null +++ b/pecl/trader_kama.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_kama(array real [, int timePeriod]) + Kaufman Adaptive Moving Average */ +PHP_FUNCTION(trader_kama) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_KAMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_KAMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_linearreg.c b/pecl/trader_linearreg.c new file mode 100644 index 0000000..86135eb --- /dev/null +++ b/pecl/trader_linearreg.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_linearreg(array real [, int timePeriod]) + Linear Regression */ +PHP_FUNCTION(trader_linearreg) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_LINEARREG_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_LINEARREG(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_linearreg_angle.c b/pecl/trader_linearreg_angle.c new file mode 100644 index 0000000..cf8b627 --- /dev/null +++ b/pecl/trader_linearreg_angle.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_linearreg_angle(array real [, int timePeriod]) + Linear Regression Angle */ +PHP_FUNCTION(trader_linearreg_angle) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_LINEARREG_ANGLE_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_LINEARREG_ANGLE(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_linearreg_intercept.c b/pecl/trader_linearreg_intercept.c new file mode 100644 index 0000000..1870868 --- /dev/null +++ b/pecl/trader_linearreg_intercept.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_linearreg_intercept(array real [, int timePeriod]) + Linear Regression Intercept */ +PHP_FUNCTION(trader_linearreg_intercept) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_LINEARREG_INTERCEPT_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_LINEARREG_INTERCEPT(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_linearreg_slope.c b/pecl/trader_linearreg_slope.c new file mode 100644 index 0000000..18c9551 --- /dev/null +++ b/pecl/trader_linearreg_slope.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_linearreg_slope(array real [, int timePeriod]) + Linear Regression Slope */ +PHP_FUNCTION(trader_linearreg_slope) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_LINEARREG_SLOPE_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_LINEARREG_SLOPE(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ln.c b/pecl/trader_ln.c new file mode 100644 index 0000000..e36bcb2 --- /dev/null +++ b/pecl/trader_ln.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ln(array real) + Vector Log Natural */ +PHP_FUNCTION(trader_ln) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_LN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_LN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_log10.c b/pecl/trader_log10.c new file mode 100644 index 0000000..7fdb462 --- /dev/null +++ b/pecl/trader_log10.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_log10(array real) + Vector Log10 */ +PHP_FUNCTION(trader_log10) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_LOG10_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_LOG10(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ma.c b/pecl/trader_ma.c new file mode 100644 index 0000000..c1b5783 --- /dev/null +++ b/pecl/trader_ma.c @@ -0,0 +1,96 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ma(array real [, int timePeriod [, int mAType]]) + Moving average */ +PHP_FUNCTION(trader_ma) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1, optInMAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + Z_PARAM_LONG(optInMAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ll", &zinReal, &optInTimePeriod, &optInMAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInMAType) + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MA_Lookback((int)optInTimePeriod, (int)optInMAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MA(startIdx, endIdx, inReal, (int)optInTimePeriod, (int)optInMAType, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_macd.c b/pecl/trader_macd.c new file mode 100644 index 0000000..3f30c17 --- /dev/null +++ b/pecl/trader_macd.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_macd(array real [, int fastPeriod [, int slowPeriod [, int signalPeriod]]]) + Moving Average Convergence/Divergence */ +PHP_FUNCTION(trader_macd) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outMACD, *outMACDSignal, *outMACDHist; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastPeriod = 2, optInSlowPeriod = 2, optInSignalPeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastPeriod) + Z_PARAM_LONG(optInSlowPeriod) + Z_PARAM_LONG(optInSignalPeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|lll", &zinReal, &optInFastPeriod, &optInSlowPeriod, &optInSignalPeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInFastPeriod); + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInSlowPeriod); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInSignalPeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MACD_Lookback((int)optInFastPeriod, (int)optInSlowPeriod, (int)optInSignalPeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outMACD = emalloc(sizeof(double)*optimalOutAlloc); + outMACDSignal = emalloc(sizeof(double)*optimalOutAlloc); + outMACDHist = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MACD(startIdx, endIdx, inReal, (int)optInFastPeriod, (int)optInSlowPeriod, (int)optInSignalPeriod, &outBegIdx, &outNBElement, outMACD, outMACDSignal, outMACDHist); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outMACD); + efree(outMACDSignal); + efree(outMACDHist); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET3(outMACD, outMACDSignal, outMACDHist, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outMACD); + efree(outMACDSignal); + efree(outMACDHist); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_macdext.c b/pecl/trader_macdext.c new file mode 100644 index 0000000..e1b8d54 --- /dev/null +++ b/pecl/trader_macdext.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_macdext(array real [, int fastPeriod [, int fastMAType [, int slowPeriod [, int slowMAType [, int signalPeriod [, int signalMAType]]]]]]) + MACD with controllable MA type */ +PHP_FUNCTION(trader_macdext) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outMACD, *outMACDSignal, *outMACDHist; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastPeriod = 2, optInFastMAType = 0, optInSlowPeriod = 2, optInSlowMAType = 0, optInSignalPeriod = 1, optInSignalMAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 7) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastPeriod) + Z_PARAM_LONG(optInFastMAType) + Z_PARAM_LONG(optInSlowPeriod) + Z_PARAM_LONG(optInSlowMAType) + Z_PARAM_LONG(optInSignalPeriod) + Z_PARAM_LONG(optInSignalMAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|llllll", &zinReal, &optInFastPeriod, &optInFastMAType, &optInSlowPeriod, &optInSlowMAType, &optInSignalPeriod, &optInSignalMAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInFastMAType) +TRADER_CHECK_MA_TYPE(optInSlowMAType) +TRADER_CHECK_MA_TYPE(optInSignalMAType) + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInFastPeriod); + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInSlowPeriod); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInSignalPeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MACDEXT_Lookback((int)optInFastPeriod, (int)optInFastMAType, (int)optInSlowPeriod, (int)optInSlowMAType, (int)optInSignalPeriod, (int)optInSignalMAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outMACD = emalloc(sizeof(double)*optimalOutAlloc); + outMACDSignal = emalloc(sizeof(double)*optimalOutAlloc); + outMACDHist = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MACDEXT(startIdx, endIdx, inReal, (int)optInFastPeriod, (int)optInFastMAType, (int)optInSlowPeriod, (int)optInSlowMAType, (int)optInSignalPeriod, (int)optInSignalMAType, &outBegIdx, &outNBElement, outMACD, outMACDSignal, outMACDHist); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outMACD); + efree(outMACDSignal); + efree(outMACDHist); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET3(outMACD, outMACDSignal, outMACDHist, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outMACD); + efree(outMACDSignal); + efree(outMACDHist); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_macdfix.c b/pecl/trader_macdfix.c new file mode 100644 index 0000000..ded57aa --- /dev/null +++ b/pecl/trader_macdfix.c @@ -0,0 +1,101 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_macdfix(array real [, int signalPeriod]) + Moving Average Convergence/Divergence Fix 12/26 */ +PHP_FUNCTION(trader_macdfix) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outMACD, *outMACDSignal, *outMACDHist; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInSignalPeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInSignalPeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInSignalPeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInSignalPeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MACDFIX_Lookback((int)optInSignalPeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outMACD = emalloc(sizeof(double)*optimalOutAlloc); + outMACDSignal = emalloc(sizeof(double)*optimalOutAlloc); + outMACDHist = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MACDFIX(startIdx, endIdx, inReal, (int)optInSignalPeriod, &outBegIdx, &outNBElement, outMACD, outMACDSignal, outMACDHist); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outMACD); + efree(outMACDSignal); + efree(outMACDHist); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET3(outMACD, outMACDSignal, outMACDHist, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outMACD); + efree(outMACDSignal); + efree(outMACDHist); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_mama.c b/pecl/trader_mama.c new file mode 100644 index 0000000..ce5eed5 --- /dev/null +++ b/pecl/trader_mama.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_mama(array real [, float fastLimit [, float slowLimit]]) + MESA Adaptive Moving Average */ +PHP_FUNCTION(trader_mama) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outMAMA, *outFAMA; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + double optInFastLimit = 0.01, optInSlowLimit = 0.01; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInFastLimit) + Z_PARAM_DOUBLE(optInSlowLimit) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|dd", &zinReal, &optInFastLimit, &optInSlowLimit) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0.01, 0.99, optInFastLimit); + TRADER_DBL_SET_BOUNDABLE(0.01, 0.99, optInSlowLimit); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MAMA_Lookback(optInFastLimit, optInSlowLimit); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outMAMA = emalloc(sizeof(double)*optimalOutAlloc); + outFAMA = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MAMA(startIdx, endIdx, inReal, optInFastLimit, optInSlowLimit, &outBegIdx, &outNBElement, outMAMA, outFAMA); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outMAMA); + efree(outFAMA); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outMAMA, outFAMA, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outMAMA); + efree(outFAMA); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_mavp.c b/pecl/trader_mavp.c new file mode 100644 index 0000000..47f4278 --- /dev/null +++ b/pecl/trader_mavp.c @@ -0,0 +1,103 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_mavp(array real, array periods [, int minPeriod [, int maxPeriod [, int mAType]]]) + Moving average with variable period */ +PHP_FUNCTION(trader_mavp) +{ + int optimalOutAlloc, lookback; + zval *zinReal, *zinPeriods; + double *inReal, *inPeriods, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInMinPeriod = 2, optInMaxPeriod = 2, optInMAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 5) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_ARRAY(zinPeriods) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInMinPeriod) + Z_PARAM_LONG(optInMaxPeriod) + Z_PARAM_LONG(optInMAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|lll", &zinReal, &zinPeriods, &optInMinPeriod, &optInMaxPeriod, &optInMAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInMAType) + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInMinPeriod); + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInMaxPeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal)), + zend_hash_num_elements(Z_ARRVAL_P(zinPeriods))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MAVP_Lookback((int)optInMinPeriod, (int)optInMaxPeriod, (int)optInMAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + TRADER_DBL_ZARR_TO_ARR(zinPeriods, inPeriods) + + TRADER_G(last_error) = TA_MAVP(startIdx, endIdx, inReal, inPeriods, (int)optInMinPeriod, (int)optInMaxPeriod, (int)optInMAType, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(inPeriods); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(inPeriods); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_max.c b/pecl/trader_max.c new file mode 100644 index 0000000..8e76fa7 --- /dev/null +++ b/pecl/trader_max.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_max(array real [, int timePeriod]) + Highest value over a specified period */ +PHP_FUNCTION(trader_max) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MAX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MAX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_maxindex.c b/pecl/trader_maxindex.c new file mode 100644 index 0000000..9bb7744 --- /dev/null +++ b/pecl/trader_maxindex.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_maxindex(array real [, int timePeriod]) + Index of highest value over a specified period */ +PHP_FUNCTION(trader_maxindex) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MAXINDEX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MAXINDEX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_medprice.c b/pecl/trader_medprice.c new file mode 100644 index 0000000..b1e953b --- /dev/null +++ b/pecl/trader_medprice.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_medprice(array high, array low) + Median Price */ +PHP_FUNCTION(trader_medprice) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinHigh, &zinLow) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MEDPRICE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_MEDPRICE(startIdx, endIdx, inHigh, inLow, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_mfi.c b/pecl/trader_mfi.c new file mode 100644 index 0000000..8e5f204 --- /dev/null +++ b/pecl/trader_mfi.c @@ -0,0 +1,110 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_mfi(array high, array low, array close, array volume [, int timePeriod]) + Money Flow Index */ +PHP_FUNCTION(trader_mfi) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose, *zinVolume; + double *inHigh, *inLow, *inClose, *inVolume, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(4, 5) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_ARRAY(zinVolume) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaaa|l", &zinHigh, &zinLow, &zinClose, &zinVolume, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT4(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose)), + zend_hash_num_elements(Z_ARRVAL_P(zinVolume))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MFI_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + TRADER_DBL_ZARR_TO_ARR(zinVolume, inVolume) + + TRADER_G(last_error) = TA_MFI(startIdx, endIdx, inHigh, inLow, inClose, inVolume, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(inVolume); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(inVolume); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_midpoint.c b/pecl/trader_midpoint.c new file mode 100644 index 0000000..832f754 --- /dev/null +++ b/pecl/trader_midpoint.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_midpoint(array real [, int timePeriod]) + MidPoint over period */ +PHP_FUNCTION(trader_midpoint) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MIDPOINT_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MIDPOINT(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_midprice.c b/pecl/trader_midprice.c new file mode 100644 index 0000000..d86c36e --- /dev/null +++ b/pecl/trader_midprice.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_midprice(array high, array low [, int timePeriod]) + Midpoint Price over period */ +PHP_FUNCTION(trader_midprice) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinHigh, &zinLow, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MIDPRICE_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_MIDPRICE(startIdx, endIdx, inHigh, inLow, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_min.c b/pecl/trader_min.c new file mode 100644 index 0000000..3e1b950 --- /dev/null +++ b/pecl/trader_min.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_min(array real [, int timePeriod]) + Lowest value over a specified period */ +PHP_FUNCTION(trader_min) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MIN_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MIN(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_minindex.c b/pecl/trader_minindex.c new file mode 100644 index 0000000..1bc3feb --- /dev/null +++ b/pecl/trader_minindex.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_minindex(array real [, int timePeriod]) + Index of lowest value over a specified period */ +PHP_FUNCTION(trader_minindex) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MININDEX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outInteger = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MININDEX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outInteger); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outInteger); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outInteger); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_minmax.c b/pecl/trader_minmax.c new file mode 100644 index 0000000..6b96074 --- /dev/null +++ b/pecl/trader_minmax.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_minmax(array real [, int timePeriod]) + Lowest and highest values over a specified period */ +PHP_FUNCTION(trader_minmax) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outMin, *outMax; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MINMAX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outMin = emalloc(sizeof(double)*optimalOutAlloc); + outMax = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MINMAX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outMin, outMax); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outMin); + efree(outMax); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outMin, outMax, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outMin); + efree(outMax); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_minmaxindex.c b/pecl/trader_minmaxindex.c new file mode 100644 index 0000000..3035908 --- /dev/null +++ b/pecl/trader_minmaxindex.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_minmaxindex(array real [, int timePeriod]) + Indexes of lowest and highest values over a specified period */ +PHP_FUNCTION(trader_minmaxindex) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outMinIdx = 0, *outMaxIdx = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MINMAXINDEX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outMinIdx = emalloc(sizeof(double)*optimalOutAlloc); + outMaxIdx = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MINMAXINDEX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outMinIdx, outMaxIdx); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outMinIdx); + efree(outMaxIdx); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outMinIdx, outMaxIdx, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outMinIdx); + efree(outMaxIdx); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_minus_di.c b/pecl/trader_minus_di.c new file mode 100644 index 0000000..567dc7f --- /dev/null +++ b/pecl/trader_minus_di.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_minus_di(array high, array low, array close [, int timePeriod]) + Minus Directional Indicator */ +PHP_FUNCTION(trader_minus_di) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MINUS_DI_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_MINUS_DI(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_minus_dm.c b/pecl/trader_minus_dm.c new file mode 100644 index 0000000..0c6563b --- /dev/null +++ b/pecl/trader_minus_dm.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_minus_dm(array high, array low [, int timePeriod]) + Minus Directional Movement */ +PHP_FUNCTION(trader_minus_dm) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinHigh, &zinLow, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MINUS_DM_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_MINUS_DM(startIdx, endIdx, inHigh, inLow, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_mom.c b/pecl/trader_mom.c new file mode 100644 index 0000000..2693983 --- /dev/null +++ b/pecl/trader_mom.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_mom(array real [, int timePeriod]) + Momentum */ +PHP_FUNCTION(trader_mom) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MOM_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_MOM(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_mult.c b/pecl/trader_mult.c new file mode 100644 index 0000000..33c2348 --- /dev/null +++ b/pecl/trader_mult.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_mult(array real0, array real1) + Vector Arithmetic Mult */ +PHP_FUNCTION(trader_mult) +{ + int optimalOutAlloc, lookback; + zval *zinReal0, *zinReal1; + double *inReal0, *inReal1, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(zinReal0) + Z_PARAM_ARRAY(zinReal1) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal0, &zinReal1) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), + zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_MULT_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) + TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) + + TRADER_G(last_error) = TA_MULT(startIdx, endIdx, inReal0, inReal1, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal0); + efree(inReal1); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal0); + efree(inReal1); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_natr.c b/pecl/trader_natr.c new file mode 100644 index 0000000..ea7ddf4 --- /dev/null +++ b/pecl/trader_natr.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_natr(array high, array low, array close [, int timePeriod]) + Normalized Average True Range */ +PHP_FUNCTION(trader_natr) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_NATR_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_NATR(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_obv.c b/pecl/trader_obv.c new file mode 100644 index 0000000..ebba266 --- /dev/null +++ b/pecl/trader_obv.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_obv(array real, array volume) + On Balance Volume */ +PHP_FUNCTION(trader_obv) +{ + int optimalOutAlloc, lookback; + zval *zinReal, *zinVolume; + double *inReal, *inVolume, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_ARRAY(zinVolume) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal, &zinVolume) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal)), + zend_hash_num_elements(Z_ARRVAL_P(zinVolume))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_OBV_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + TRADER_DBL_ZARR_TO_ARR(zinVolume, inVolume) + + TRADER_G(last_error) = TA_OBV(startIdx, endIdx, inReal, inVolume, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(inVolume); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(inVolume); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_php_arginfo.h b/pecl/trader_php_arginfo.h new file mode 100644 index 0000000..25556b1 --- /dev/null +++ b/pecl/trader_php_arginfo.h @@ -0,0 +1,1041 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#ifndef TA_PHP_ARGINFO_H +#define TA_PHP_ARGINFO_H + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_accbands, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_acos, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ad, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_ARRAY_INFO(0, volume, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_add, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real0, 0) + ZEND_ARG_ARRAY_INFO(0, real1, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_adosc, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_ARRAY_INFO(0, volume, 0) + ZEND_ARG_INFO(0, fastPeriod) + ZEND_ARG_INFO(0, slowPeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_adx, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_adxr, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_apo, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, fastPeriod) + ZEND_ARG_INFO(0, slowPeriod) + ZEND_ARG_INFO(0, mAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_aroon, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_aroonosc, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_asin, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_atan, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_atr, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_avgprice, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_avgdev, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_bbands, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) + ZEND_ARG_INFO(0, nbDevUp) + ZEND_ARG_INFO(0, nbDevDn) + ZEND_ARG_INFO(0, mAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_beta, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real0, 0) + ZEND_ARG_ARRAY_INFO(0, real1, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_bop, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cci, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl2crows, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl3blackcrows, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl3inside, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl3linestrike, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl3outside, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl3starsinsouth, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdl3whitesoldiers, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlabandonedbaby, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdladvanceblock, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlbelthold, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlbreakaway, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlclosingmarubozu, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlconcealbabyswall, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlcounterattack, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdldarkcloudcover, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdldoji, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdldojistar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdldragonflydoji, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlengulfing, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdleveningdojistar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdleveningstar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlgapsidesidewhite, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlgravestonedoji, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlhammer, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlhangingman, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlharami, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlharamicross, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlhighwave, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlhikkake, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlhikkakemod, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlhomingpigeon, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlidentical3crows, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlinneck, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlinvertedhammer, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlkicking, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlkickingbylength, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlladderbottom, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdllongleggeddoji, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdllongline, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlmarubozu, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlmatchinglow, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlmathold, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlmorningdojistar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlmorningstar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, penetration) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlonneck, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlpiercing, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlrickshawman, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlrisefall3methods, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlseparatinglines, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlshootingstar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlshortline, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlspinningtop, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlstalledpattern, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlsticksandwich, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdltakuri, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdltasukigap, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlthrusting, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdltristar, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlunique3river, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlupsidegap2crows, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cdlxsidegap3methods, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ceil, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cmo, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_correl, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real0, 0) + ZEND_ARG_ARRAY_INFO(0, real1, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cos, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_cosh, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_dema, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_div, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real0, 0) + ZEND_ARG_ARRAY_INFO(0, real1, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_dx, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ema, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_exp, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_floor, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ht_dcperiod, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ht_dcphase, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ht_phasor, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ht_sine, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ht_trendline, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ht_trendmode, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_imi, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, open, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_kama, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_linearreg, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_linearreg_angle, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_linearreg_intercept, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_linearreg_slope, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ln, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_log10, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ma, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) + ZEND_ARG_INFO(0, mAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_macd, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, fastPeriod) + ZEND_ARG_INFO(0, slowPeriod) + ZEND_ARG_INFO(0, signalPeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_macdext, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, fastPeriod) + ZEND_ARG_INFO(0, fastMAType) + ZEND_ARG_INFO(0, slowPeriod) + ZEND_ARG_INFO(0, slowMAType) + ZEND_ARG_INFO(0, signalPeriod) + ZEND_ARG_INFO(0, signalMAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_macdfix, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, signalPeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_mama, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, fastLimit) + ZEND_ARG_INFO(0, slowLimit) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_mavp, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_ARRAY_INFO(0, periods, 0) + ZEND_ARG_INFO(0, minPeriod) + ZEND_ARG_INFO(0, maxPeriod) + ZEND_ARG_INFO(0, mAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_max, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_maxindex, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_medprice, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_mfi, 0, 0, 4) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_ARRAY_INFO(0, volume, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_midpoint, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_midprice, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_min, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_minindex, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_minmax, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_minmaxindex, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_minus_di, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_minus_dm, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_mom, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_mult, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real0, 0) + ZEND_ARG_ARRAY_INFO(0, real1, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_natr, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_obv, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_ARRAY_INFO(0, volume, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_plus_di, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_plus_dm, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ppo, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, fastPeriod) + ZEND_ARG_INFO(0, slowPeriod) + ZEND_ARG_INFO(0, mAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_roc, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_rocp, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_rocr, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_rocr100, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_rsi, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sar, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, acceleration) + ZEND_ARG_INFO(0, maximum) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sarext, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_INFO(0, startValue) + ZEND_ARG_INFO(0, offsetOnReverse) + ZEND_ARG_INFO(0, accelerationInitLong) + ZEND_ARG_INFO(0, accelerationLong) + ZEND_ARG_INFO(0, accelerationMaxLong) + ZEND_ARG_INFO(0, accelerationInitShort) + ZEND_ARG_INFO(0, accelerationShort) + ZEND_ARG_INFO(0, accelerationMaxShort) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sin, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sinh, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sma, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sqrt, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_stddev, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) + ZEND_ARG_INFO(0, nbDev) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_stoch, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, fastK_Period) + ZEND_ARG_INFO(0, slowK_Period) + ZEND_ARG_INFO(0, slowK_MAType) + ZEND_ARG_INFO(0, slowD_Period) + ZEND_ARG_INFO(0, slowD_MAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_stochf, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, fastK_Period) + ZEND_ARG_INFO(0, fastD_Period) + ZEND_ARG_INFO(0, fastD_MAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_stochrsi, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) + ZEND_ARG_INFO(0, fastK_Period) + ZEND_ARG_INFO(0, fastD_Period) + ZEND_ARG_INFO(0, fastD_MAType) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sub, 0, 0, 2) + ZEND_ARG_ARRAY_INFO(0, real0, 0) + ZEND_ARG_ARRAY_INFO(0, real1, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_sum, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_t3, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) + ZEND_ARG_INFO(0, vFactor) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_tan, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_tanh, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_tema, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_trange, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_trima, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_trix, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_tsf, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_typprice, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_ultosc, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod1) + ZEND_ARG_INFO(0, timePeriod2) + ZEND_ARG_INFO(0, timePeriod3) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_var, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) + ZEND_ARG_INFO(0, nbDev) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_wclprice, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_willr, 0, 0, 3) + ZEND_ARG_ARRAY_INFO(0, high, 0) + ZEND_ARG_ARRAY_INFO(0, low, 0) + ZEND_ARG_ARRAY_INFO(0, close, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(arg_info_trader_wma, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, real, 0) + ZEND_ARG_INFO(0, timePeriod) +ZEND_END_ARG_INFO(); + +#endif /* TA_PHP_ARGINFO_H */ + diff --git a/pecl/trader_php_arginfo.h.tpl b/pecl/trader_php_arginfo.h.tpl new file mode 100644 index 0000000..f3c4328 --- /dev/null +++ b/pecl/trader_php_arginfo.h.tpl @@ -0,0 +1,37 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#ifndef TA_PHP_ARGINFO_H +#define TA_PHP_ARGINFO_H + +HEADER_CONTENT + +#endif /* TA_PHP_ARGINFO_H */ + diff --git a/pecl/trader_php_fe.h b/pecl/trader_php_fe.h new file mode 100644 index 0000000..ac73dcf --- /dev/null +++ b/pecl/trader_php_fe.h @@ -0,0 +1,199 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#ifndef TA_PHP_FE_H +#define TA_PHP_FE_H +const zend_function_entry ta_functions[] = { + PHP_FE(trader_accbands, arg_info_trader_accbands) + PHP_FE(trader_acos, arg_info_trader_acos) + PHP_FE(trader_ad, arg_info_trader_ad) + PHP_FE(trader_add, arg_info_trader_add) + PHP_FE(trader_adosc, arg_info_trader_adosc) + PHP_FE(trader_adx, arg_info_trader_adx) + PHP_FE(trader_adxr, arg_info_trader_adxr) + PHP_FE(trader_apo, arg_info_trader_apo) + PHP_FE(trader_aroon, arg_info_trader_aroon) + PHP_FE(trader_aroonosc, arg_info_trader_aroonosc) + PHP_FE(trader_asin, arg_info_trader_asin) + PHP_FE(trader_atan, arg_info_trader_atan) + PHP_FE(trader_atr, arg_info_trader_atr) + PHP_FE(trader_avgprice, arg_info_trader_avgprice) + PHP_FE(trader_avgdev, arg_info_trader_avgdev) + PHP_FE(trader_bbands, arg_info_trader_bbands) + PHP_FE(trader_beta, arg_info_trader_beta) + PHP_FE(trader_bop, arg_info_trader_bop) + PHP_FE(trader_cci, arg_info_trader_cci) + PHP_FE(trader_cdl2crows, arg_info_trader_cdl2crows) + PHP_FE(trader_cdl3blackcrows, arg_info_trader_cdl3blackcrows) + PHP_FE(trader_cdl3inside, arg_info_trader_cdl3inside) + PHP_FE(trader_cdl3linestrike, arg_info_trader_cdl3linestrike) + PHP_FE(trader_cdl3outside, arg_info_trader_cdl3outside) + PHP_FE(trader_cdl3starsinsouth, arg_info_trader_cdl3starsinsouth) + PHP_FE(trader_cdl3whitesoldiers, arg_info_trader_cdl3whitesoldiers) + PHP_FE(trader_cdlabandonedbaby, arg_info_trader_cdlabandonedbaby) + PHP_FE(trader_cdladvanceblock, arg_info_trader_cdladvanceblock) + PHP_FE(trader_cdlbelthold, arg_info_trader_cdlbelthold) + PHP_FE(trader_cdlbreakaway, arg_info_trader_cdlbreakaway) + PHP_FE(trader_cdlclosingmarubozu, arg_info_trader_cdlclosingmarubozu) + PHP_FE(trader_cdlconcealbabyswall, arg_info_trader_cdlconcealbabyswall) + PHP_FE(trader_cdlcounterattack, arg_info_trader_cdlcounterattack) + PHP_FE(trader_cdldarkcloudcover, arg_info_trader_cdldarkcloudcover) + PHP_FE(trader_cdldoji, arg_info_trader_cdldoji) + PHP_FE(trader_cdldojistar, arg_info_trader_cdldojistar) + PHP_FE(trader_cdldragonflydoji, arg_info_trader_cdldragonflydoji) + PHP_FE(trader_cdlengulfing, arg_info_trader_cdlengulfing) + PHP_FE(trader_cdleveningdojistar, arg_info_trader_cdleveningdojistar) + PHP_FE(trader_cdleveningstar, arg_info_trader_cdleveningstar) + PHP_FE(trader_cdlgapsidesidewhite, arg_info_trader_cdlgapsidesidewhite) + PHP_FE(trader_cdlgravestonedoji, arg_info_trader_cdlgravestonedoji) + PHP_FE(trader_cdlhammer, arg_info_trader_cdlhammer) + PHP_FE(trader_cdlhangingman, arg_info_trader_cdlhangingman) + PHP_FE(trader_cdlharami, arg_info_trader_cdlharami) + PHP_FE(trader_cdlharamicross, arg_info_trader_cdlharamicross) + PHP_FE(trader_cdlhighwave, arg_info_trader_cdlhighwave) + PHP_FE(trader_cdlhikkake, arg_info_trader_cdlhikkake) + PHP_FE(trader_cdlhikkakemod, arg_info_trader_cdlhikkakemod) + PHP_FE(trader_cdlhomingpigeon, arg_info_trader_cdlhomingpigeon) + PHP_FE(trader_cdlidentical3crows, arg_info_trader_cdlidentical3crows) + PHP_FE(trader_cdlinneck, arg_info_trader_cdlinneck) + PHP_FE(trader_cdlinvertedhammer, arg_info_trader_cdlinvertedhammer) + PHP_FE(trader_cdlkicking, arg_info_trader_cdlkicking) + PHP_FE(trader_cdlkickingbylength, arg_info_trader_cdlkickingbylength) + PHP_FE(trader_cdlladderbottom, arg_info_trader_cdlladderbottom) + PHP_FE(trader_cdllongleggeddoji, arg_info_trader_cdllongleggeddoji) + PHP_FE(trader_cdllongline, arg_info_trader_cdllongline) + PHP_FE(trader_cdlmarubozu, arg_info_trader_cdlmarubozu) + PHP_FE(trader_cdlmatchinglow, arg_info_trader_cdlmatchinglow) + PHP_FE(trader_cdlmathold, arg_info_trader_cdlmathold) + PHP_FE(trader_cdlmorningdojistar, arg_info_trader_cdlmorningdojistar) + PHP_FE(trader_cdlmorningstar, arg_info_trader_cdlmorningstar) + PHP_FE(trader_cdlonneck, arg_info_trader_cdlonneck) + PHP_FE(trader_cdlpiercing, arg_info_trader_cdlpiercing) + PHP_FE(trader_cdlrickshawman, arg_info_trader_cdlrickshawman) + PHP_FE(trader_cdlrisefall3methods, arg_info_trader_cdlrisefall3methods) + PHP_FE(trader_cdlseparatinglines, arg_info_trader_cdlseparatinglines) + PHP_FE(trader_cdlshootingstar, arg_info_trader_cdlshootingstar) + PHP_FE(trader_cdlshortline, arg_info_trader_cdlshortline) + PHP_FE(trader_cdlspinningtop, arg_info_trader_cdlspinningtop) + PHP_FE(trader_cdlstalledpattern, arg_info_trader_cdlstalledpattern) + PHP_FE(trader_cdlsticksandwich, arg_info_trader_cdlsticksandwich) + PHP_FE(trader_cdltakuri, arg_info_trader_cdltakuri) + PHP_FE(trader_cdltasukigap, arg_info_trader_cdltasukigap) + PHP_FE(trader_cdlthrusting, arg_info_trader_cdlthrusting) + PHP_FE(trader_cdltristar, arg_info_trader_cdltristar) + PHP_FE(trader_cdlunique3river, arg_info_trader_cdlunique3river) + PHP_FE(trader_cdlupsidegap2crows, arg_info_trader_cdlupsidegap2crows) + PHP_FE(trader_cdlxsidegap3methods, arg_info_trader_cdlxsidegap3methods) + PHP_FE(trader_ceil, arg_info_trader_ceil) + PHP_FE(trader_cmo, arg_info_trader_cmo) + PHP_FE(trader_correl, arg_info_trader_correl) + PHP_FE(trader_cos, arg_info_trader_cos) + PHP_FE(trader_cosh, arg_info_trader_cosh) + PHP_FE(trader_dema, arg_info_trader_dema) + PHP_FE(trader_div, arg_info_trader_div) + PHP_FE(trader_dx, arg_info_trader_dx) + PHP_FE(trader_ema, arg_info_trader_ema) + PHP_FE(trader_exp, arg_info_trader_exp) + PHP_FE(trader_floor, arg_info_trader_floor) + PHP_FE(trader_ht_dcperiod, arg_info_trader_ht_dcperiod) + PHP_FE(trader_ht_dcphase, arg_info_trader_ht_dcphase) + PHP_FE(trader_ht_phasor, arg_info_trader_ht_phasor) + PHP_FE(trader_ht_sine, arg_info_trader_ht_sine) + PHP_FE(trader_ht_trendline, arg_info_trader_ht_trendline) + PHP_FE(trader_ht_trendmode, arg_info_trader_ht_trendmode) + PHP_FE(trader_imi, arg_info_trader_imi) + PHP_FE(trader_kama, arg_info_trader_kama) + PHP_FE(trader_linearreg, arg_info_trader_linearreg) + PHP_FE(trader_linearreg_angle, arg_info_trader_linearreg_angle) + PHP_FE(trader_linearreg_intercept, arg_info_trader_linearreg_intercept) + PHP_FE(trader_linearreg_slope, arg_info_trader_linearreg_slope) + PHP_FE(trader_ln, arg_info_trader_ln) + PHP_FE(trader_log10, arg_info_trader_log10) + PHP_FE(trader_ma, arg_info_trader_ma) + PHP_FE(trader_macd, arg_info_trader_macd) + PHP_FE(trader_macdext, arg_info_trader_macdext) + PHP_FE(trader_macdfix, arg_info_trader_macdfix) + PHP_FE(trader_mama, arg_info_trader_mama) + PHP_FE(trader_mavp, arg_info_trader_mavp) + PHP_FE(trader_max, arg_info_trader_max) + PHP_FE(trader_maxindex, arg_info_trader_maxindex) + PHP_FE(trader_medprice, arg_info_trader_medprice) + PHP_FE(trader_mfi, arg_info_trader_mfi) + PHP_FE(trader_midpoint, arg_info_trader_midpoint) + PHP_FE(trader_midprice, arg_info_trader_midprice) + PHP_FE(trader_min, arg_info_trader_min) + PHP_FE(trader_minindex, arg_info_trader_minindex) + PHP_FE(trader_minmax, arg_info_trader_minmax) + PHP_FE(trader_minmaxindex, arg_info_trader_minmaxindex) + PHP_FE(trader_minus_di, arg_info_trader_minus_di) + PHP_FE(trader_minus_dm, arg_info_trader_minus_dm) + PHP_FE(trader_mom, arg_info_trader_mom) + PHP_FE(trader_mult, arg_info_trader_mult) + PHP_FE(trader_natr, arg_info_trader_natr) + PHP_FE(trader_obv, arg_info_trader_obv) + PHP_FE(trader_plus_di, arg_info_trader_plus_di) + PHP_FE(trader_plus_dm, arg_info_trader_plus_dm) + PHP_FE(trader_ppo, arg_info_trader_ppo) + PHP_FE(trader_roc, arg_info_trader_roc) + PHP_FE(trader_rocp, arg_info_trader_rocp) + PHP_FE(trader_rocr, arg_info_trader_rocr) + PHP_FE(trader_rocr100, arg_info_trader_rocr100) + PHP_FE(trader_rsi, arg_info_trader_rsi) + PHP_FE(trader_sar, arg_info_trader_sar) + PHP_FE(trader_sarext, arg_info_trader_sarext) + PHP_FE(trader_sin, arg_info_trader_sin) + PHP_FE(trader_sinh, arg_info_trader_sinh) + PHP_FE(trader_sma, arg_info_trader_sma) + PHP_FE(trader_sqrt, arg_info_trader_sqrt) + PHP_FE(trader_stddev, arg_info_trader_stddev) + PHP_FE(trader_stoch, arg_info_trader_stoch) + PHP_FE(trader_stochf, arg_info_trader_stochf) + PHP_FE(trader_stochrsi, arg_info_trader_stochrsi) + PHP_FE(trader_sub, arg_info_trader_sub) + PHP_FE(trader_sum, arg_info_trader_sum) + PHP_FE(trader_t3, arg_info_trader_t3) + PHP_FE(trader_tan, arg_info_trader_tan) + PHP_FE(trader_tanh, arg_info_trader_tanh) + PHP_FE(trader_tema, arg_info_trader_tema) + PHP_FE(trader_trange, arg_info_trader_trange) + PHP_FE(trader_trima, arg_info_trader_trima) + PHP_FE(trader_trix, arg_info_trader_trix) + PHP_FE(trader_tsf, arg_info_trader_tsf) + PHP_FE(trader_typprice, arg_info_trader_typprice) + PHP_FE(trader_ultosc, arg_info_trader_ultosc) + PHP_FE(trader_var, arg_info_trader_var) + PHP_FE(trader_wclprice, arg_info_trader_wclprice) + PHP_FE(trader_willr, arg_info_trader_willr) + PHP_FE(trader_wma, arg_info_trader_wma) + PHP_FE_END +}; + +#endif /* TA_PHP_FE_H */ + diff --git a/pecl/trader_php_fe.h.tpl b/pecl/trader_php_fe.h.tpl new file mode 100644 index 0000000..7a75af0 --- /dev/null +++ b/pecl/trader_php_fe.h.tpl @@ -0,0 +1,39 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#ifndef TA_PHP_FE_H +#define TA_PHP_FE_H +const zend_function_entry ta_functions[] = { +HEADER_CONTENT + PHP_FE_END +}; + +#endif /* TA_PHP_FE_H */ + diff --git a/pecl/trader_php_func.h b/pecl/trader_php_func.h new file mode 100644 index 0000000..c166105 --- /dev/null +++ b/pecl/trader_php_func.h @@ -0,0 +1,197 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#ifndef TA_PHP_FUNC_H +#define TA_PHP_FUNC_H + +PHP_FUNCTION(trader_accbands); +PHP_FUNCTION(trader_acos); +PHP_FUNCTION(trader_ad); +PHP_FUNCTION(trader_add); +PHP_FUNCTION(trader_adosc); +PHP_FUNCTION(trader_adx); +PHP_FUNCTION(trader_adxr); +PHP_FUNCTION(trader_apo); +PHP_FUNCTION(trader_aroon); +PHP_FUNCTION(trader_aroonosc); +PHP_FUNCTION(trader_asin); +PHP_FUNCTION(trader_atan); +PHP_FUNCTION(trader_atr); +PHP_FUNCTION(trader_avgprice); +PHP_FUNCTION(trader_avgdev); +PHP_FUNCTION(trader_bbands); +PHP_FUNCTION(trader_beta); +PHP_FUNCTION(trader_bop); +PHP_FUNCTION(trader_cci); +PHP_FUNCTION(trader_cdl2crows); +PHP_FUNCTION(trader_cdl3blackcrows); +PHP_FUNCTION(trader_cdl3inside); +PHP_FUNCTION(trader_cdl3linestrike); +PHP_FUNCTION(trader_cdl3outside); +PHP_FUNCTION(trader_cdl3starsinsouth); +PHP_FUNCTION(trader_cdl3whitesoldiers); +PHP_FUNCTION(trader_cdlabandonedbaby); +PHP_FUNCTION(trader_cdladvanceblock); +PHP_FUNCTION(trader_cdlbelthold); +PHP_FUNCTION(trader_cdlbreakaway); +PHP_FUNCTION(trader_cdlclosingmarubozu); +PHP_FUNCTION(trader_cdlconcealbabyswall); +PHP_FUNCTION(trader_cdlcounterattack); +PHP_FUNCTION(trader_cdldarkcloudcover); +PHP_FUNCTION(trader_cdldoji); +PHP_FUNCTION(trader_cdldojistar); +PHP_FUNCTION(trader_cdldragonflydoji); +PHP_FUNCTION(trader_cdlengulfing); +PHP_FUNCTION(trader_cdleveningdojistar); +PHP_FUNCTION(trader_cdleveningstar); +PHP_FUNCTION(trader_cdlgapsidesidewhite); +PHP_FUNCTION(trader_cdlgravestonedoji); +PHP_FUNCTION(trader_cdlhammer); +PHP_FUNCTION(trader_cdlhangingman); +PHP_FUNCTION(trader_cdlharami); +PHP_FUNCTION(trader_cdlharamicross); +PHP_FUNCTION(trader_cdlhighwave); +PHP_FUNCTION(trader_cdlhikkake); +PHP_FUNCTION(trader_cdlhikkakemod); +PHP_FUNCTION(trader_cdlhomingpigeon); +PHP_FUNCTION(trader_cdlidentical3crows); +PHP_FUNCTION(trader_cdlinneck); +PHP_FUNCTION(trader_cdlinvertedhammer); +PHP_FUNCTION(trader_cdlkicking); +PHP_FUNCTION(trader_cdlkickingbylength); +PHP_FUNCTION(trader_cdlladderbottom); +PHP_FUNCTION(trader_cdllongleggeddoji); +PHP_FUNCTION(trader_cdllongline); +PHP_FUNCTION(trader_cdlmarubozu); +PHP_FUNCTION(trader_cdlmatchinglow); +PHP_FUNCTION(trader_cdlmathold); +PHP_FUNCTION(trader_cdlmorningdojistar); +PHP_FUNCTION(trader_cdlmorningstar); +PHP_FUNCTION(trader_cdlonneck); +PHP_FUNCTION(trader_cdlpiercing); +PHP_FUNCTION(trader_cdlrickshawman); +PHP_FUNCTION(trader_cdlrisefall3methods); +PHP_FUNCTION(trader_cdlseparatinglines); +PHP_FUNCTION(trader_cdlshootingstar); +PHP_FUNCTION(trader_cdlshortline); +PHP_FUNCTION(trader_cdlspinningtop); +PHP_FUNCTION(trader_cdlstalledpattern); +PHP_FUNCTION(trader_cdlsticksandwich); +PHP_FUNCTION(trader_cdltakuri); +PHP_FUNCTION(trader_cdltasukigap); +PHP_FUNCTION(trader_cdlthrusting); +PHP_FUNCTION(trader_cdltristar); +PHP_FUNCTION(trader_cdlunique3river); +PHP_FUNCTION(trader_cdlupsidegap2crows); +PHP_FUNCTION(trader_cdlxsidegap3methods); +PHP_FUNCTION(trader_ceil); +PHP_FUNCTION(trader_cmo); +PHP_FUNCTION(trader_correl); +PHP_FUNCTION(trader_cos); +PHP_FUNCTION(trader_cosh); +PHP_FUNCTION(trader_dema); +PHP_FUNCTION(trader_div); +PHP_FUNCTION(trader_dx); +PHP_FUNCTION(trader_ema); +PHP_FUNCTION(trader_exp); +PHP_FUNCTION(trader_floor); +PHP_FUNCTION(trader_ht_dcperiod); +PHP_FUNCTION(trader_ht_dcphase); +PHP_FUNCTION(trader_ht_phasor); +PHP_FUNCTION(trader_ht_sine); +PHP_FUNCTION(trader_ht_trendline); +PHP_FUNCTION(trader_ht_trendmode); +PHP_FUNCTION(trader_imi); +PHP_FUNCTION(trader_kama); +PHP_FUNCTION(trader_linearreg); +PHP_FUNCTION(trader_linearreg_angle); +PHP_FUNCTION(trader_linearreg_intercept); +PHP_FUNCTION(trader_linearreg_slope); +PHP_FUNCTION(trader_ln); +PHP_FUNCTION(trader_log10); +PHP_FUNCTION(trader_ma); +PHP_FUNCTION(trader_macd); +PHP_FUNCTION(trader_macdext); +PHP_FUNCTION(trader_macdfix); +PHP_FUNCTION(trader_mama); +PHP_FUNCTION(trader_mavp); +PHP_FUNCTION(trader_max); +PHP_FUNCTION(trader_maxindex); +PHP_FUNCTION(trader_medprice); +PHP_FUNCTION(trader_mfi); +PHP_FUNCTION(trader_midpoint); +PHP_FUNCTION(trader_midprice); +PHP_FUNCTION(trader_min); +PHP_FUNCTION(trader_minindex); +PHP_FUNCTION(trader_minmax); +PHP_FUNCTION(trader_minmaxindex); +PHP_FUNCTION(trader_minus_di); +PHP_FUNCTION(trader_minus_dm); +PHP_FUNCTION(trader_mom); +PHP_FUNCTION(trader_mult); +PHP_FUNCTION(trader_natr); +PHP_FUNCTION(trader_obv); +PHP_FUNCTION(trader_plus_di); +PHP_FUNCTION(trader_plus_dm); +PHP_FUNCTION(trader_ppo); +PHP_FUNCTION(trader_roc); +PHP_FUNCTION(trader_rocp); +PHP_FUNCTION(trader_rocr); +PHP_FUNCTION(trader_rocr100); +PHP_FUNCTION(trader_rsi); +PHP_FUNCTION(trader_sar); +PHP_FUNCTION(trader_sarext); +PHP_FUNCTION(trader_sin); +PHP_FUNCTION(trader_sinh); +PHP_FUNCTION(trader_sma); +PHP_FUNCTION(trader_sqrt); +PHP_FUNCTION(trader_stddev); +PHP_FUNCTION(trader_stoch); +PHP_FUNCTION(trader_stochf); +PHP_FUNCTION(trader_stochrsi); +PHP_FUNCTION(trader_sub); +PHP_FUNCTION(trader_sum); +PHP_FUNCTION(trader_t3); +PHP_FUNCTION(trader_tan); +PHP_FUNCTION(trader_tanh); +PHP_FUNCTION(trader_tema); +PHP_FUNCTION(trader_trange); +PHP_FUNCTION(trader_trima); +PHP_FUNCTION(trader_trix); +PHP_FUNCTION(trader_tsf); +PHP_FUNCTION(trader_typprice); +PHP_FUNCTION(trader_ultosc); +PHP_FUNCTION(trader_var); +PHP_FUNCTION(trader_wclprice); +PHP_FUNCTION(trader_willr); +PHP_FUNCTION(trader_wma); + +#endif /* TA_PHP_FUNC_H */ + diff --git a/pecl/trader_php_func.h.tpl b/pecl/trader_php_func.h.tpl new file mode 100644 index 0000000..01406e5 --- /dev/null +++ b/pecl/trader_php_func.h.tpl @@ -0,0 +1,37 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#ifndef TA_PHP_FUNC_H +#define TA_PHP_FUNC_H + +HEADER_CONTENT + +#endif /* TA_PHP_FUNC_H */ + diff --git a/pecl/trader_plus_di.c b/pecl/trader_plus_di.c new file mode 100644 index 0000000..0b704f9 --- /dev/null +++ b/pecl/trader_plus_di.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_plus_di(array high, array low, array close [, int timePeriod]) + Plus Directional Indicator */ +PHP_FUNCTION(trader_plus_di) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_PLUS_DI_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_PLUS_DI(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_plus_dm.c b/pecl/trader_plus_dm.c new file mode 100644 index 0000000..1673204 --- /dev/null +++ b/pecl/trader_plus_dm.c @@ -0,0 +1,100 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_plus_dm(array high, array low [, int timePeriod]) + Plus Directional Movement */ +PHP_FUNCTION(trader_plus_dm) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|l", &zinHigh, &zinLow, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_PLUS_DM_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_PLUS_DM(startIdx, endIdx, inHigh, inLow, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ppo.c b/pecl/trader_ppo.c new file mode 100644 index 0000000..3aacd00 --- /dev/null +++ b/pecl/trader_ppo.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ppo(array real [, int fastPeriod [, int slowPeriod [, int mAType]]]) + Percentage Price Oscillator */ +PHP_FUNCTION(trader_ppo) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastPeriod = 2, optInSlowPeriod = 2, optInMAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastPeriod) + Z_PARAM_LONG(optInSlowPeriod) + Z_PARAM_LONG(optInMAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|lll", &zinReal, &optInFastPeriod, &optInSlowPeriod, &optInMAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInMAType) + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInFastPeriod); + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInSlowPeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_PPO_Lookback((int)optInFastPeriod, (int)optInSlowPeriod, (int)optInMAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_PPO(startIdx, endIdx, inReal, (int)optInFastPeriod, (int)optInSlowPeriod, (int)optInMAType, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_roc.c b/pecl/trader_roc.c new file mode 100644 index 0000000..d2e6d2c --- /dev/null +++ b/pecl/trader_roc.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_roc(array real [, int timePeriod]) + Rate of change : ((price/prevPrice)-1)*100 */ +PHP_FUNCTION(trader_roc) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ROC_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ROC(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_rocp.c b/pecl/trader_rocp.c new file mode 100644 index 0000000..a5e7d85 --- /dev/null +++ b/pecl/trader_rocp.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_rocp(array real [, int timePeriod]) + Rate of change Percentage: (price-prevPrice)/prevPrice */ +PHP_FUNCTION(trader_rocp) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ROCP_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ROCP(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_rocr.c b/pecl/trader_rocr.c new file mode 100644 index 0000000..1938ad3 --- /dev/null +++ b/pecl/trader_rocr.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_rocr(array real [, int timePeriod]) + Rate of change ratio: (price/prevPrice) */ +PHP_FUNCTION(trader_rocr) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ROCR_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ROCR(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_rocr100.c b/pecl/trader_rocr100.c new file mode 100644 index 0000000..7cb9c79 --- /dev/null +++ b/pecl/trader_rocr100.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_rocr100(array real [, int timePeriod]) + Rate of change ratio 100 scale: (price/prevPrice)*100 */ +PHP_FUNCTION(trader_rocr100) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ROCR100_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_ROCR100(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_rsi.c b/pecl/trader_rsi.c new file mode 100644 index 0000000..80fcb10 --- /dev/null +++ b/pecl/trader_rsi.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_rsi(array real [, int timePeriod]) + Relative Strength Index */ +PHP_FUNCTION(trader_rsi) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_RSI_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_RSI(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sar.c b/pecl/trader_sar.c new file mode 100644 index 0000000..696af51 --- /dev/null +++ b/pecl/trader_sar.c @@ -0,0 +1,102 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sar(array high, array low [, float acceleration [, float maximum]]) + Parabolic SAR */ +PHP_FUNCTION(trader_sar) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + double optInAcceleration = 0, optInMaximum = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInAcceleration) + Z_PARAM_DOUBLE(optInMaximum) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|dd", &zinHigh, &zinLow, &optInAcceleration, &optInMaximum) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAcceleration); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInMaximum); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SAR_Lookback(optInAcceleration, optInMaximum); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_SAR(startIdx, endIdx, inHigh, inLow, optInAcceleration, optInMaximum, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sarext.c b/pecl/trader_sarext.c new file mode 100644 index 0000000..fdb44a7 --- /dev/null +++ b/pecl/trader_sarext.c @@ -0,0 +1,114 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sarext(array high, array low [, float startValue [, float offsetOnReverse [, float accelerationInitLong [, float accelerationLong [, float accelerationMaxLong [, float accelerationInitShort [, float accelerationShort [, float accelerationMaxShort]]]]]]]]) + Parabolic SAR - Extended */ +PHP_FUNCTION(trader_sarext) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow; + double *inHigh, *inLow, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + double optInStartValue = TA_REAL_MIN, optInOffsetOnReverse = 0, optInAccelerationInitLong = 0, optInAccelerationLong = 0, optInAccelerationMaxLong = 0, optInAccelerationInitShort = 0, optInAccelerationShort = 0, optInAccelerationMaxShort = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 10) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_OPTIONAL + Z_PARAM_DOUBLE(optInStartValue) + Z_PARAM_DOUBLE(optInOffsetOnReverse) + Z_PARAM_DOUBLE(optInAccelerationInitLong) + Z_PARAM_DOUBLE(optInAccelerationLong) + Z_PARAM_DOUBLE(optInAccelerationMaxLong) + Z_PARAM_DOUBLE(optInAccelerationInitShort) + Z_PARAM_DOUBLE(optInAccelerationShort) + Z_PARAM_DOUBLE(optInAccelerationMaxShort) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa|dddddddd", &zinHigh, &zinLow, &optInStartValue, &optInOffsetOnReverse, &optInAccelerationInitLong, &optInAccelerationLong, &optInAccelerationMaxLong, &optInAccelerationInitShort, &optInAccelerationShort, &optInAccelerationMaxShort) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_DBL_SET_BOUNDABLE(TA_REAL_MIN, TA_REAL_MAX, optInStartValue); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInOffsetOnReverse); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAccelerationInitLong); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAccelerationLong); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAccelerationMaxLong); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAccelerationInitShort); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAccelerationShort); + TRADER_DBL_SET_BOUNDABLE(0, TA_REAL_MAX, optInAccelerationMaxShort); + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SAREXT_Lookback(optInStartValue, optInOffsetOnReverse, optInAccelerationInitLong, optInAccelerationLong, optInAccelerationMaxLong, optInAccelerationInitShort, optInAccelerationShort, optInAccelerationMaxShort); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + + TRADER_G(last_error) = TA_SAREXT(startIdx, endIdx, inHigh, inLow, optInStartValue, optInOffsetOnReverse, optInAccelerationInitLong, optInAccelerationLong, optInAccelerationMaxLong, optInAccelerationInitShort, optInAccelerationShort, optInAccelerationMaxShort, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sin.c b/pecl/trader_sin.c new file mode 100644 index 0000000..0b69d76 --- /dev/null +++ b/pecl/trader_sin.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sin(array real) + Vector Trigonometric Sin */ +PHP_FUNCTION(trader_sin) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SIN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_SIN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sinh.c b/pecl/trader_sinh.c new file mode 100644 index 0000000..90aac1a --- /dev/null +++ b/pecl/trader_sinh.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sinh(array real) + Vector Trigonometric Sinh */ +PHP_FUNCTION(trader_sinh) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SINH_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_SINH(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sma.c b/pecl/trader_sma.c new file mode 100644 index 0000000..e27c515 --- /dev/null +++ b/pecl/trader_sma.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sma(array real [, int timePeriod]) + Simple Moving Average */ +PHP_FUNCTION(trader_sma) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_SMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sqrt.c b/pecl/trader_sqrt.c new file mode 100644 index 0000000..de64f34 --- /dev/null +++ b/pecl/trader_sqrt.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sqrt(array real) + Vector Square Root */ +PHP_FUNCTION(trader_sqrt) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SQRT_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_SQRT(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_stddev.c b/pecl/trader_stddev.c new file mode 100644 index 0000000..676c4c4 --- /dev/null +++ b/pecl/trader_stddev.c @@ -0,0 +1,97 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_stddev(array real [, int timePeriod [, float nbDev]]) + Standard Deviation */ +PHP_FUNCTION(trader_stddev) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + double optInNbDev = TA_REAL_MIN; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + Z_PARAM_DOUBLE(optInNbDev) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ld", &zinReal, &optInTimePeriod, &optInNbDev) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + TRADER_DBL_SET_BOUNDABLE(TA_REAL_MIN, TA_REAL_MAX, optInNbDev); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_STDDEV_Lookback((int)optInTimePeriod, optInNbDev); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_STDDEV(startIdx, endIdx, inReal, (int)optInTimePeriod, optInNbDev, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_stoch.c b/pecl/trader_stoch.c new file mode 100644 index 0000000..9063410 --- /dev/null +++ b/pecl/trader_stoch.c @@ -0,0 +1,115 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_stoch(array high, array low, array close [, int fastK_Period [, int slowK_Period [, int slowK_MAType [, int slowD_Period [, int slowD_MAType]]]]]) + Stochastic */ +PHP_FUNCTION(trader_stoch) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outSlowK, *outSlowD; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastK_Period = 1, optInSlowK_Period = 1, optInSlowK_MAType = 0, optInSlowD_Period = 1, optInSlowD_MAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 8) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastK_Period) + Z_PARAM_LONG(optInSlowK_Period) + Z_PARAM_LONG(optInSlowK_MAType) + Z_PARAM_LONG(optInSlowD_Period) + Z_PARAM_LONG(optInSlowD_MAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|lllll", &zinHigh, &zinLow, &zinClose, &optInFastK_Period, &optInSlowK_Period, &optInSlowK_MAType, &optInSlowD_Period, &optInSlowD_MAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInSlowK_MAType) +TRADER_CHECK_MA_TYPE(optInSlowD_MAType) + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInFastK_Period); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInSlowK_Period); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInSlowD_Period); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_STOCH_Lookback((int)optInFastK_Period, (int)optInSlowK_Period, (int)optInSlowK_MAType, (int)optInSlowD_Period, (int)optInSlowD_MAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outSlowK = emalloc(sizeof(double)*optimalOutAlloc); + outSlowD = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_STOCH(startIdx, endIdx, inHigh, inLow, inClose, (int)optInFastK_Period, (int)optInSlowK_Period, (int)optInSlowK_MAType, (int)optInSlowD_Period, (int)optInSlowD_MAType, &outBegIdx, &outNBElement, outSlowK, outSlowD); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outSlowK); + efree(outSlowD); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outSlowK, outSlowD, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outSlowK); + efree(outSlowD); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_stochf.c b/pecl/trader_stochf.c new file mode 100644 index 0000000..cf912b7 --- /dev/null +++ b/pecl/trader_stochf.c @@ -0,0 +1,111 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_stochf(array high, array low, array close [, int fastK_Period [, int fastD_Period [, int fastD_MAType]]]) + Stochastic Fast */ +PHP_FUNCTION(trader_stochf) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outFastK, *outFastD; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInFastK_Period = 1, optInFastD_Period = 1, optInFastD_MAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 6) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInFastK_Period) + Z_PARAM_LONG(optInFastD_Period) + Z_PARAM_LONG(optInFastD_MAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|lll", &zinHigh, &zinLow, &zinClose, &optInFastK_Period, &optInFastD_Period, &optInFastD_MAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInFastD_MAType) + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInFastK_Period); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInFastD_Period); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_STOCHF_Lookback((int)optInFastK_Period, (int)optInFastD_Period, (int)optInFastD_MAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outFastK = emalloc(sizeof(double)*optimalOutAlloc); + outFastD = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_STOCHF(startIdx, endIdx, inHigh, inLow, inClose, (int)optInFastK_Period, (int)optInFastD_Period, (int)optInFastD_MAType, &outBegIdx, &outNBElement, outFastK, outFastD); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outFastK); + efree(outFastD); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outFastK, outFastD, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outFastK); + efree(outFastD); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_stochrsi.c b/pecl/trader_stochrsi.c new file mode 100644 index 0000000..3e0d2cf --- /dev/null +++ b/pecl/trader_stochrsi.c @@ -0,0 +1,103 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_stochrsi(array real [, int timePeriod [, int fastK_Period [, int fastD_Period [, int fastD_MAType]]]]) + Stochastic Relative Strength Index */ +PHP_FUNCTION(trader_stochrsi) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outFastK, *outFastD; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2, optInFastK_Period = 1, optInFastD_Period = 1, optInFastD_MAType = 0; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 5) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + Z_PARAM_LONG(optInFastK_Period) + Z_PARAM_LONG(optInFastD_Period) + Z_PARAM_LONG(optInFastD_MAType) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|llll", &zinReal, &optInTimePeriod, &optInFastK_Period, &optInFastD_Period, &optInFastD_MAType) == FAILURE) { + RETURN_FALSE; + } +#endif + + TRADER_CHECK_MA_TYPE(optInFastD_MAType) + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInFastK_Period); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInFastD_Period); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_STOCHRSI_Lookback((int)optInTimePeriod, (int)optInFastK_Period, (int)optInFastD_Period, (int)optInFastD_MAType); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outFastK = emalloc(sizeof(double)*optimalOutAlloc); + outFastD = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_STOCHRSI(startIdx, endIdx, inReal, (int)optInTimePeriod, (int)optInFastK_Period, (int)optInFastD_Period, (int)optInFastD_MAType, &outBegIdx, &outNBElement, outFastK, outFastD); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outFastK); + efree(outFastD); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET2(outFastK, outFastD, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outFastK); + efree(outFastD); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sub.c b/pecl/trader_sub.c new file mode 100644 index 0000000..a49d039 --- /dev/null +++ b/pecl/trader_sub.c @@ -0,0 +1,98 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sub(array real0, array real1) + Vector Arithmetic Substraction */ +PHP_FUNCTION(trader_sub) +{ + int optimalOutAlloc, lookback; + zval *zinReal0, *zinReal1; + double *inReal0, *inReal1, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(zinReal0) + Z_PARAM_ARRAY(zinReal1) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal0, &zinReal1) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), + zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SUB_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) + TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) + + TRADER_G(last_error) = TA_SUB(startIdx, endIdx, inReal0, inReal1, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal0); + efree(inReal1); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal0); + efree(inReal1); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_sum.c b/pecl/trader_sum.c new file mode 100644 index 0000000..df7a0a8 --- /dev/null +++ b/pecl/trader_sum.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_sum(array real [, int timePeriod]) + Summation */ +PHP_FUNCTION(trader_sum) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_SUM_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_SUM(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_t3.c b/pecl/trader_t3.c new file mode 100644 index 0000000..267a786 --- /dev/null +++ b/pecl/trader_t3.c @@ -0,0 +1,97 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_t3(array real [, int timePeriod [, float vFactor]]) + Triple Exponential Moving Average (T3) */ +PHP_FUNCTION(trader_t3) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + double optInVFactor = 0; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + Z_PARAM_DOUBLE(optInVFactor) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ld", &zinReal, &optInTimePeriod, &optInVFactor) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + TRADER_DBL_SET_BOUNDABLE(0, 1, optInVFactor); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_T3_Lookback((int)optInTimePeriod, optInVFactor); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_T3(startIdx, endIdx, inReal, (int)optInTimePeriod, optInVFactor, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_tan.c b/pecl/trader_tan.c new file mode 100644 index 0000000..49dad2a --- /dev/null +++ b/pecl/trader_tan.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_tan(array real) + Vector Trigonometric Tan */ +PHP_FUNCTION(trader_tan) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TAN_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_TAN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_tanh.c b/pecl/trader_tanh.c new file mode 100644 index 0000000..6123cce --- /dev/null +++ b/pecl/trader_tanh.c @@ -0,0 +1,93 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_tanh(array real) + Vector Trigonometric Tanh */ +PHP_FUNCTION(trader_tanh) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(zinReal) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TANH_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_TANH(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_tema.c b/pecl/trader_tema.c new file mode 100644 index 0000000..094e7ce --- /dev/null +++ b/pecl/trader_tema.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_tema(array real [, int timePeriod]) + Triple Exponential Moving Average */ +PHP_FUNCTION(trader_tema) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TEMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_TEMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_trange.c b/pecl/trader_trange.c new file mode 100644 index 0000000..31e3173 --- /dev/null +++ b/pecl/trader_trange.c @@ -0,0 +1,103 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_trange(array high, array low, array close) + True Range */ +PHP_FUNCTION(trader_trange) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa", &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TRANGE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_TRANGE(startIdx, endIdx, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_trima.c b/pecl/trader_trima.c new file mode 100644 index 0000000..74b6818 --- /dev/null +++ b/pecl/trader_trima.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_trima(array real [, int timePeriod]) + Triangular Moving Average */ +PHP_FUNCTION(trader_trima) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TRIMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_TRIMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_trix.c b/pecl/trader_trix.c new file mode 100644 index 0000000..a32b294 --- /dev/null +++ b/pecl/trader_trix.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_trix(array real [, int timePeriod]) + 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA */ +PHP_FUNCTION(trader_trix) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TRIX_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_TRIX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_tsf.c b/pecl/trader_tsf.c new file mode 100644 index 0000000..5470059 --- /dev/null +++ b/pecl/trader_tsf.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_tsf(array real [, int timePeriod]) + Time Series Forecast */ +PHP_FUNCTION(trader_tsf) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TSF_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_TSF(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_typprice.c b/pecl/trader_typprice.c new file mode 100644 index 0000000..63f0bd6 --- /dev/null +++ b/pecl/trader_typprice.c @@ -0,0 +1,103 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_typprice(array high, array low, array close) + Typical Price */ +PHP_FUNCTION(trader_typprice) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa", &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_TYPPRICE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_TYPPRICE(startIdx, endIdx, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_ultosc.c b/pecl/trader_ultosc.c new file mode 100644 index 0000000..a792a31 --- /dev/null +++ b/pecl/trader_ultosc.c @@ -0,0 +1,109 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_ultosc(array high, array low, array close [, int timePeriod1 [, int timePeriod2 [, int timePeriod3]]]) + Ultimate Oscillator */ +PHP_FUNCTION(trader_ultosc) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod1 = 1, optInTimePeriod2 = 1, optInTimePeriod3 = 1; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 6) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod1) + Z_PARAM_LONG(optInTimePeriod2) + Z_PARAM_LONG(optInTimePeriod3) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|lll", &zinHigh, &zinLow, &zinClose, &optInTimePeriod1, &optInTimePeriod2, &optInTimePeriod3) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod1); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod2); + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod3); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_ULTOSC_Lookback((int)optInTimePeriod1, (int)optInTimePeriod2, (int)optInTimePeriod3); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_ULTOSC(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod1, (int)optInTimePeriod2, (int)optInTimePeriod3, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_utility.c b/pecl/trader_utility.c new file mode 100644 index 0000000..0c70a5e --- /dev/null +++ b/pecl/trader_utility.c @@ -0,0 +1,106 @@ +/* + Copyright (c) 2012, Anatoliy Belsky + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto void trader_set_unstable_period(int functionId, int timePeriod) + see more here http://www.ta-lib.org/d_api/ta_setunstableperiod.html */ +PHP_FUNCTION(trader_set_unstable_period) +{ + long functionId, timePeriod; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &functionId, &timePeriod) == FAILURE) { + RETURN_FALSE; + } + + if (TA_SetUnstablePeriod((int)functionId, (int)timePeriod) != TA_SUCCESS) { + /* XXX error handling here */ + } +} +/* }}} */ + +/* {{{ proto int trader_get_unstable_period(int functionId) */ +PHP_FUNCTION(trader_get_unstable_period) +{ + long functionId; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &functionId) == FAILURE) { + RETURN_FALSE; + } + + /* XXX error handling here */ + RETURN_LONG(TA_GetUnstablePeriod((int)functionId)); +} +/* }}} */ + +/* {{{ proto void trader_set_compat(compatId) */ +PHP_FUNCTION(trader_set_compat) +{ + long compatId; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &compatId) == FAILURE) { + RETURN_FALSE; + } + + if (TA_SetCompatibility((int)compatId) != TA_SUCCESS) { + /* XXX error handling here */ + } +} +/* }}} */ + +/* {{{ proto int trader_get_compat(void)*/ +PHP_FUNCTION(trader_get_compat) +{ + if (zend_parse_parameters_none() == FAILURE) { + RETURN_FALSE; + } + + RETURN_LONG(TA_GetCompatibility()); +} +/* }}} */ + + +/* {{{ proto int trader_errno(void)*/ +PHP_FUNCTION(trader_errno) +{ + if (zend_parse_parameters_none() == FAILURE) { + RETURN_FALSE; + } + + RETURN_LONG(TRADER_G(last_error)); +} +/* }}} */ + diff --git a/pecl/trader_var.c b/pecl/trader_var.c new file mode 100644 index 0000000..bf5b5a5 --- /dev/null +++ b/pecl/trader_var.c @@ -0,0 +1,97 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_var(array real [, int timePeriod [, float nbDev]]) + Variance */ +PHP_FUNCTION(trader_var) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 1; + double optInNbDev = TA_REAL_MIN; + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + Z_PARAM_DOUBLE(optInNbDev) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|ld", &zinReal, &optInTimePeriod, &optInNbDev) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); + TRADER_DBL_SET_BOUNDABLE(TA_REAL_MIN, TA_REAL_MAX, optInNbDev); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_VAR_Lookback((int)optInTimePeriod, optInNbDev); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_VAR(startIdx, endIdx, inReal, (int)optInTimePeriod, optInNbDev, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_wclprice.c b/pecl/trader_wclprice.c new file mode 100644 index 0000000..09f18fb --- /dev/null +++ b/pecl/trader_wclprice.c @@ -0,0 +1,103 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_wclprice(array high, array low, array close) + Weighted Close Price */ +PHP_FUNCTION(trader_wclprice) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa", &zinHigh, &zinLow, &zinClose) == FAILURE) { + RETURN_FALSE; + } +#endif + + + + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_WCLPRICE_Lookback(); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_WCLPRICE(startIdx, endIdx, inHigh, inLow, inClose, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_willr.c b/pecl/trader_willr.c new file mode 100644 index 0000000..5394101 --- /dev/null +++ b/pecl/trader_willr.c @@ -0,0 +1,105 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_willr(array high, array low, array close [, int timePeriod]) + Williams' %R */ +PHP_FUNCTION(trader_willr) +{ + int optimalOutAlloc, lookback; + zval *zinHigh, *zinLow, *zinClose; + double *inHigh, *inLow, *inClose, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_ARRAY(zinHigh) + Z_PARAM_ARRAY(zinLow) + Z_PARAM_ARRAY(zinClose) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "aaa|l", &zinHigh, &zinLow, &zinClose, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT3(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), + zend_hash_num_elements(Z_ARRVAL_P(zinLow)), + zend_hash_num_elements(Z_ARRVAL_P(zinClose))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_WILLR_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) + TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) + TRADER_DBL_ZARR_TO_ARR(zinClose, inClose) + + TRADER_G(last_error) = TA_WILLR(startIdx, endIdx, inHigh, inLow, inClose, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inHigh); + efree(inLow); + efree(inClose); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/pecl/trader_wma.c b/pecl/trader_wma.c new file mode 100644 index 0000000..9e377f3 --- /dev/null +++ b/pecl/trader_wma.c @@ -0,0 +1,95 @@ +/* + Copyright (c) 2012-2018, Anatol Belski + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* $Id$ */ + +#include "php.h" +#include "php_trader.h" + +#include +#include + +ZEND_EXTERN_MODULE_GLOBALS(trader) + +/* {{{ proto array trader_wma(array real [, int timePeriod]) + Weighted Moving Average */ +PHP_FUNCTION(trader_wma) +{ + int optimalOutAlloc, lookback; + zval *zinReal; + double *inReal, *outReal; + int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; + zend_long optInTimePeriod = 2; + + +#if PHP_MAJOR_VERSION >= 7 + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(zinReal) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(optInTimePeriod) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); +#else + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { + RETURN_FALSE; + } +#endif + + + TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); + + TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) + endIdx--; /* it's <= in the ta-lib */ + + + lookback = TA_WMA_Lookback((int)optInTimePeriod); + optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); + if (optimalOutAlloc > 0) { + outReal = emalloc(sizeof(double)*optimalOutAlloc); + TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) + + TRADER_G(last_error) = TA_WMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); + if (TRADER_G(last_error) != TA_SUCCESS) { + efree(inReal); + efree(outReal); + + RETURN_FALSE; + } + + TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) + + efree(inReal); + efree(outReal); + } else { + /* The current input args combination would cause TA-Lib to produce + zero output, don't bother making any allocs or calls. */ + TRADER_G(last_error) = TA_BAD_PARAM; + RETURN_FALSE; + } +} +/* }}} */ + diff --git a/source/TALib/Core/PatternRecognition.php b/source/TALib/Core/PatternRecognition.php index 35137a4..908a4c6 100644 --- a/source/TALib/Core/PatternRecognition.php +++ b/source/TALib/Core/PatternRecognition.php @@ -1256,15 +1256,26 @@ public static function cdlEngulfing(int $startIdx, int $endIdx, array $inOpen, a $i = $startIdx; $outIdx = 0; do { - if ((($inClose[$i] >= $inOpen[$i] ? 1 : -1) == 1 && ($inClose[$i - 1] >= $inOpen[$i - 1] ? 1 : -1) == -1 && - $inClose[$i] > $inOpen[$i - 1] && $inOpen[$i] < $inClose[$i - 1] - ) - || - (($inClose[$i] >= $inOpen[$i] ? 1 : -1) == -1 && ($inClose[$i - 1] >= $inOpen[$i - 1] ? 1 : -1) == 1 && - $inOpen[$i] > $inClose[$i - 1] && $inClose[$i] < $inOpen[$i - 1] + if ( + ( + ($inOpen[$i] < $inClose[$i] && $inOpen[$i - 1] > $inClose[$i - 1]) && + ( + ($inClose[$i] >= $inOpen[$i - 1] && $inOpen[$i] <= $inClose[$i - 1]) || + ($inClose[$i] > $inOpen[$i - 1] && $inOpen[$i] < $inClose[$i - 1]) + ) + ) || ( + ($inOpen[$i] > $inClose[$i] && $inOpen[$i - 1] < $inClose[$i - 1]) && + ( + ($inOpen[$i] >= $inClose[$i - 1] && $inClose[$i] <= $inOpen[$i - 1]) || + ($inOpen[$i] > $inClose[$i - 1] && $inClose[$i] < $inOpen[$i - 1]) + ) ) ) { - $outInteger[$outIdx++] = ($inClose[$i] >= $inOpen[$i] ? 1 : -1) * 100; + if (($inOpen[$i] != $inClose[$i - 1]) && ($inClose[$i] != $inOpen[$i - 1])) { + $outInteger[$outIdx++] = $inClose[$i] > $inOpen[$i] ? 100 : -100; + } else { + $outInteger[$outIdx++] = $inClose[$i] > $inOpen[$i] ? 80 : -80; + } } else { $outInteger[$outIdx++] = 0; } diff --git a/talib/ta_common/ta_global.c b/talib/ta_common/ta_global.c new file mode 100644 index 0000000..83433e3 --- /dev/null +++ b/talib/ta_common/ta_global.c @@ -0,0 +1,186 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF First version. + * 082004 AC Add TA_SetCandleSettings, TA_RestoreCandleDefaultSettings + * and call to TA_RestoreCandleDefaultSettings in TA_Initialize + * 041106 MF Add prefix to theGlobals to avoid clash with other libs. + * 040707 MF Change global initialization to eliminate Mac OS X link error. + */ + +/* Description: + * Provides initialization / shutdown functionality for all modules. + */ + +/**** Headers ****/ +#include +#include +#include + +#include "ta_common.h" +#include "ta_magic_nb.h" +#include "ta_global.h" +#include "ta_func.h" + +#ifdef TA_LIB_PRO +/* Section for code distributed with TA-Lib Pro only. */ +#endif + +/**** External functions declarations. ****/ +/* None */ + +/**** External variables declarations. ****/ +/* None */ + +/**** Global variables definitions. ****/ + +/* The entry point for all globals */ +TA_LibcPriv ta_theGlobals = {0,{{0,0,0}},0,0,0,0,(TA_Compatibility)0,{0},{{(TA_CandleSettingType)0,(TA_RangeType)0,0,0}}}; + +TA_LibcPriv *TA_Globals = &ta_theGlobals; + +/**** Local declarations. ****/ +/* None */ + +/**** Local functions declarations. ****/ +/* None */ + +/**** Local variables definitions. ****/ +/* None */ + +/**** Global functions definitions. ****/ +TA_RetCode TA_Initialize( void ) +{ + /* Initialize the "global variable" used to manage the global + * variables of all other modules... + */ + memset( TA_Globals, 0, sizeof( TA_LibcPriv ) ); + TA_Globals->magicNb = TA_LIBC_PRIV_MAGIC_NB; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /*** At this point, TA_Shutdown can be called to clean-up. ***/ + + /* Set the default value to global variables */ + TA_RestoreCandleDefaultSettings( TA_AllCandleSettings ); + + return TA_SUCCESS; +} + +TA_RetCode TA_Shutdown( void ) +{ + if( TA_Globals->magicNb != TA_LIBC_PRIV_MAGIC_NB ) + return TA_LIB_NOT_INITIALIZE; + + /* Initialize to all zero to make sure we invalidate that object. */ + memset( TA_Globals, 0, sizeof( TA_LibcPriv ) ); + + return TA_SUCCESS; +} + +TA_RetCode TA_SetCandleSettings( TA_CandleSettingType settingType, + TA_RangeType rangeType, + int avgPeriod, + double factor ) +{ + /*printf("setcdlset:%d ",settingType);*/ + if( settingType >= TA_AllCandleSettings ) + return TA_BAD_PARAM; + TA_Globals->candleSettings[settingType].settingType = settingType; + TA_Globals->candleSettings[settingType].rangeType = rangeType; + TA_Globals->candleSettings[settingType].avgPeriod = avgPeriod; + TA_Globals->candleSettings[settingType].factor = factor; + /*printf("cdlset: %d %d %d %f\n",TA_Globals->candleSettings[settingType].settingType,TA_Globals->candleSettings[settingType].rangeType, + TA_Globals->candleSettings[settingType].avgPeriod,TA_Globals->candleSettings[settingType].factor);*/ + return TA_SUCCESS; +} + +TA_RetCode TA_RestoreCandleDefaultSettings( TA_CandleSettingType settingType ) +{ + const TA_CandleSetting TA_CandleDefaultSettings[] = { + /* real body is long when it's longer than the average of the 10 previous candles' real body */ + { TA_BodyLong, TA_RangeType_RealBody, 10, 1.0 }, + /* real body is very long when it's longer than 3 times the average of the 10 previous candles' real body */ + { TA_BodyVeryLong, TA_RangeType_RealBody, 10, 3.0 }, + /* real body is short when it's shorter than the average of the 10 previous candles' real bodies */ + { TA_BodyShort, TA_RangeType_RealBody, 10, 1.0 }, + /* real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range */ + { TA_BodyDoji, TA_RangeType_HighLow, 10, 0.1 }, + /* shadow is long when it's longer than the real body */ + { TA_ShadowLong, TA_RangeType_RealBody, 0, 1.0 }, + /* shadow is very long when it's longer than 2 times the real body */ + { TA_ShadowVeryLong, TA_RangeType_RealBody, 0, 2.0 }, + /* shadow is short when it's shorter than half the average of the 10 previous candles' sum of shadows */ + { TA_ShadowShort, TA_RangeType_Shadows, 10, 1.0 }, + /* shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range */ + { TA_ShadowVeryShort, TA_RangeType_HighLow, 10, 0.1 }, + /* when measuring distance between parts of candles or width of gaps */ + /* "near" means "<= 20% of the average of the 5 previous candles' high-low range" */ + { TA_Near, TA_RangeType_HighLow, 5, 0.2 }, + /* when measuring distance between parts of candles or width of gaps */ + /* "far" means ">= 60% of the average of the 5 previous candles' high-low range" */ + { TA_Far, TA_RangeType_HighLow, 5, 0.6 }, + /* when measuring distance between parts of candles or width of gaps */ + /* "equal" means "<= 5% of the average of the 5 previous candles' high-low range" */ + { TA_Equal, TA_RangeType_HighLow, 5, 0.05 } + }; + + int i; + if( settingType > TA_AllCandleSettings ) + return TA_BAD_PARAM; + if( settingType == TA_AllCandleSettings ) + for( i = 0; i < TA_AllCandleSettings; ++i ) + TA_Globals->candleSettings[i] = TA_CandleDefaultSettings[i]; + else + TA_Globals->candleSettings[settingType] = TA_CandleDefaultSettings[settingType]; + return TA_SUCCESS; +} + +/**** Local functions definitions. ****/ +/* None */ + + diff --git a/talib/ta_common/ta_global.h b/talib/ta_common/ta_global.h new file mode 100644 index 0000000..3cdfcf6 --- /dev/null +++ b/talib/ta_common/ta_global.h @@ -0,0 +1,119 @@ +#ifndef TA_GLOBAL_H +#define TA_GLOBAL_H + +#ifndef TA_COMMON_H + #include "ta_common.h" +#endif + +#ifndef TA_FUNC_H + #include "ta_func.h" +#endif + +/* TA_CandleSetting is the one setting struct */ +typedef struct { + TA_CandleSettingType settingType; + TA_RangeType rangeType; + int avgPeriod; + double factor; +} TA_CandleSetting; + +/* This interface is used exclusively INTERNALY to the TA-LIB. + * There is nothing for the end-user here ;-> + */ + +/* Provides functionality for managing global ressource + * throughout the TA-LIB. + * + * Since not all module are used/link in the application, + * the ta_common simply provides the mechanism for the module + * to optionnaly "register" its initialization/shutdown + * function. + * + * A function shall access its global variable by calling + * TA_GetGlobal. This function will appropriatly call the + * initialization function if its global are not yet initialized. + * + * The call of the init and shutdown function are guaranteed + * to be multithread protected. It is also guarantee that + * these function will always get called in alternance (in + * other word, following an initialization only a shutdown + * can get called). + */ + +typedef enum +{ + /* Module will be shutdown in the order specified here. */ + + TA_ABSTRACTION_GLOBAL_ID, + TA_FUNC_GLOBAL_ID, + TA_MEMORY_GLOBAL_ID, /* Must be last. */ + TA_NB_GLOBAL_ID +} TA_GlobalModuleId; + +typedef TA_RetCode (*TA_GlobalInitFunc) ( void **globalToAlloc ); +typedef TA_RetCode (*TA_GlobalShutdownFunc)( void *globalAllocated ); + +typedef struct +{ + const TA_GlobalModuleId id; + const TA_GlobalInitFunc init; + const TA_GlobalShutdownFunc shutdown; +} TA_GlobalControl; + +TA_RetCode TA_GetGlobal( const TA_GlobalControl * const control, + void **global ); + +/* Occasionaly, code tracing must be disable. + * Example: + * - The memory module needs to know if the tracing is + * still enabled or not when freeing memory on shutdown. + * - We do not want to recursively trace while the tracing + * function themselves gets called ;-> + */ +int TA_IsTraceEnabled( void ); +void TA_TraceEnable ( void ); +void TA_TraceDisable ( void ); + +/* If enabled by the user, use a local drive + * for configuration and/or temporary file. + * TA-LIB must NEVER assume such local drive + * is available. + */ +const char *TA_GetLocalCachePath( void ); + +typedef struct +{ + unsigned int initialize; + const TA_GlobalControl * control; + void *global; +} TA_ModuleControl; + +/* This is the hidden implementation of TA_Libc. */ +typedef struct +{ + unsigned int magicNb; /* Unique identifier of this object. */ + TA_ModuleControl moduleControl[TA_NB_GLOBAL_ID]; + + unsigned int traceEnabled; + unsigned int stdioEnabled; + FILE *stdioFile; + + const char *localCachePath; + + /* For handling the compatibility with other software */ + TA_Compatibility compatibility; + + /* For handling the unstable period of some TA function. */ + unsigned int unstablePeriod[TA_FUNC_UNST_ALL]; + + /* For handling the candlestick global settings */ + TA_CandleSetting candleSettings[TA_AllCandleSettings]; + +} TA_LibcPriv; + +/* The following global is used all over the place + * and is the entry point for all other globals. + */ +extern TA_LibcPriv *TA_Globals; + +#endif diff --git a/talib/ta_common/ta_magic_nb.h b/talib/ta_common/ta_magic_nb.h new file mode 100644 index 0000000..72ac109 --- /dev/null +++ b/talib/ta_common/ta_magic_nb.h @@ -0,0 +1,31 @@ +#ifndef TA_MAGIC_NB_H +#define TA_MAGIC_NB_H + +/* Many allocated structures contains a magic number. + * + * These numbers are used solely to make sure that when a pointer is + * provided, it is really pointing on the expected type of data. + * It helps also for the detection of memory corruption. + * This mechanism is simple, but add a non-negligeable level of + * reliability at a very low cost (speed/memory wise). + */ +#define TA_FUNC_DEF_MAGIC_NB 0xA201B201 +#define TA_PARAM_HOLDER_PRIV_MAGIC_NB 0xA202B202 +#define TA_LIBC_PRIV_MAGIC_NB 0xA203B203 +#define TA_UDBASE_MAGIC_NB 0xA204B204 +#define TA_CATEGORY_TABLE_MAGIC_NB 0xA205B205 +#define TA_SYMBOL_TABLE_MAGIC_NB 0xA206B206 +#define TA_WEBPAGE_MAGIC_NB 0xA207B207 +#define TA_STREAM_MAGIC_NB 0xA208B208 +#define TA_STREAM_ACCESS_MAGIC_NB 0xA209B209 +#define TA_YAHOO_IDX_MAGIC_NB 0xA20AB20A +#define TA_STRING_TABLE_GROUP_MAGIC_NB 0xA20BB20B +#define TA_STRING_TABLE_FUNC_MAGIC_NB 0xA20CB20C +#define TA_MARKET_PAGE_MAGIC_NB 0xA20DB20D +#define TA_TRADELOGPRIV_MAGIC_NB 0xA20EB20E +#define TA_PMPRIV_MAGIC_NB 0xA20FB20F +#define TA_PMREPORT_MAGIC_NB 0xA210B210 +#define TA_TRADEREPORT_MAGIC_NB 0xA211B211 +#define TA_HISTORY_MAGIC_NB 0xA212B212 + +#endif diff --git a/talib/ta_common/ta_memory.h b/talib/ta_common/ta_memory.h new file mode 100644 index 0000000..6f86964 --- /dev/null +++ b/talib/ta_common/ta_memory.h @@ -0,0 +1,362 @@ +#ifndef TA_MEMORY_H +#define TA_MEMORY_H + +#if !defined( _MANAGED ) && !defined( _JAVA ) + #ifndef TA_COMMON_H + #include "ta_common.h" + #endif + + #include + + /* Interface macros */ + #define TA_Malloc(a) malloc(a) + #define TA_Realloc(a,b) realloc((a),(b)) + #define TA_Free(a) free(a) + + #define FREE_IF_NOT_NULL(x) { if((x)!=NULL) {TA_Free((void *)(x)); (x)=NULL;} } + +#endif /* !defined(_MANAGED) && !defined( _JAVA ) */ + + +/* ARRAY : Macros to manipulate arrays of value type. + * + * Using temporary array of double and integer are often needed for the + * TA functions. + * + * These macros allow basic operations to alloc/copy/free array of value type. + * + * These macros works in plain old C/C++, managed C++.and Java. + * + * (Use ARRAY_REF and ARRAY_INT_REF for double/integer arrays). + */ +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) + #define ARRAY_VTYPE_REF(type,name) SubArray^ name + #define ARRAY_VTYPE_LOCAL(type,name,size) SubArray^ name = gcnew SubArrayFrom1D(gcnew cli::array(size),0) + #define ARRAY_VTYPE_ALLOC(type,name,size) name = gcnew SubArrayFrom1D(gcnew cli::array(size),0) + #define ARRAY_VTYPE_COPY(type,dest,src,size) SubArray::Copy( src, 0, dest, 0, size ) + #define ARRAY_VTYPE_MEMMOVE(type,dest,destIdx,src,srcIdx,size) SubArray::Copy( src, srcIdx, dest, destIdx, size ) + #define ARRAY_VTYPE_FREE(type,name) + #define ARRAY_VTYPE_FREE_COND(type,cond,name) +#elif defined( _MANAGED ) + #define ARRAY_VTYPE_REF(type,name) cli::array^ name + #define ARRAY_VTYPE_LOCAL(type,name,size) cli::array^ name = gcnew cli::array(size) + #define ARRAY_VTYPE_ALLOC(type,name,size) name = gcnew cli::array(size) + #define ARRAY_VTYPE_COPY(type,dest,src,size) cli::array::Copy( src, 0, dest, 0, size ) + #define ARRAY_VTYPE_MEMMOVE(type,dest,destIdx,src,srcIdx,size) cli::array::Copy( src, srcIdx, dest, destIdx, size ) + #define ARRAY_VTYPE_FREE(type,name) + #define ARRAY_VTYPE_FREE_COND(type,cond,name) +#elif defined( _JAVA ) + #define ARRAY_VTYPE_REF(type,name) type []name + #define ARRAY_VTYPE_LOCAL(type,name,size) type []name = new type[size] + #define ARRAY_VTYPE_ALLOC(type,name,size) name = new type[size] + #define ARRAY_VTYPE_COPY(type,dest,src,size) System.arraycopy(src,0,dest,0,size) + #define ARRAY_VTYPE_MEMMOVE(type,dest,destIdx,src,srcIdx,size) System.arraycopy(src,srcIdx,dest,destIdx,size) + #define ARRAY_VTYPE_FREE(type,name) + #define ARRAY_VTYPE_FREE_COND(type,cond,name) +#else + #define ARRAY_VTYPE_REF(type,name) type *name + #define ARRAY_VTYPE_LOCAL(type,name,size) type name[size] + #define ARRAY_VTYPE_ALLOC(type,name,size) name = (type *)TA_Malloc( sizeof(type)*(size)) + #define ARRAY_VTYPE_COPY(type,dest,src,size) memcpy(dest,src,sizeof(type)*(size)) + #define ARRAY_VTYPE_MEMMOVE(type,dest,destIdx,src,srcIdx,size) memmove( &dest[destIdx], &src[srcIdx], (size)*sizeof(type) ) + #define ARRAY_VTYPE_FREE(type,name) TA_Free(name) + #define ARRAY_VTYPE_FREE_COND(type,cond,name) if( cond ){ TA_Free(name); } +#endif + +/* ARRAY : Macros to manipulate arrays of double. */ +#define ARRAY_REF(name) ARRAY_VTYPE_REF(double,name) +#define ARRAY_LOCAL(name,size) ARRAY_VTYPE_LOCAL(double,name,size) +#define ARRAY_ALLOC(name,size) ARRAY_VTYPE_ALLOC(double,name,size) +#define ARRAY_COPY(dest,src,size) ARRAY_VTYPE_COPY(double,dest,src,size) +#define ARRAY_MEMMOVE(dest,destIdx,src,srcIdx,size) ARRAY_VTYPE_MEMMOVE(double,dest,destIdx,src,srcIdx,size) +#define ARRAY_FREE(name) ARRAY_VTYPE_FREE(double,name) +#define ARRAY_FREE_COND(cond,name) ARRAY_VTYPE_FREE_COND(double,cond,name) + +/* ARRAY : Macros to manipulate arrays of integer. */ +#define ARRAY_INT_REF(name) ARRAY_VTYPE_REF(int,name) +#define ARRAY_INT_LOCAL(name,size) ARRAY_VTYPE_LOCAL(int,name,size) +#define ARRAY_INT_ALLOC(name,size) ARRAY_VTYPE_ALLOC(int,name,size) +#define ARRAY_INT_COPY(dest,src,size) ARRAY_VTYPE_COPY(int,dest,src,size) +#define ARRAY_INT_MEMMOVE(dest,destIdx,src,srcIdx,size) ARRAY_VTYPE_MEMMOVE(int,dest,destIdx,src,srcIdx,size) +#define ARRAY_INT_FREE(name) ARRAY_VTYPE_FREE(int,name) +#define ARRAY_INT_FREE_COND(cond,name) ARRAY_VTYPE_FREE_COND(int,cond,name) + +/* ARRAY: Macros to manipulate arrays of mix type. + * This is just a loop doing an element by element copy. + */ +#define ARRAY_MEMMOVEMIX_VAR int mmmixi, mmmixdestIdx, mmmixsrcIdx +#define ARRAY_MEMMOVEMIX(dest,destIdx,src,srcIdx,size) { \ + for( mmmixi=0, mmmixdestIdx=destIdx, mmmixsrcIdx=srcIdx; \ + mmmixi < size; \ + mmmixi++, mmmixdestIdx++, mmmixsrcIdx++ ) \ + { \ + dest[mmmixdestIdx] = src[mmmixsrcIdx]; \ + } \ + } + +/* Access to "Globals" + * + * The globals here just means that these variables are accessible from + * all technical analysis functions. + * + * Depending of the language/platform, the globals might be in reality + * a private member variable of an object... + */ +#if defined( _MANAGED ) + #define TA_GLOBALS_UNSTABLE_PERIOD(x,y) (Globals->unstablePeriod[(int)(FuncUnstId::y)]) + #define TA_GLOBALS_COMPATIBILITY (Globals->compatibility) +#elif defined( _JAVA ) + #define TA_GLOBALS_UNSTABLE_PERIOD(x,y) (this.unstablePeriod[FuncUnstId.y.ordinal()]) + #define TA_GLOBALS_COMPATIBILITY (this.compatibility) +#else + #define TA_GLOBALS_UNSTABLE_PERIOD(x,y) (TA_Globals->unstablePeriod[x]) + #define TA_GLOBALS_COMPATIBILITY (TA_Globals->compatibility) +#endif + + + +/* CIRCBUF : Circular Buffer Macros. + * + * The CIRCBUF is like a FIFO buffer (First In - First Out), except + * that the rate of data coming out is the same as the rate of + * data coming in (for simplification and speed optimization). + * In other word, when you add one new value, you must also consume + * one value (if not consume, the value is lost). + * + * The CIRCBUF size is unlimited, so it will automatically allocate and + * de-allocate memory as needed. In C/C++. when small enough, CIRCBUF will + * instead use a buffer "allocated" on the stack (automatic variable). + * + * Multiple CIRCBUF can be used within the same function. To make that + * possible the first parameter of the MACRO is an "Id" that can be + * any string. + * + * The macros offer the advantage to work in C/C++ and managed C++. + * + * CIRCBUF_PROLOG(Id,Type,Size); + * Will declare all the needed variables. 2 variables are + * important: + * 1) 'Id' will be a ptr of the specified Type. + * 2) 'Id'_Idx indicates from where to consume and + * to add the data. + * + * Important: You must consume the oldest data before + * setting the new data! + * + * The Size must be reasonable since it might "allocate" + * an array of this size on the stack (each element are 'Type'). + * + * CIRCBUF_CONSTRUCT(Id,Type,Size); + * Must be called prior to use the remaining macros. Must be + * followed by CIRCBUF_DESTROY when leaving the function. + * The Size here can be large. If the static Size specified + * with CIRCBUF_PROLOG is not sufficient, this MACRO will + * allocate a new buffer from the Heap. + * + * CIRCBUF_DESTROY(Id,Size); + * Must be call prior to leave the function. + * + * CIRCBUF_NEXT(Id); + * Move forward the indexes. + * + * Example: + * TA_RetCode MyFunc( int size ) + * { + * CIRCBUF_PROLOG(MyBuf,int,4); + * int i, value; + * ... + * CIRCBUF_CONSTRUCT(MyBuf,int,size); + * ... + * // 1st Loop: Fill MyBuf with initial values + * // (must be done). + * value = 0; + * for( i=0; i < size; i++ ) + * { + * // Set the data + * MyBuf[MyBuf_Idx] = value++; + * CIRCBUF_NEXT(MyBuf); + * } + * + * // 2nd Loop: Get and Add subsequent values + * // in MyBuf (optional) + * for( i=0; i < 3; i++ ) + * { + * // Consume the data (must be done first) + * printf( "%d ", MyBuf[MyBuf_Idx] ); + * + * // Set the new data (must be done second) + * MyBuf[MyBuf_Idx] = value++; + * + * // Move the index forward + * CIRCBUF_NEXT(MyBuf); + * } + * + * // 3rd Loop: Empty MyBuf (optional) + * for( i=0; i < size; i++ ) + * { + * printf( "%d ", MyBuf[MyBuf_Idx] ); + * CIRCBUF_NEXT(MyBuf); + * } + * + * CIRCBUF_DESTROY(MyBuf); + * return TA_SUCCESS; + * } + * + * + * A call to MyFunc(5) will output: + * 0 1 2 3 4 5 6 7 + * + * The value 0 to 4 are added by the 1st loop. + * The value 5 to 7 are added by the 2nd loop. + * + * The value 0 to 2 are displayed by the 2nd loop. + * The value 3 to 7 are displayed by the 3rd loop. + * + * Because the size 5 is greater than the + * value provided in CIRCBUF_PROLOG, a buffer will + * be dynamically allocated (and freed). + */ +#if defined( _MANAGED ) + +#define CIRCBUF_PROLOG(Id,Type,Size) int Id##_Idx = 0; \ + cli::array^ Id; \ + int maxIdx_##Id = (Size-1) + +/* Use this macro instead if the Type is a class or a struct. */ +#define CIRCBUF_PROLOG_CLASS(Id,Type,Size) int Id##_Idx = 0; \ + cli::array^ Id; \ + int maxIdx_##Id = (Size-1) + +#define CIRCBUF_INIT(Id,Type,Size) \ + { \ + if( Size <= 0 ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + Id = gcnew cli::array(Size); \ + if( !Id ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + maxIdx_##Id = (Size-1); \ + } + +#define CIRCBUF_INIT_CLASS(Id,Type,Size) \ + { \ + if( Size <= 0 ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + Id = gcnew cli::array(Size); \ + for( int _##Id##_index=0; _##Id##_indexLength; _##Id##_index++) \ + { \ + Id[_##Id##_index]=gcnew Type(); \ + } \ + if( !Id ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + maxIdx_##Id = (Size-1); \ + } + +#define CIRCBUF_INIT_LOCAL_ONLY(Id,Type) \ + { \ + Id = gcnew cli::array(maxIdx_##Id+1); \ + if( !Id ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + } + +#define CIRCBUF_DESTROY(Id) + +/* Use this macro to access the member when type is a class or a struct. */ +#define CIRCBUF_REF(x) (x)-> + +#elif defined(_JAVA) + +#define CIRCBUF_PROLOG(Id,Type,Size) int Id##_Idx = 0; \ + Type []Id; \ + int maxIdx_##Id = (Size-1) + +/* Use this macro instead if the Type is a class or a struct. */ +#define CIRCBUF_PROLOG_CLASS(Id,Type,Size) int Id##_Idx = 0; \ + Type []Id; \ + int maxIdx_##Id = (Size-1) + +#define CIRCBUF_INIT(Id,Type,Size) \ + { \ + if( Size <= 0 ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + Id = new Type[Size]; \ + maxIdx_##Id = (Size-1); \ + } + +#define CIRCBUF_INIT_CLASS(Id,Type,Size) \ + { \ + if( Size <= 0 ) \ + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); \ + Id = new Type[Size]; \ + for( int _##Id##_index=0; _##Id##_index (int)(sizeof(local_##Id)/sizeof(Type)) ) \ + { \ + Id = TA_Malloc( sizeof(Type)*Size ); \ + if( !Id ) \ + return TA_ALLOC_ERR; \ + } \ + else \ + Id = &local_##Id[0]; \ + maxIdx_##Id = (Size-1); \ + Id##_Idx = 0; \ + } + +#define CIRCBUF_INIT_CLASS(Id,Type,Size) CIRCBUF_INIT(Id,Type,Size) + +#define CIRCBUF_INIT_LOCAL_ONLY(Id,Type) \ + { \ + Id = &local_##Id[0]; \ + maxIdx_##Id = (int)(sizeof(local_##Id)/sizeof(Type))-1; \ + Id##_Idx = 0; \ + } + +#define CIRCBUF_DESTROY(Id) \ + { \ + if( Id != &local_##Id[0] ) \ + TA_Free( Id ); \ + } + +/* Use this macro to access the member when Type is a class or a struct. */ +#define CIRCBUF_REF(x) (x). + +#endif + +#define CIRCBUF_NEXT(Id) \ + { \ + Id##_Idx++; \ + if( Id##_Idx > maxIdx_##Id ) \ + Id##_Idx = 0; \ + } + + +#endif + diff --git a/talib/ta_common/ta_pragma.h b/talib/ta_common/ta_pragma.h new file mode 100644 index 0000000..040c187 --- /dev/null +++ b/talib/ta_common/ta_pragma.h @@ -0,0 +1,87 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * CM Craig Miller (c-miller@users.sourceforge.net) + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011707 CM First version. + */ + +/* Description: + * + * Visual Studio 2005 has extended the C Run-Time Library by including "secure" + * runtime functions and deprecating the previous function prototypes. Since + * we need to use the previous prototypes to maintain compatibility with other + * platform compilers we are going to disable the deprecation warnings when + * compiling with Visual Studio 2005. + * + * Note: this header must be the first inclusion referenced by the code file + * needing these settings!!!!! + * + */ + +#ifndef TA_PRAGMA_H +#define TA_PRAGMA_H + +#if (_MSC_VER >= 1400) // VC8+ nmake and VS2005 + + #ifndef _CRT_SECURE_NO_DEPRECATE //turn off MS 'safe' CRT library routines + #define _CRT_SECURE_NO_DEPRECATE 1 + #endif + +// There are additional macros that may be needed in the future, so we'll list them here + //#ifndef _CRT_SECURE_NO_WARNINGS //turn off MS 'safe' CRT library routines + // #define _CRT_SECURE_NO_WARNINGS 1 + //#endif + // + //#ifndef _SCL_SECURE_NO_DEPRECATE //turn off MS 'safe' C++RT library routines + // #define _SCL_SECURE_NO_DEPRECATE 1 + //#endif + //#ifndef _SCL_SECURE_NO_WARNINGS + // #define _SCL_SECURE_NO_WARNINGS 1 + //#endif + // + //#ifndef _CRT_NONSTDC_NO_DEPRECATE //turn off MS POSIX replacements library routines + // #define _CRT_NONSTDC_NO_DEPRECATE 1 + //#endif + +#endif // VC8+ + +#endif //TA_PRAGMA_H diff --git a/talib/ta_common/ta_retcode.c b/talib/ta_common/ta_retcode.c new file mode 100644 index 0000000..ba04686 --- /dev/null +++ b/talib/ta_common/ta_retcode.c @@ -0,0 +1,109 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* Important: This file is automatically generated by the utility gen_code. + * Any modification will be lost on next execution of gen_code. + * + * The goal of this file is to provide the functionality TA_SetRetCodeInfo. + * + * This function is a convenient way for the user to translate a TA_RetCode into + * a human readable string. + */ +#include + +typedef struct +{ + TA_RetCode retCode; + const char * const enumStr; + const char * const infoStr; +} TA_InternalRetCodeInfo; + +static TA_InternalRetCodeInfo retCodeInfoTable[] = { + {(TA_RetCode)0,"TA_SUCCESS","No error"}, + {(TA_RetCode)1,"TA_LIB_NOT_INITIALIZE","TA_Initialize was not sucessfully called"}, + {(TA_RetCode)2,"TA_BAD_PARAM","A parameter is out of range"}, + {(TA_RetCode)3,"TA_ALLOC_ERR","Possibly out-of-memory"}, + {(TA_RetCode)4,"TA_GROUP_NOT_FOUND","No Info"}, + {(TA_RetCode)5,"TA_FUNC_NOT_FOUND","No Info"}, + {(TA_RetCode)6,"TA_INVALID_HANDLE","No Info"}, + {(TA_RetCode)7,"TA_INVALID_PARAM_HOLDER","No Info"}, + {(TA_RetCode)8,"TA_INVALID_PARAM_HOLDER_TYPE","No Info"}, + {(TA_RetCode)9,"TA_INVALID_PARAM_FUNCTION","No Info"}, + {(TA_RetCode)10,"TA_INPUT_NOT_ALL_INITIALIZE","No Info"}, + {(TA_RetCode)11,"TA_OUTPUT_NOT_ALL_INITIALIZE","No Info"}, + {(TA_RetCode)12,"TA_OUT_OF_RANGE_START_INDEX","No Info"}, + {(TA_RetCode)13,"TA_OUT_OF_RANGE_END_INDEX","No Info"}, + {(TA_RetCode)14,"TA_INVALID_LIST_TYPE","No Info"}, + {(TA_RetCode)15,"TA_BAD_OBJECT","No Info"}, + {(TA_RetCode)16,"TA_NOT_SUPPORTED","No Info"}, + {(TA_RetCode)5000,"TA_INTERNAL_ERROR","No Info"}, + {(TA_RetCode)0xFFFF,"TA_UNKNOWN_ERR","Unknown Error"} +}; + +#define NB_RET_CODE_INFO (sizeof(retCodeInfoTable)/sizeof(TA_InternalRetCodeInfo)) + +void TA_SetRetCodeInfo( TA_RetCode theRetCode, TA_RetCodeInfo *retCodeInfo ) +{ + unsigned int i; + + /* Trap internal error code */ + if( (theRetCode >= 5000) && (theRetCode <= 5999) ) + { + retCodeInfo->enumStr = "TA_INTERNAL_ERROR"; + retCodeInfo->infoStr = "Unexpected Internal Error - Contact TA-Lib.org"; + return; + } + + /* Check among all the error code defined in ta_common.h */ + for( i=0; i < (NB_RET_CODE_INFO-1); i++ ) + { + if( theRetCode == retCodeInfoTable[i].retCode ) + { + /* Error code found. */ + retCodeInfo->enumStr = retCodeInfoTable[i].enumStr; + retCodeInfo->infoStr = retCodeInfoTable[i].infoStr; + return; + } + } + + /* Error code not found. */ + + /* "TA_UNKNOWN_ERR" is ALWAYS the last entry in the table. */ + retCodeInfo->enumStr = retCodeInfoTable[i].enumStr; + retCodeInfo->infoStr = retCodeInfoTable[i].infoStr; +} + +/***************/ +/* End of File */ +/***************/ + diff --git a/talib/ta_common/ta_retcode.csv b/talib/ta_common/ta_retcode.csv new file mode 100644 index 0000000..ea3bd70 --- /dev/null +++ b/talib/ta_common/ta_retcode.csv @@ -0,0 +1,18 @@ +0,TA_SUCCESS,No error +1,TA_LIB_NOT_INITIALIZE,TA_Initialize was not sucessfully called +2,TA_BAD_PARAM,A parameter is out of range +3,TA_ALLOC_ERR,Possibly out-of-memory +4,TA_GROUP_NOT_FOUND,No Info +5,TA_FUNC_NOT_FOUND,No Info +6,TA_INVALID_HANDLE,No Info +7,TA_INVALID_PARAM_HOLDER,No Info +8,TA_INVALID_PARAM_HOLDER_TYPE,No Info +9,TA_INVALID_PARAM_FUNCTION,No Info +10,TA_INPUT_NOT_ALL_INITIALIZE,No Info +11,TA_OUTPUT_NOT_ALL_INITIALIZE,No Info +12,TA_OUT_OF_RANGE_START_INDEX,No Info +13,TA_OUT_OF_RANGE_END_INDEX,No Info +14,TA_INVALID_LIST_TYPE,No Info +15,TA_BAD_OBJECT,No Info +16,TA_NOT_SUPPORTED,No Info +5000,TA_INTERNAL_ERROR,No Info diff --git a/talib/ta_common/ta_version.c b/talib/ta_common/ta_version.c new file mode 100644 index 0000000..591fe27 --- /dev/null +++ b/talib/ta_common/ta_version.c @@ -0,0 +1,87 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/* Version number controlled manually. + * + * Should be modified only by TA-Lib.org + */ +#define MAJOR "0" +#define MINOR "6" +#define BUILD "0" +#define EXTRA "dev" + +/* Nothing to modify below this line. */ + +#define TA_VERSION_DT "(" __DATE__ " " __TIME__ ")" + +const char *TA_GetVersionString( void ) +{ + if (sizeof(EXTRA) > 1) { + return MAJOR "." MINOR "." BUILD "-" EXTRA " " TA_VERSION_DT; + } else { + return MAJOR "." MINOR "." BUILD " " TA_VERSION_DT; + } +} + +const char *TA_GetVersionMajor( void ) +{ + return MAJOR; +} + +const char *TA_GetVersionMinor( void ) +{ + return MINOR; +} + +const char *TA_GetVersionBuild( void ) +{ + return BUILD; +} + +const char *TA_GetVersionExtra( void ) +{ + return EXTRA; +} + +const char *TA_GetVersionDate( void ) +{ + return __DATE__; +} + +const char *TA_GetVersionTime( void ) +{ + return __TIME__; +} diff --git a/talib/ta_func/ta_ACCBANDS.c b/talib/ta_func/ta_ACCBANDS.c new file mode 100644 index 0000000..c8201be --- /dev/null +++ b/talib/ta_func/ta_ACCBANDS.c @@ -0,0 +1,516 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * RM Robert Meier + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120307 RM Initial Version + * 120907 MF Handling of a few limit cases + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AccbandsLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int accbandsLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ACCBANDS_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 20; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return LOOKBACK_CALL(SMA)( optInTimePeriod ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ACCBANDS - Acceleration Bands + * + * Input = High, Low, Close + * Output = double, double, double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Accbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outRealUpperBand, +/* Generated */ SubArray^ outRealMiddleBand, +/* Generated */ SubArray^ outRealLowerBand ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Accbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outRealUpperBand, +/* Generated */ cli::array^ outRealMiddleBand, +/* Generated */ cli::array^ outRealLowerBand ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode accbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ACCBANDS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ENUM_DECLARATION(RetCode) retCode; + ARRAY_REF( tempBuffer1 ); + ARRAY_REF( tempBuffer2 ); + VALUE_HANDLE_INT(outBegIdxDummy); + VALUE_HANDLE_INT(outNbElementDummy); + int i, j, outputSize, bufferSize, lookbackTotal; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 20; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outRealUpperBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outRealMiddleBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outRealLowerBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = LOOKBACK_CALL(SMA)( optInTimePeriod ); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Buffer will contains also the lookback required for SMA + * to satisfy the caller requested startIdx/endIdx. + */ + outputSize = endIdx-startIdx+1; + bufferSize = outputSize+lookbackTotal; + ARRAY_ALLOC(tempBuffer1, bufferSize ); + #if !defined(_JAVA) + if( !tempBuffer1 ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + ARRAY_ALLOC(tempBuffer2, bufferSize ); + #if !defined(_JAVA) + if( !tempBuffer2 ) + { + ARRAY_FREE(tempBuffer1); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + /* Calculate the upper/lower band at the same time (no SMA yet). + * Must start calculation back enough to cover the lookback + * required later for the SMA. + */ + for(j=0, i=startIdx-lookbackTotal; i<=endIdx; i++, j++) + { + tempReal = inHigh[i]+inLow[i]; + if( !TA_IS_ZERO(tempReal) ) + { + tempReal = 4*(inHigh[i]-inLow[i])/tempReal; + tempBuffer1[j] = inHigh[i]*(1+tempReal); + tempBuffer2[j] = inLow[i]*(1-tempReal); + } + else + { + tempBuffer1[j] = inHigh[i]; + tempBuffer2[j] = inLow[i]; + } + } + + /* Calculate the middle band, which is a moving average of the close. */ + retCode = FUNCTION_CALL(SMA)( startIdx, endIdx, inClose, + optInTimePeriod, + VALUE_HANDLE_OUT(outBegIdxDummy), VALUE_HANDLE_OUT(outNbElementDummy), outRealMiddleBand ); + + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_GET(outNbElementDummy) != outputSize) ) + { + ARRAY_FREE( tempBuffer1 ); + ARRAY_FREE( tempBuffer2 ); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Now let's take the SMA for the upper band. */ + retCode = FUNCTION_CALL_DOUBLE(SMA)( 0, bufferSize-1, tempBuffer1, + optInTimePeriod, + VALUE_HANDLE_OUT(outBegIdxDummy), VALUE_HANDLE_OUT(outNbElementDummy), + outRealUpperBand ); + + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_GET(outNbElementDummy) != outputSize) ) + { + ARRAY_FREE( tempBuffer1 ); + ARRAY_FREE( tempBuffer2 ); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Now let's take the SMA for the lower band. */ + retCode = FUNCTION_CALL_DOUBLE(SMA)( 0, bufferSize-1, tempBuffer2, + optInTimePeriod, + VALUE_HANDLE_OUT(outBegIdxDummy), VALUE_HANDLE_OUT(outNbElementDummy), + outRealLowerBand ); + + ARRAY_FREE( tempBuffer1 ); + ARRAY_FREE( tempBuffer2 ); + + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_GET(outNbElementDummy) != outputSize) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outputSize; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Accbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outRealUpperBand, +/* Generated */ SubArray^ outRealMiddleBand, +/* Generated */ SubArray^ outRealLowerBand ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Accbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outRealUpperBand, +/* Generated */ cli::array^ outRealMiddleBand, +/* Generated */ cli::array^ outRealLowerBand ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode accbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ACCBANDS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ ARRAY_REF( tempBuffer1 ); +/* Generated */ ARRAY_REF( tempBuffer2 ); +/* Generated */ VALUE_HANDLE_INT(outBegIdxDummy); +/* Generated */ VALUE_HANDLE_INT(outNbElementDummy); +/* Generated */ int i, j, outputSize, bufferSize, lookbackTotal; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 20; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outRealUpperBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outRealMiddleBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outRealLowerBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(SMA)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outputSize = endIdx-startIdx+1; +/* Generated */ bufferSize = outputSize+lookbackTotal; +/* Generated */ ARRAY_ALLOC(tempBuffer1, bufferSize ); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !tempBuffer1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC(tempBuffer2, bufferSize ); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !tempBuffer2 ) +/* Generated */ { +/* Generated */ ARRAY_FREE(tempBuffer1); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ for(j=0, i=startIdx-lookbackTotal; i<=endIdx; i++, j++) +/* Generated */ { +/* Generated */ tempReal = inHigh[i]+inLow[i]; +/* Generated */ if( !TA_IS_ZERO(tempReal) ) +/* Generated */ { +/* Generated */ tempReal = 4*(inHigh[i]-inLow[i])/tempReal; +/* Generated */ tempBuffer1[j] = inHigh[i]*(1+tempReal); +/* Generated */ tempBuffer2[j] = inLow[i]*(1-tempReal); +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ tempBuffer1[j] = inHigh[i]; +/* Generated */ tempBuffer2[j] = inLow[i]; +/* Generated */ } +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL(SMA)( startIdx, endIdx, inClose, +/* Generated */ optInTimePeriod, +/* Generated */ VALUE_HANDLE_OUT(outBegIdxDummy), VALUE_HANDLE_OUT(outNbElementDummy), outRealMiddleBand ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_GET(outNbElementDummy) != outputSize) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempBuffer1 ); +/* Generated */ ARRAY_FREE( tempBuffer2 ); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(SMA)( 0, bufferSize-1, tempBuffer1, +/* Generated */ optInTimePeriod, +/* Generated */ VALUE_HANDLE_OUT(outBegIdxDummy), VALUE_HANDLE_OUT(outNbElementDummy), +/* Generated */ outRealUpperBand ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_GET(outNbElementDummy) != outputSize) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempBuffer1 ); +/* Generated */ ARRAY_FREE( tempBuffer2 ); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(SMA)( 0, bufferSize-1, tempBuffer2, +/* Generated */ optInTimePeriod, +/* Generated */ VALUE_HANDLE_OUT(outBegIdxDummy), VALUE_HANDLE_OUT(outNbElementDummy), +/* Generated */ outRealLowerBand ); +/* Generated */ ARRAY_FREE( tempBuffer1 ); +/* Generated */ ARRAY_FREE( tempBuffer2 ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_GET(outNbElementDummy) != outputSize) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outputSize; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ACOS.c b/talib/ta_func/ta_ACOS.c new file mode 100644 index 0000000..617892c --- /dev/null +++ b/talib/ta_func/ta_ACOS.c @@ -0,0 +1,255 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AcosLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int acosLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ACOS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ACOS - Vector Trigonometric ACos + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Acos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Acos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode acos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ACOS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + int i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_acos(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Acos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Acos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode acos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ACOS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_acos(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_AD.c b/talib/ta_func/ta_AD.c new file mode 100644 index 0000000..4025be5 --- /dev/null +++ b/talib/ta_func/ta_AD.c @@ -0,0 +1,325 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JD jdoyle + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 111705 MF,JD Fix#1359452 for handling properly start/end range. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AdLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int adLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_AD_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* This function have no lookback needed. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_AD - Chaikin A/D Line + * + * Input = High, Low, Close, Volume + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ad( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ SubArray^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ad( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ cli::array^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ad( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double inVolume[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_AD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ const double inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int nbBar, currentBar, outIdx; + + double high, low, close, tmp; + double ad; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose||!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Note: Results from this function might vary slightly + * from Metastock outputs. The reason being that + * Metastock use float instead of double and this + * cause a different floating-point precision to + * be used. + * + * For most function, this is not an apparent difference + * but for function using large cummulative values (like + * this AD function), minor imprecision adds up and becomes + * significative. + * + * For better precision, TA-Lib use double in all its + * its calculations. + */ + + /* Default return values */ + nbBar = endIdx-startIdx+1; + VALUE_HANDLE_DEREF(outNBElement) = nbBar; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + currentBar = startIdx; + outIdx = 0; + ad = 0.0; + + while( nbBar != 0 ) + { + high = inHigh[currentBar]; + low = inLow[currentBar]; + tmp = high-low; + close = inClose[currentBar]; + + if( tmp > 0.0 ) + ad += (((close-low)-(high-close))/tmp)*((double)inVolume[currentBar]); + + outReal[outIdx++] = ad; + + currentBar++; + nbBar--; + } + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ad( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ SubArray^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ad( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ cli::array^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ad( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ float inVolume[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_AD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ const float inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int nbBar, currentBar, outIdx; +/* Generated */ double high, low, close, tmp; +/* Generated */ double ad; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose||!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbBar = endIdx-startIdx+1; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = nbBar; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ currentBar = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ ad = 0.0; +/* Generated */ while( nbBar != 0 ) +/* Generated */ { +/* Generated */ high = inHigh[currentBar]; +/* Generated */ low = inLow[currentBar]; +/* Generated */ tmp = high-low; +/* Generated */ close = inClose[currentBar]; +/* Generated */ if( tmp > 0.0 ) +/* Generated */ ad += (((close-low)-(high-close))/tmp)*((double)inVolume[currentBar]); +/* Generated */ outReal[outIdx++] = ad; +/* Generated */ currentBar++; +/* Generated */ nbBar--; +/* Generated */ } +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ diff --git a/talib/ta_func/ta_ADD.c b/talib/ta_func/ta_ADD.c new file mode 100644 index 0000000..c337272 --- /dev/null +++ b/talib/ta_func/ta_ADD.c @@ -0,0 +1,277 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AddLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int addLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ADD_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ADD - Vector Arithmetic Add + * + * Input = double, double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Add( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Add( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode add( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal0[], +/* Generated */ double inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ADD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal0[], +/* Generated */ const double inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +/* Begin Proprietary */ +/* End Proprietary */ +#else + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = inReal0[i]+inReal1[i]; + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Add( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Add( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode add( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal0[], +/* Generated */ float inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ADD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal0[], +/* Generated */ const float inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ /* Begin Proprietary */ +/* Generated */ /* End Proprietary */ +/* Generated */ #else +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = inReal0[i]+inReal1[i]; +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ADOSC.c b/talib/ta_func/ta_ADOSC.c new file mode 100644 index 0000000..784bc4f --- /dev/null +++ b/talib/ta_func/ta_ADOSC.c @@ -0,0 +1,493 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AdOscLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int adOscLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ADOSC_Lookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int slowestPeriod; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 3; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 10; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Use the slowest EMA period to evaluate the total lookback. */ + if( optInFastPeriod < optInSlowPeriod ) + slowestPeriod = optInSlowPeriod; + else + slowestPeriod = optInFastPeriod; + + /* Adjust startIdx to account for the lookback period. */ + return LOOKBACK_CALL(EMA)( slowestPeriod ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ADOSC - Chaikin A/D Oscillator + * + * Input = High, Low, Close, Volume + * Output = double + * + * Optional Parameters + * ------------------- + * optInFastPeriod:(From 2 to 100000) + * Number of period for the fast MA + * + * optInSlowPeriod:(From 2 to 100000) + * Number of period for the slow MA + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AdOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ SubArray^ inVolume, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AdOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ cli::array^ inVolume, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode adOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double inVolume[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ADOSC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ const double inVolume[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int today, outIdx, lookbackTotal; + int slowestPeriod; + double high, low, close, tmp; + + double slowEMA, slowk, one_minus_slowk; + double fastEMA, fastk, one_minus_fastk; + double ad; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose||!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 3; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 10; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Implementation Note: + * The fastEMA varaible is not neceseraly the + * fastest EMA. + * In the same way, slowEMA is not neceseraly the + * slowest EMA. + * + * The ADOSC is always the (fastEMA - slowEMA) regardless + * of the period specified. In other word: + * + * ADOSC(3,10) = EMA(3,AD) - EMA(10,AD) + * + * while + * + * ADOSC(10,3) = EMA(10,AD)- EMA(3,AD) + * + * In the first case the EMA(3) is truly a faster EMA, + * while in the second case, the EMA(10) is still call + * fastEMA in the algorithm, even if it is in fact slower. + * + * This gives more flexibility to the user if they want to + * experiment with unusual parameter settings. + */ + + /* Identify the slowest period. + * This infomration is used soleley to bootstrap + * the algorithm (skip the lookback period). + */ + if( optInFastPeriod < optInSlowPeriod ) + slowestPeriod = optInSlowPeriod; + else + slowestPeriod = optInFastPeriod; + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(EMA)( slowestPeriod ); + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + today = startIdx-lookbackTotal; + + /* The following variables and macro are used to + * calculate the "ad". + */ + ad = 0.0; + #define CALCULATE_AD \ + { \ + high = inHigh[today]; \ + low = inLow[today]; \ + tmp = high-low; \ + close = inClose[today]; \ + if( tmp > 0.0 ) \ + ad += (((close-low)-(high-close))/tmp)*((double)inVolume[today]); \ + today++; \ + } + + /* Constants for EMA */ + fastk = PER_TO_K( optInFastPeriod ); + one_minus_fastk = 1.0 - fastk; + + slowk = PER_TO_K( optInSlowPeriod ); + one_minus_slowk = 1.0 - slowk; + + /* Initialize the two EMA + * + * Use the same range of initialization inputs for + * both EMA and simply seed with the first A/D value. + * + * Note: Metastock do the same. + */ + CALCULATE_AD; + fastEMA = ad; + slowEMA = ad; + + /* Initialize the EMA and skip the unstable period. */ + while( today < startIdx ) + { + CALCULATE_AD; + fastEMA = (fastk*ad)+(one_minus_fastk*fastEMA); + slowEMA = (slowk*ad)+(one_minus_slowk*slowEMA); + } + + /* Perform the calculation for the requested range */ + outIdx = 0; + while( today <= endIdx ) + { + CALCULATE_AD; + fastEMA = (fastk*ad)+(one_minus_fastk*fastEMA); + slowEMA = (slowk*ad)+(one_minus_slowk*slowEMA); + + outReal[outIdx++] = fastEMA - slowEMA; + } + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AdOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ SubArray^ inVolume, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AdOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ cli::array^ inVolume, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode adOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ float inVolume[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ADOSC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ const float inVolume[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, outIdx, lookbackTotal; +/* Generated */ int slowestPeriod; +/* Generated */ double high, low, close, tmp; +/* Generated */ double slowEMA, slowk, one_minus_slowk; +/* Generated */ double fastEMA, fastk, one_minus_fastk; +/* Generated */ double ad; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose||!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 3; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 10; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( optInFastPeriod < optInSlowPeriod ) +/* Generated */ slowestPeriod = optInSlowPeriod; +/* Generated */ else +/* Generated */ slowestPeriod = optInFastPeriod; +/* Generated */ lookbackTotal = LOOKBACK_CALL(EMA)( slowestPeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ today = startIdx-lookbackTotal; +/* Generated */ ad = 0.0; +/* Generated */ #define CALCULATE_AD \ +/* Generated */ { \ +/* Generated */ high = inHigh[today]; \ +/* Generated */ low = inLow[today]; \ +/* Generated */ tmp = high-low; \ +/* Generated */ close = inClose[today]; \ +/* Generated */ if( tmp > 0.0 ) \ +/* Generated */ ad += (((close-low)-(high-close))/tmp)*((double)inVolume[today]); \ +/* Generated */ today++; \ +/* Generated */ } +/* Generated */ fastk = PER_TO_K( optInFastPeriod ); +/* Generated */ one_minus_fastk = 1.0 - fastk; +/* Generated */ slowk = PER_TO_K( optInSlowPeriod ); +/* Generated */ one_minus_slowk = 1.0 - slowk; +/* Generated */ CALCULATE_AD; +/* Generated */ fastEMA = ad; +/* Generated */ slowEMA = ad; +/* Generated */ while( today < startIdx ) +/* Generated */ { +/* Generated */ CALCULATE_AD; +/* Generated */ fastEMA = (fastk*ad)+(one_minus_fastk*fastEMA); +/* Generated */ slowEMA = (slowk*ad)+(one_minus_slowk*slowEMA); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ CALCULATE_AD; +/* Generated */ fastEMA = (fastk*ad)+(one_minus_fastk*fastEMA); +/* Generated */ slowEMA = (slowk*ad)+(one_minus_slowk*slowEMA); +/* Generated */ outReal[outIdx++] = fastEMA - slowEMA; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ADX.c b/talib/ta_func/ta_ADX.c new file mode 100644 index 0000000..138622f --- /dev/null +++ b/talib/ta_func/ta_ADX.c @@ -0,0 +1,796 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * MIF Mirek Fontan (mira@fontan.cz) + * GC guycom@users.sourceforge.net + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 082303 MF Fix #792298. Remove rounding. Bug reported by AM. + * 062704 MF Fix #965557. Div by zero bug reported by MIF. + * 082206 MF Fix #1544555. Div by zero bug reported by GC. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AdxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int adxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ADX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return (2 * optInTimePeriod) + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ADX,Adx) - 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ADX - Average Directional Movement Index + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Adx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Adx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode adx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ADX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int today, lookbackTotal, outIdx; + double prevHigh, prevLow, prevClose; + double prevMinusDM, prevPlusDM, prevTR; + double tempReal, tempReal2, diffP, diffM; + double minusDI, plusDI, sumDX, prevADX; + + int i; + + #define TRUE_RANGE(TH,TL,YC,OUT) {\ + OUT = TH-TL; \ + tempReal2 = std_fabs(TH-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + tempReal2 = std_fabs(TL-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + } + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* + * The DM1 (one period) is base on the largest part of + * today's range that is outside of yesterdays range. + * + * The following 7 cases explain how the +DM and -DM are + * calculated on one period: + * + * Case 1: Case 2: + * C| A| + * | | C| + * | +DM1 = (C-A) B| | +DM1 = 0 + * | -DM1 = 0 | -DM1 = (B-D) + * A| | D| + * | D| + * B| + * + * Case 3: Case 4: + * C| C| + * | A| | + * | +DM1 = (C-A) | | +DM1 = 0 + * | -DM1 = 0 B| | -DM1 = (B-D) + * A| | | + * | | D| + * B| | + * D| + * + * Case 5: Case 6: + * A| A| C| + * | C| +DM1 = 0 | | +DM1 = 0 + * | | -DM1 = 0 | | -DM1 = 0 + * | D| | | + * B| B| D| + * + * + * Case 7: + * + * C| + * A| | + * | | +DM=0 + * B| | -DM=0 + * D| + * + * In case 3 and 4, the rule is that the smallest delta between + * (C-A) and (B-D) determine which of +DM or -DM is zero. + * + * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are + * zero. + * + * The rules remain the same when A=B and C=D (when the highs + * equal the lows). + * + * When calculating the DM over a period > 1, the one-period DM + * for the desired period are initialy sum. In other word, + * for a -DM14, sum the -DM1 for the first 14 days (that's + * 13 values because there is no DM for the first day!) + * Subsequent DM are calculated using the Wilder's + * smoothing approach: + * + * Previous -DM14 + * Today's -DM14 = Previous -DM14 - -------------- + Today's -DM1 + * 14 + * + * (Same thing for +DM14) + * + * Calculation of a -DI14 is as follow: + * + * -DM14 + * -DI14 = -------- + * TR14 + * + * (Same thing for +DI14) + * + * Calculation of the TR14 is: + * + * Previous TR14 + * Today's TR14 = Previous TR14 - -------------- + Today's TR1 + * 14 + * + * The first TR14 is the summation of the first 14 TR1. See the + * TA_TRANGE function on how to calculate the true range. + * + * Calculation of the DX14 is: + * + * diffDI = ABS( (-DI14) - (+DI14) ) + * sumDI = (-DI14) + (+DI14) + * + * DX14 = 100 * (diffDI / sumDI) + * + * Calculation of the first ADX: + * + * ADX14 = SUM of the first 14 DX + * + * Calculation of subsequent ADX: + * + * ((Previous ADX14)*(14-1))+ Today's DX + * ADX14 = ------------------------------------- + * 14 + * + * Reference: + * New Concepts In Technical Trading Systems, J. Welles Wilder Jr + */ + + /* Original implementation from Wilder's book was doing some integer + * rounding in its calculations. + * + * This was understandable in the context that at the time the book + * was written, most user were doing the calculation by hand. + * + * For a computer, rounding is unnecessary (and even problematic when inputs + * are close to 1). + * + * TA-Lib does not do the rounding. Still, if you want to reproduce Wilder's examples, + * you can comment out the following #undef/#define and rebuild the library. + */ + #undef round_pos + #define round_pos(x) (x) + + lookbackTotal = (2*optInTimePeriod) + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ADX,Adx) - 1; + + /* Adjust startIdx to account for the lookback period. */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Indicate where the next output should be put + * in the outReal. + */ + outIdx = 0; + + /* Process the initial DM and TR */ + VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; + + prevMinusDM = 0.0; + prevPlusDM = 0.0; + prevTR = 0.0; + today = startIdx - lookbackTotal; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + prevClose = inClose[today]; + i = optInTimePeriod-1; + while( i-- > 0 ) + { + /* Calculate the prevMinusDM and prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR += tempReal; + prevClose = inClose[today]; + } + + /* Add up all the initial DX. */ + sumDX = 0.0; + i = optInTimePeriod; + while( i-- > 0 ) + { + /* Calculate the prevMinusDM and prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + prevMinusDM -= prevMinusDM/optInTimePeriod; + prevPlusDM -= prevPlusDM/optInTimePeriod; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + + /* Calculate the DX. The value is rounded (see Wilder book). */ + if( !TA_IS_ZERO(prevTR) ) + { + minusDI = round_pos(100.0*(prevMinusDM/prevTR)); + plusDI = round_pos(100.0*(prevPlusDM/prevTR)); + /* This loop is just to accumulate the initial DX */ + tempReal = minusDI+plusDI; + if( !TA_IS_ZERO(tempReal) ) + sumDX += round_pos( 100.0 * (std_fabs(minusDI-plusDI)/tempReal) ); + } + } + + /* Calculate the first ADX */ + prevADX = round_pos( sumDX / optInTimePeriod ); + + /* Skip the unstable period */ + i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ADX,Adx); + while( i-- > 0 ) + { + /* Calculate the prevMinusDM and prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + prevMinusDM -= prevMinusDM/optInTimePeriod; + prevPlusDM -= prevPlusDM/optInTimePeriod; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + + if( !TA_IS_ZERO(prevTR) ) + { + /* Calculate the DX. The value is rounded (see Wilder book). */ + minusDI = round_pos(100.0*(prevMinusDM/prevTR)); + plusDI = round_pos(100.0*(prevPlusDM/prevTR)); + tempReal = minusDI+plusDI; + if( !TA_IS_ZERO(tempReal) ) + { + tempReal = round_pos(100.0*(std_fabs(minusDI-plusDI)/tempReal)); + /* Calculate the ADX */ + prevADX = round_pos(((prevADX*(optInTimePeriod-1))+tempReal)/optInTimePeriod); + } + } + } + + /* Output the first ADX */ + outReal[0] = prevADX; + outIdx = 1; + + /* Calculate and output subsequent ADX */ + while( today < endIdx ) + { + /* Calculate the prevMinusDM and prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + prevMinusDM -= prevMinusDM/optInTimePeriod; + prevPlusDM -= prevPlusDM/optInTimePeriod; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + + if( !TA_IS_ZERO(prevTR) ) + { + /* Calculate the DX. The value is rounded (see Wilder book). */ + minusDI = round_pos(100.0*(prevMinusDM/prevTR)); + plusDI = round_pos(100.0*(prevPlusDM/prevTR)); + tempReal = minusDI+plusDI; + if( !TA_IS_ZERO(tempReal) ) + { + tempReal = round_pos(100.0*(std_fabs(minusDI-plusDI)/tempReal)); + /* Calculate the ADX */ + prevADX = round_pos(((prevADX*(optInTimePeriod-1))+tempReal)/optInTimePeriod); + } + } + + /* Output the ADX */ + outReal[outIdx++] = prevADX; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Adx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Adx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode adx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ADX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, lookbackTotal, outIdx; +/* Generated */ double prevHigh, prevLow, prevClose; +/* Generated */ double prevMinusDM, prevPlusDM, prevTR; +/* Generated */ double tempReal, tempReal2, diffP, diffM; +/* Generated */ double minusDI, plusDI, sumDX, prevADX; +/* Generated */ int i; +/* Generated */ #define TRUE_RANGE(TH,TL,YC,OUT) {\ +/* Generated */ OUT = TH-TL; \ +/* Generated */ tempReal2 = std_fabs(TH-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ tempReal2 = std_fabs(TL-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ } +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #undef round_pos +/* Generated */ #define round_pos(x) (x) +/* Generated */ lookbackTotal = (2*optInTimePeriod) + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ADX,Adx) - 1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; +/* Generated */ prevMinusDM = 0.0; +/* Generated */ prevPlusDM = 0.0; +/* Generated */ prevTR = 0.0; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ prevClose = inClose[today]; +/* Generated */ i = optInTimePeriod-1; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR += tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ sumDX = 0.0; +/* Generated */ i = optInTimePeriod; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ prevMinusDM -= prevMinusDM/optInTimePeriod; +/* Generated */ prevPlusDM -= prevPlusDM/optInTimePeriod; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ { +/* Generated */ minusDI = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ plusDI = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ tempReal = minusDI+plusDI; +/* Generated */ if( !TA_IS_ZERO(tempReal) ) +/* Generated */ sumDX += round_pos( 100.0 * (std_fabs(minusDI-plusDI)/tempReal) ); +/* Generated */ } +/* Generated */ } +/* Generated */ prevADX = round_pos( sumDX / optInTimePeriod ); +/* Generated */ i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ADX,Adx); +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ prevMinusDM -= prevMinusDM/optInTimePeriod; +/* Generated */ prevPlusDM -= prevPlusDM/optInTimePeriod; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ { +/* Generated */ minusDI = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ plusDI = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ tempReal = minusDI+plusDI; +/* Generated */ if( !TA_IS_ZERO(tempReal) ) +/* Generated */ { +/* Generated */ tempReal = round_pos(100.0*(std_fabs(minusDI-plusDI)/tempReal)); +/* Generated */ prevADX = round_pos(((prevADX*(optInTimePeriod-1))+tempReal)/optInTimePeriod); +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ outReal[0] = prevADX; +/* Generated */ outIdx = 1; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ prevMinusDM -= prevMinusDM/optInTimePeriod; +/* Generated */ prevPlusDM -= prevPlusDM/optInTimePeriod; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ { +/* Generated */ minusDI = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ plusDI = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ tempReal = minusDI+plusDI; +/* Generated */ if( !TA_IS_ZERO(tempReal) ) +/* Generated */ { +/* Generated */ tempReal = round_pos(100.0*(std_fabs(minusDI-plusDI)/tempReal)); +/* Generated */ prevADX = round_pos(((prevADX*(optInTimePeriod-1))+tempReal)/optInTimePeriod); +/* Generated */ } +/* Generated */ } +/* Generated */ outReal[outIdx++] = prevADX; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ADXR.c b/talib/ta_func/ta_ADXR.c new file mode 100644 index 0000000..73ef746 --- /dev/null +++ b/talib/ta_func/ta_ADXR.c @@ -0,0 +1,385 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 082303 MF Fix #792298. Remove rounding. Bug reported by AM. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AdxrLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int adxrLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ADXR_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + if( optInTimePeriod > 1 ) + return optInTimePeriod + LOOKBACK_CALL(ADX)( optInTimePeriod) - 1; + else + return 3; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ADXR - Average Directional Movement Index Rating + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Adxr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Adxr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode adxr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ADXR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ARRAY_REF( adx ); + int adxrLookback, i, j, outIdx, nbElement; + ENUM_DECLARATION(RetCode) retCode; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Original implementation from Wilder's book was doing some integer + * rounding in its calculations. + * + * This was understandable in the context that at the time the book + * was written, most user were doing the calculation by hand. + * + * For a computer, rounding is unnecessary (and even problematic when inputs + * are close to 1). + * + * TA-Lib does not do the rounding. Still, if you want to reproduce Wilder's examples, + * you can comment out the following #undef/#define and rebuild the library. + */ + #undef round_pos + #define round_pos(x) (x) + + /* Move up the start index if there is not + * enough initial data. + * Always one price bar gets consumed. + */ + adxrLookback = LOOKBACK_CALL(ADXR)( optInTimePeriod ); + + if( startIdx < adxrLookback ) + startIdx = adxrLookback; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + ARRAY_ALLOC( adx, endIdx-startIdx+optInTimePeriod ); + #if !defined( _JAVA ) + if( !adx ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + + retCode = FUNCTION_CALL(ADX)( startIdx-(optInTimePeriod-1), endIdx, + inHigh, inLow, inClose, + optInTimePeriod, outBegIdx, outNBElement, adx ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + ARRAY_FREE( adx ); + return retCode; + } + + i = optInTimePeriod-1; + j = 0; + outIdx = 0; + nbElement = endIdx-startIdx+2; + while( --nbElement != 0 ) + outReal[outIdx++] = round_pos( (adx[i++]+adx[j++])/2.0 ); + + ARRAY_FREE( adx ); + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Adxr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Adxr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode adxr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ADXR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF( adx ); +/* Generated */ int adxrLookback, i, j, outIdx, nbElement; +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #undef round_pos +/* Generated */ #define round_pos(x) (x) +/* Generated */ adxrLookback = LOOKBACK_CALL(ADXR)( optInTimePeriod ); +/* Generated */ if( startIdx < adxrLookback ) +/* Generated */ startIdx = adxrLookback; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ARRAY_ALLOC( adx, endIdx-startIdx+optInTimePeriod ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !adx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL(ADX)( startIdx-(optInTimePeriod-1), endIdx, +/* Generated */ inHigh, inLow, inClose, +/* Generated */ optInTimePeriod, outBegIdx, outNBElement, adx ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( adx ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ i = optInTimePeriod-1; +/* Generated */ j = 0; +/* Generated */ outIdx = 0; +/* Generated */ nbElement = endIdx-startIdx+2; +/* Generated */ while( --nbElement != 0 ) +/* Generated */ outReal[outIdx++] = round_pos( (adx[i++]+adx[j++])/2.0 ); +/* Generated */ ARRAY_FREE( adx ); +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_APO.c b/talib/ta_func/ta_APO.c new file mode 100644 index 0000000..6bbd3c4 --- /dev/null +++ b/talib/ta_func/ta_APO.c @@ -0,0 +1,617 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AA Andrew Atkinson + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 062804 MF Resolve div by zero bug on limit case. + * 020605 AA Fix #1117666 Lookback & out-of-bound bug. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::ApoLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int apoLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_APO_Lookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* The slow MA is the key factor determining the lookback period. */ + return LOOKBACK_CALL(MA)( max(optInSlowPeriod,optInFastPeriod), optInMAType ); +} + + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_APO - Absolute Price Oscillator + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInFastPeriod:(From 2 to 100000) + * Number of period for the fast MA + * + * optInSlowPeriod:(From 2 to 100000) + * Number of period for the slow MA + * + * optInMAType: + * Type of Moving Average + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Apo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Apo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode apo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_APO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_REF(tempBuffer); + ENUM_DECLARATION(RetCode) retCode; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Allocate an intermediate buffer. */ + ARRAY_ALLOC(tempBuffer, (endIdx-startIdx+1) ); + #if !defined(_JAVA) + if( !tempBuffer ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + + retCode = FUNCTION_CALL(INT_PO)( startIdx, endIdx, + inReal, + optInFastPeriod, + optInSlowPeriod, + optInMAType, + outBegIdx, + outNBElement, + outReal, + tempBuffer, + 0 /* No percentage. */ ); + + ARRAY_FREE( tempBuffer ); + + return retCode; +} + +/* Internal price oscillator function. + * + * A buffer must be provided for intermediate processing. + */ +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + // No INT fucntion +#else + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) + enum class Core::RetCode Core::TA_INT_PO( int startIdx, + int endIdx, + SubArray^ inReal, + int optInFastPeriod, + int optInSlowPeriod, + MAType optInMethod_2, + [Out]int% outBegIdx, + [Out]int% outNBElement, + SubArray^ outReal, + SubArray^ tempBuffer, + int doPercentageOutput ) + +#elif defined( _MANAGED ) + enum class Core::RetCode Core::TA_INT_PO( int startIdx, + int endIdx, + cli::array^ inReal, + int optInFastPeriod, + int optInSlowPeriod, + MAType optInMethod_2, + [Out]int% outBegIdx, + [Out]int% outNBElement, + cli::array^ outReal, + cli::array^ tempBuffer, + int doPercentageOutput ) +#elif defined( _JAVA ) +RetCode TA_INT_PO( int startIdx, + int endIdx, + INPUT_TYPE inReal[], + int optInFastPeriod, + int optInSlowPeriod, + MAType optInMethod_2, + MInteger outBegIdx, + MInteger outNBElement, + double outReal[], + double tempBuffer[], + int doPercentageOutput ) + +#else +TA_RetCode TA_PREFIX(INT_PO)( int startIdx, + int endIdx, + const INPUT_TYPE *inReal, + int optInFastPeriod, + int optInSlowPeriod, + TA_MAType optInMethod_2, + int *outBegIdx, + int *outNBElement, + double *outReal, + double *tempBuffer, + int doPercentageOutput ) +#endif +{ + ENUM_DECLARATION(RetCode) retCode; + + double tempReal; + int tempInteger; + VALUE_HANDLE_INT(outBegIdx1); + VALUE_HANDLE_INT(outNbElement1); + VALUE_HANDLE_INT(outBegIdx2); + VALUE_HANDLE_INT(outNbElement2); + + int i, j; + + /* Make sure slow is really slower than + * the fast period! if not, swap... + */ + if( optInSlowPeriod < optInFastPeriod ) + { + /* swap */ + tempInteger = optInSlowPeriod; + optInSlowPeriod = optInFastPeriod; + optInFastPeriod = tempInteger; + } + + /* Calculate the fast MA into the tempBuffer. */ + retCode = FUNCTION_CALL(MA)( startIdx, endIdx, + inReal, + optInFastPeriod, + optInMethod_2, + VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), + tempBuffer ); + + if( retCode == ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + /* Calculate the slow MA into the output. */ + retCode = FUNCTION_CALL(MA)( startIdx, endIdx, + inReal, + optInSlowPeriod, + optInMethod_2, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), + outReal ); + + if( retCode == ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + tempInteger = VALUE_HANDLE_GET(outBegIdx1) - VALUE_HANDLE_GET(outBegIdx2); + if( doPercentageOutput != 0 ) + { + /* Calculate ((fast MA)-(slow MA))/(slow MA) in the output. */ + for( i=0,j=tempInteger; i < VALUE_HANDLE_GET(outNbElement1); i++, j++ ) + { + tempReal = outReal[i]; + if( !TA_IS_ZERO(tempReal) ) + outReal[i] = ((tempBuffer[j]-tempReal)/tempReal)*100.0; + else + outReal[i] = 0.0; + } + } + else + { + /* Calculate (fast MA)-(slow MA) in the output. */ + for( i=0,j=tempInteger; i < VALUE_HANDLE_GET(outNbElement1); i++, j++ ) + outReal[i] = tempBuffer[j]-outReal[i]; + } + + VALUE_HANDLE_DEREF(outBegIdx) = VALUE_HANDLE_GET(outBegIdx1); + VALUE_HANDLE_DEREF(outNBElement) = VALUE_HANDLE_GET(outNbElement1); + } + } + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + } + + return retCode; +} +#endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Apo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Apo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode apo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_APO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(tempBuffer); +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC(tempBuffer, (endIdx-startIdx+1) ); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !tempBuffer ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL(INT_PO)( startIdx, endIdx, +/* Generated */ inReal, +/* Generated */ optInFastPeriod, +/* Generated */ optInSlowPeriod, +/* Generated */ optInMAType, +/* Generated */ outBegIdx, +/* Generated */ outNBElement, +/* Generated */ outReal, +/* Generated */ tempBuffer, +/* Generated */ 0 ); +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ // No INT fucntion +/* Generated */ #else +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TA_INT_PO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ MAType optInMethod_2, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal, +/* Generated */ SubArray^ tempBuffer, +/* Generated */ int doPercentageOutput ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TA_INT_PO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ MAType optInMethod_2, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal, +/* Generated */ cli::array^ tempBuffer, +/* Generated */ int doPercentageOutput ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ RetCode TA_INT_PO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ INPUT_TYPE inReal[], +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ MAType optInMethod_2, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[], +/* Generated */ double tempBuffer[], +/* Generated */ int doPercentageOutput ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_PREFIX(INT_PO)( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const INPUT_TYPE *inReal, +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ TA_MAType optInMethod_2, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double *outReal, +/* Generated */ double *tempBuffer, +/* Generated */ int doPercentageOutput ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ double tempReal; +/* Generated */ int tempInteger; +/* Generated */ VALUE_HANDLE_INT(outBegIdx1); +/* Generated */ VALUE_HANDLE_INT(outNbElement1); +/* Generated */ VALUE_HANDLE_INT(outBegIdx2); +/* Generated */ VALUE_HANDLE_INT(outNbElement2); +/* Generated */ int i, j; +/* Generated */ if( optInSlowPeriod < optInFastPeriod ) +/* Generated */ { +/* Generated */ tempInteger = optInSlowPeriod; +/* Generated */ optInSlowPeriod = optInFastPeriod; +/* Generated */ optInFastPeriod = tempInteger; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL(MA)( startIdx, endIdx, +/* Generated */ inReal, +/* Generated */ optInFastPeriod, +/* Generated */ optInMethod_2, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), +/* Generated */ tempBuffer ); +/* Generated */ if( retCode == ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ retCode = FUNCTION_CALL(MA)( startIdx, endIdx, +/* Generated */ inReal, +/* Generated */ optInSlowPeriod, +/* Generated */ optInMethod_2, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ outReal ); +/* Generated */ if( retCode == ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ tempInteger = VALUE_HANDLE_GET(outBegIdx1) - VALUE_HANDLE_GET(outBegIdx2); +/* Generated */ if( doPercentageOutput != 0 ) +/* Generated */ { +/* Generated */ for( i=0,j=tempInteger; i < VALUE_HANDLE_GET(outNbElement1); i++, j++ ) +/* Generated */ { +/* Generated */ tempReal = outReal[i]; +/* Generated */ if( !TA_IS_ZERO(tempReal) ) +/* Generated */ outReal[i] = ((tempBuffer[j]-tempReal)/tempReal)*100.0; +/* Generated */ else +/* Generated */ outReal[i] = 0.0; +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ for( i=0,j=tempInteger; i < VALUE_HANDLE_GET(outNbElement1); i++, j++ ) +/* Generated */ outReal[i] = tempBuffer[j]-outReal[i]; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = VALUE_HANDLE_GET(outBegIdx1); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = VALUE_HANDLE_GET(outNbElement1); +/* Generated */ } +/* Generated */ } +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ } +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ #endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_AROON.c b/talib/ta_func/ta_AROON.c new file mode 100644 index 0000000..3acdb30 --- /dev/null +++ b/talib/ta_func/ta_AROON.c @@ -0,0 +1,461 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 050703 MF Fix algorithm base on Adrian Michel bug report #748163 + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AroonLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int aroonLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_AROON_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_AROON - Aroon + * + * Input = High, Low + * Output = double, double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Aroon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outAroonDown, +/* Generated */ SubArray^ outAroonUp ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Aroon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outAroonDown, +/* Generated */ cli::array^ outAroonUp ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode aroon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outAroonDown[], +/* Generated */ double outAroonUp[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_AROON( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outAroonDown[], +/* Generated */ double outAroonUp[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double lowest, highest, tmp, factor; + int outIdx; + int trailingIdx, lowestIdx, highestIdx, today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outAroonDown ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outAroonUp ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* This function is using a speed optimized algorithm + * for the min/max logic. + * + * You might want to first look at how TA_MIN/TA_MAX works + * and this function will become easier to understand. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-optInTimePeriod; + lowestIdx = -1; + highestIdx = -1; + lowest = 0.0; + highest = 0.0; + factor = (double)100.0/(double)optInTimePeriod; + + while( today <= endIdx ) + { + /* Keep track of the lowestIdx */ + tmp = inLow[today]; + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inLow[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inLow[i]; + if( tmp <= lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + } + + /* Keep track of the highestIdx */ + tmp = inHigh[today]; + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inHigh[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inHigh[i]; + if( tmp >= highest ) + { + highestIdx = i; + highest = tmp; + } + } + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + } + + /* Note: Do not forget that input and output buffer can be the same, + * so writing to the output is the last thing being done here. + */ + outAroonUp[outIdx] = factor*(optInTimePeriod-(today-highestIdx)); + outAroonDown[outIdx] = factor*(optInTimePeriod-(today-lowestIdx)); + + outIdx++; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Aroon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outAroonDown, +/* Generated */ SubArray^ outAroonUp ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Aroon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outAroonDown, +/* Generated */ cli::array^ outAroonUp ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode aroon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outAroonDown[], +/* Generated */ double outAroonUp[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_AROON( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outAroonDown[], +/* Generated */ double outAroonUp[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, highest, tmp, factor; +/* Generated */ int outIdx; +/* Generated */ int trailingIdx, lowestIdx, highestIdx, today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outAroonDown ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outAroonUp ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-optInTimePeriod; +/* Generated */ lowestIdx = -1; +/* Generated */ highestIdx = -1; +/* Generated */ lowest = 0.0; +/* Generated */ highest = 0.0; +/* Generated */ factor = (double)100.0/(double)optInTimePeriod; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inLow[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inLow[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inLow[i]; +/* Generated */ if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ tmp = inHigh[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inHigh[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inHigh[i]; +/* Generated */ if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ outAroonUp[outIdx] = factor*(optInTimePeriod-(today-highestIdx)); +/* Generated */ outAroonDown[outIdx] = factor*(optInTimePeriod-(today-lowestIdx)); +/* Generated */ outIdx++; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_AROONOSC.c b/talib/ta_func/ta_AROONOSC.c new file mode 100644 index 0000000..66715a3 --- /dev/null +++ b/talib/ta_func/ta_AROONOSC.c @@ -0,0 +1,466 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 050703 MF Fix algorithm base on Adrian Michel bug report #748163 + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AroonOscLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int aroonOscLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_AROONOSC_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_AROONOSC - Aroon Oscillator + * + * Input = High, Low + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AroonOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AroonOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode aroonOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_AROONOSC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double lowest, highest, tmp, factor, aroon; + int outIdx; + int trailingIdx, lowestIdx, highestIdx, today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* This code is almost identical to the TA_AROON function + * except that instead of outputing ArroonUp and AroonDown + * individually, an oscillator is build from both. + * + * AroonOsc = AroonUp- AroonDown; + * + */ + + /* This function is using a speed optimized algorithm + * for the min/max logic. + * + * You might want to first look at how TA_MIN/TA_MAX works + * and this function will become easier to understand. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-optInTimePeriod; + lowestIdx = -1; + highestIdx = -1; + lowest = 0.0; + highest = 0.0; + factor = (double)100.0/(double)optInTimePeriod; + + while( today <= endIdx ) + { + /* Keep track of the lowestIdx */ + tmp = inLow[today]; + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inLow[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inLow[i]; + if( tmp <= lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + } + + /* Keep track of the highestIdx */ + tmp = inHigh[today]; + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inHigh[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inHigh[i]; + if( tmp >= highest ) + { + highestIdx = i; + highest = tmp; + } + } + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + } + + /* The oscillator is the following: + * AroonUp = factor*(optInTimePeriod-(today-highestIdx)); + * AroonDown = factor*(optInTimePeriod-(today-lowestIdx)); + * AroonOsc = AroonUp-AroonDown; + * + * An arithmetic simplification give us: + * Aroon = factor*(highestIdx-lowestIdx) + */ + aroon = factor*(highestIdx-lowestIdx); + + /* Note: Do not forget that input and output buffer can be the same, + * so writing to the output is the last thing being done here. + */ + outReal[outIdx] = aroon; + + outIdx++; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AroonOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AroonOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode aroonOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_AROONOSC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, highest, tmp, factor, aroon; +/* Generated */ int outIdx; +/* Generated */ int trailingIdx, lowestIdx, highestIdx, today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-optInTimePeriod; +/* Generated */ lowestIdx = -1; +/* Generated */ highestIdx = -1; +/* Generated */ lowest = 0.0; +/* Generated */ highest = 0.0; +/* Generated */ factor = (double)100.0/(double)optInTimePeriod; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inLow[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inLow[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inLow[i]; +/* Generated */ if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ tmp = inHigh[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inHigh[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inHigh[i]; +/* Generated */ if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ aroon = factor*(highestIdx-lowestIdx); +/* Generated */ outReal[outIdx] = aroon; +/* Generated */ outIdx++; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ASIN.c b/talib/ta_func/ta_ASIN.c new file mode 100644 index 0000000..4219bdf --- /dev/null +++ b/talib/ta_func/ta_ASIN.c @@ -0,0 +1,255 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AsinLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int asinLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ASIN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ASIN - Vector Trigonometric ASin + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Asin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Asin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode asin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ASIN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + int i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_asin(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Asin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Asin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode asin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ASIN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_asin(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ATAN.c b/talib/ta_func/ta_ATAN.c new file mode 100644 index 0000000..2d9443d --- /dev/null +++ b/talib/ta_func/ta_ATAN.c @@ -0,0 +1,249 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AtanLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int atanLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ATAN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ATAN - Vector Trigonometric ATan + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Atan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Atan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode atan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ATAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + int i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Default return values */ + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_atan(inReal[i]); + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Atan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Atan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode atan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ATAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_atan(inReal[i]); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ATR.c b/talib/ta_func/ta_ATR.c new file mode 100644 index 0000000..05c410b --- /dev/null +++ b/talib/ta_func/ta_ATR.c @@ -0,0 +1,464 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AtrLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int atrLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ATR_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* The ATR lookback is the sum of: + * 1 + (optInTimePeriod - 1) + * + * Where 1 is for the True Range, and + * (optInTimePeriod-1) is for the simple + * moving average. + */ + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ATR,Atr); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ATR - Average True Range + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Atr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Atr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode atr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ATR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ENUM_DECLARATION(RetCode) retCode; + int outIdx, today, lookbackTotal; + int nbATR; + VALUE_HANDLE_INT(outBegIdx1); + VALUE_HANDLE_INT(outNbElement1); + + double prevATR; + ARRAY_REF( tempBuffer ); + ARRAY_LOCAL(prevATRTemp,1); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Average True Range is the greatest of the following: + * + * val1 = distance from today's high to today's low. + * val2 = distance from yesterday's close to today's high. + * val3 = distance from yesterday's close to today's low. + * + * These value are averaged for the specified period using + * Wilder method. This method have an unstable period comparable + * to and Exponential Moving Average (EMA). + */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(ATR)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + /* Trap the case where no smoothing is needed. */ + if( optInTimePeriod <= 1 ) + { + /* No smoothing needed. Just do a TRANGE. */ + return FUNCTION_CALL(TRANGE)( startIdx, endIdx, + inHigh, inLow, inClose, + outBegIdx, outNBElement, outReal ); + } + + /* Allocate an intermediate buffer for TRANGE. */ + ARRAY_ALLOC(tempBuffer, lookbackTotal+(endIdx-startIdx)+1 ); + + /* Do TRANGE in the intermediate buffer. */ + retCode = FUNCTION_CALL(TRANGE)( (startIdx-lookbackTotal+1), endIdx, + inHigh, inLow, inClose, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), + tempBuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + ARRAY_FREE( tempBuffer ); + return retCode; + } + + /* First value of the ATR is a simple Average of + * the TRANGE output for the specified period. + */ + retCode = FUNCTION_CALL_DOUBLE(INT_SMA)( optInTimePeriod-1, + optInTimePeriod-1, + tempBuffer, optInTimePeriod, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), + prevATRTemp ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + ARRAY_FREE( tempBuffer ); + return retCode; + } + prevATR = prevATRTemp[0]; + + /* Subsequent value are smoothed using the + * previous ATR value (Wilder's approach). + * 1) Multiply the previous ATR by 'period-1'. + * 2) Add today TR value. + * 3) Divide by 'period'. + */ + today = optInTimePeriod; + outIdx = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ATR,Atr); + /* Skip the unstable period. */ + while( outIdx != 0 ) + { + prevATR *= optInTimePeriod - 1; + prevATR += tempBuffer[today++]; + prevATR /= optInTimePeriod; + outIdx--; + } + + /* Now start to write the final ATR in the caller + * provided outReal. + */ + outIdx = 1; + outReal[0] = prevATR; + + /* Now do the number of requested ATR. */ + nbATR = (endIdx - startIdx)+1; + + while( --nbATR != 0 ) + { + prevATR *= optInTimePeriod - 1; + prevATR += tempBuffer[today++]; + prevATR /= optInTimePeriod; + outReal[outIdx++] = prevATR; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + ARRAY_FREE( tempBuffer ); + + return retCode; +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Atr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Atr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode atr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ATR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int outIdx, today, lookbackTotal; +/* Generated */ int nbATR; +/* Generated */ VALUE_HANDLE_INT(outBegIdx1); +/* Generated */ VALUE_HANDLE_INT(outNbElement1); +/* Generated */ double prevATR; +/* Generated */ ARRAY_REF( tempBuffer ); +/* Generated */ ARRAY_LOCAL(prevATRTemp,1); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackTotal = LOOKBACK_CALL(ATR)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ if( optInTimePeriod <= 1 ) +/* Generated */ { +/* Generated */ return FUNCTION_CALL(TRANGE)( startIdx, endIdx, +/* Generated */ inHigh, inLow, inClose, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ } +/* Generated */ ARRAY_ALLOC(tempBuffer, lookbackTotal+(endIdx-startIdx)+1 ); +/* Generated */ retCode = FUNCTION_CALL(TRANGE)( (startIdx-lookbackTotal+1), endIdx, +/* Generated */ inHigh, inLow, inClose, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ tempBuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_SMA)( optInTimePeriod-1, +/* Generated */ optInTimePeriod-1, +/* Generated */ tempBuffer, optInTimePeriod, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ prevATRTemp ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ prevATR = prevATRTemp[0]; +/* Generated */ today = optInTimePeriod; +/* Generated */ outIdx = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_ATR,Atr); +/* Generated */ while( outIdx != 0 ) +/* Generated */ { +/* Generated */ prevATR *= optInTimePeriod - 1; +/* Generated */ prevATR += tempBuffer[today++]; +/* Generated */ prevATR /= optInTimePeriod; +/* Generated */ outIdx--; +/* Generated */ } +/* Generated */ outIdx = 1; +/* Generated */ outReal[0] = prevATR; +/* Generated */ nbATR = (endIdx - startIdx)+1; +/* Generated */ while( --nbATR != 0 ) +/* Generated */ { +/* Generated */ prevATR *= optInTimePeriod - 1; +/* Generated */ prevATR += tempBuffer[today++]; +/* Generated */ prevATR /= optInTimePeriod; +/* Generated */ outReal[outIdx++] = prevATR; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_AVGDEV.c b/talib/ta_func/ta_AVGDEV.c new file mode 100644 index 0000000..1c3ecb4 --- /dev/null +++ b/talib/ta_func/ta_AVGDEV.c @@ -0,0 +1,329 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AB Anatoliy Belsky + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090812 AB Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AvgDevLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int avgDevLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_AVGDEV_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_AVGDEV - Average Deviation + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AvgDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AvgDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode avgDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_AVGDEV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int today, outIdx, lookback; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + lookback = optInTimePeriod - 1; + + if (startIdx < lookback) { + startIdx = lookback; + } + today = startIdx; + + /* Make sure there is still something to evaluate. */ + if( today > endIdx ) { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Process the initial DM and TR */ + VALUE_HANDLE_DEREF(outBegIdx) = today; + + outIdx = 0; + + while (today <= endIdx) { + double todaySum, todayDev; + int i; + + todaySum = 0.0; + for (i = 0; i < optInTimePeriod; i++) { + todaySum += inReal[today-i]; + } + + todayDev = 0.0; + for (i = 0; i < optInTimePeriod; i++) { + todayDev += std_fabs(inReal[today-i] - todaySum/optInTimePeriod); + } + outReal[outIdx] = todayDev/optInTimePeriod; + + outIdx++; + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AvgDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AvgDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode avgDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_AVGDEV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, outIdx, lookback; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookback = optInTimePeriod - 1; +/* Generated */ if (startIdx < lookback) { +/* Generated */ startIdx = lookback; +/* Generated */ } +/* Generated */ today = startIdx; +/* Generated */ if( today > endIdx ) { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = today; +/* Generated */ outIdx = 0; +/* Generated */ while (today <= endIdx) { +/* Generated */ double todaySum, todayDev; +/* Generated */ int i; +/* Generated */ todaySum = 0.0; +/* Generated */ for (i = 0; i < optInTimePeriod; i++) { +/* Generated */ todaySum += inReal[today-i]; +/* Generated */ } +/* Generated */ todayDev = 0.0; +/* Generated */ for (i = 0; i < optInTimePeriod; i++) { +/* Generated */ todayDev += std_fabs(inReal[today-i] - todaySum/optInTimePeriod); +/* Generated */ } +/* Generated */ outReal[outIdx] = todayDev/optInTimePeriod; +/* Generated */ outIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_AVGPRICE.c b/talib/ta_func/ta_AVGPRICE.c new file mode 100644 index 0000000..07b9a35 --- /dev/null +++ b/talib/ta_func/ta_AVGPRICE.c @@ -0,0 +1,289 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 112605 MF Fix outBegIdx when startIdx != 0 + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::AvgPriceLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int avgPriceLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_AVGPRICE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* This function have no lookback needed. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_AVGPRICE - Average Price + * + * Input = Open, High, Low, Close + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AvgPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AvgPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode avgPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_AVGPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Average price = (High + Low + Open + Close) / 4 */ + + outIdx = 0; + + for( i=startIdx; i <= endIdx; i++ ) + { + outReal[outIdx++] = ( inHigh [i] + + inLow [i] + + inClose[i] + + inOpen [i]) / 4; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::AvgPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::AvgPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode avgPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_AVGPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ for( i=startIdx; i <= endIdx; i++ ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = ( inHigh [i] + +/* Generated */ inLow [i] + +/* Generated */ inClose[i] + +/* Generated */ inOpen [i]) / 4; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_BBANDS.c b/talib/ta_func/ta_BBANDS.c new file mode 100644 index 0000000..de8b46b --- /dev/null +++ b/talib/ta_func/ta_BBANDS.c @@ -0,0 +1,657 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JV Jesus Viver <324122@cienz.unizar.es> + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 010503 MF Fix to always use SMA for the STDDEV (Thanks to JV). + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::BbandsLookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int bbandsLookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_BBANDS_Lookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ TA_MAType optInMAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInNbDevUp == TA_REAL_DEFAULT ) +/* Generated */ optInNbDevUp = 2.000000e+0; +/* Generated */ else if( (optInNbDevUp < -3.000000e+37) ||/* Generated */ (optInNbDevUp > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInNbDevDn == TA_REAL_DEFAULT ) +/* Generated */ optInNbDevDn = 2.000000e+0; +/* Generated */ else if( (optInNbDevDn < -3.000000e+37) ||/* Generated */ (optInNbDevDn > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInNbDevUp); + UNUSED_VARIABLE(optInNbDevDn); + + /* The lookback is driven by the middle band moving average. */ + return LOOKBACK_CALL(MA)( optInTimePeriod, optInMAType ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_BBANDS - Bollinger Bands + * + * Input = double + * Output = double, double, double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * optInNbDevUp:(From TA_REAL_MIN to TA_REAL_MAX) + * Deviation multiplier for upper band + * + * optInNbDevDn:(From TA_REAL_MIN to TA_REAL_MAX) + * Deviation multiplier for lower band + * + * optInMAType: + * Type of Moving Average + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Bbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outRealUpperBand, +/* Generated */ SubArray^ outRealMiddleBand, +/* Generated */ SubArray^ outRealLowerBand ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Bbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outRealUpperBand, +/* Generated */ cli::array^ outRealMiddleBand, +/* Generated */ cli::array^ outRealLowerBand ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode bbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_BBANDS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ENUM_DECLARATION(RetCode) retCode; + int i; + double tempReal, tempReal2; + ARRAY_REF(tempBuffer1); + ARRAY_REF(tempBuffer2); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInNbDevUp == TA_REAL_DEFAULT ) +/* Generated */ optInNbDevUp = 2.000000e+0; +/* Generated */ else if( (optInNbDevUp < -3.000000e+37) ||/* Generated */ (optInNbDevUp > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInNbDevDn == TA_REAL_DEFAULT ) +/* Generated */ optInNbDevDn = 2.000000e+0; +/* Generated */ else if( (optInNbDevDn < -3.000000e+37) ||/* Generated */ (optInNbDevDn > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outRealUpperBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outRealMiddleBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outRealLowerBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify TWO temporary buffer among the outputs. + * + * These temporary buffers allows to perform the + * calculation without any memory allocation. + * + * Whenever possible, make the tempBuffer1 be the + * middle band output. This will save one copy operation. + */ + #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) + tempBuffer1 = outRealMiddleBand; + tempBuffer2 = outRealLowerBand; + #else + if( inReal == outRealUpperBand ) + { + tempBuffer1 = outRealMiddleBand; + tempBuffer2 = outRealLowerBand; + } + else if( inReal == outRealLowerBand ) + { + tempBuffer1 = outRealMiddleBand; + tempBuffer2 = outRealUpperBand; + } + else if( inReal == outRealMiddleBand ) + { + tempBuffer1 = outRealLowerBand; + tempBuffer2 = outRealUpperBand; + } + else + { + tempBuffer1 = outRealMiddleBand; + tempBuffer2 = outRealUpperBand; + } + /* Check that the caller is not doing tricky things. + * (like using the input buffer in two output!) + */ + if( (tempBuffer1 == inReal) || (tempBuffer2 == inReal) ) + return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); + #endif + + + /* Calculate the middle band, which is a moving average. + * The other two bands will simply add/substract the + * standard deviation from this middle band. + */ + retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal, + optInTimePeriod, optInMAType, + outBegIdx, outNBElement, tempBuffer1 ); + + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Calculate the standard deviation into tempBuffer2. */ + if( optInMAType == ENUM_VALUE(MAType,TA_MAType_SMA,Sma) ) + { + /* A small speed optimization by re-using the + * already calculated SMA. + */ + FUNCTION_CALL(INT_stddev_using_precalc_ma)( inReal, tempBuffer1, + (int)VALUE_HANDLE_DEREF(outBegIdx), (int)VALUE_HANDLE_DEREF(outNBElement), + optInTimePeriod, tempBuffer2 ); + } + else + { + /* Calculate the Standard Deviation */ + retCode = FUNCTION_CALL(STDDEV)( (int)VALUE_HANDLE_DEREF(outBegIdx), endIdx, inReal, + optInTimePeriod, 1.0, + outBegIdx, outNBElement, tempBuffer2 ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + } + + /* Copy the MA calculation into the middle band ouput, unless + * the calculation was done into it already! + */ + #if !defined(USE_SINGLE_PRECISION_INPUT) + if( tempBuffer1 != outRealMiddleBand ) + { + ARRAY_COPY( outRealMiddleBand, tempBuffer1, VALUE_HANDLE_DEREF(outNBElement) ); + } + #endif + + /* Now do a tight loop to calculate the upper/lower band at + * the same time. + * + * All the following 5 loops are doing the same, except there + * is an attempt to speed optimize by eliminating uneeded + * multiplication. + */ + if( optInNbDevUp == optInNbDevDn ) + { + if( optInNbDevUp == 1.0 ) + { + /* No standard deviation multiplier needed. */ + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = tempBuffer2[i]; + tempReal2 = outRealMiddleBand[i]; + outRealUpperBand[i] = tempReal2 + tempReal; + outRealLowerBand[i] = tempReal2 - tempReal; + } + } + else + { + /* Upper/lower band use the same standard deviation multiplier. */ + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = tempBuffer2[i] * optInNbDevUp; + tempReal2 = outRealMiddleBand[i]; + outRealUpperBand[i] = tempReal2 + tempReal; + outRealLowerBand[i] = tempReal2 - tempReal; + } + } + } + else if( optInNbDevUp == 1.0 ) + { + /* Only lower band has a standard deviation multiplier. */ + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = tempBuffer2[i]; + tempReal2 = outRealMiddleBand[i]; + outRealUpperBand[i] = tempReal2 + tempReal; + outRealLowerBand[i] = tempReal2 - (tempReal * optInNbDevDn); + } + } + else if( optInNbDevDn == 1.0 ) + { + /* Only upper band has a standard deviation multiplier. */ + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = tempBuffer2[i]; + tempReal2 = outRealMiddleBand[i]; + outRealLowerBand[i] = tempReal2 - tempReal; + outRealUpperBand[i] = tempReal2 + (tempReal * optInNbDevUp); + } + } + else + { + /* Upper/lower band have distinctive standard deviation multiplier. */ + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = tempBuffer2[i]; + tempReal2 = outRealMiddleBand[i]; + outRealUpperBand[i] = tempReal2 + (tempReal * optInNbDevUp); + outRealLowerBand[i] = tempReal2 - (tempReal * optInNbDevDn); + } + } + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Bbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outRealUpperBand, +/* Generated */ SubArray^ outRealMiddleBand, +/* Generated */ SubArray^ outRealLowerBand ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Bbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outRealUpperBand, +/* Generated */ cli::array^ outRealMiddleBand, +/* Generated */ cli::array^ outRealLowerBand ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode bbands( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_BBANDS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDevUp, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInNbDevDn, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outRealUpperBand[], +/* Generated */ double outRealMiddleBand[], +/* Generated */ double outRealLowerBand[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int i; +/* Generated */ double tempReal, tempReal2; +/* Generated */ ARRAY_REF(tempBuffer1); +/* Generated */ ARRAY_REF(tempBuffer2); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInNbDevUp == TA_REAL_DEFAULT ) +/* Generated */ optInNbDevUp = 2.000000e+0; +/* Generated */ else if( (optInNbDevUp < -3.000000e+37) || (optInNbDevUp > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInNbDevDn == TA_REAL_DEFAULT ) +/* Generated */ optInNbDevDn = 2.000000e+0; +/* Generated */ else if( (optInNbDevDn < -3.000000e+37) || (optInNbDevDn > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outRealUpperBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outRealMiddleBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outRealLowerBand ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) +/* Generated */ tempBuffer1 = outRealMiddleBand; +/* Generated */ tempBuffer2 = outRealLowerBand; +/* Generated */ #else +/* Generated */ if( inReal == outRealUpperBand ) +/* Generated */ { +/* Generated */ tempBuffer1 = outRealMiddleBand; +/* Generated */ tempBuffer2 = outRealLowerBand; +/* Generated */ } +/* Generated */ else if( inReal == outRealLowerBand ) +/* Generated */ { +/* Generated */ tempBuffer1 = outRealMiddleBand; +/* Generated */ tempBuffer2 = outRealUpperBand; +/* Generated */ } +/* Generated */ else if( inReal == outRealMiddleBand ) +/* Generated */ { +/* Generated */ tempBuffer1 = outRealLowerBand; +/* Generated */ tempBuffer2 = outRealUpperBand; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ tempBuffer1 = outRealMiddleBand; +/* Generated */ tempBuffer2 = outRealUpperBand; +/* Generated */ } +/* Generated */ if( (tempBuffer1 == inReal) || (tempBuffer2 == inReal) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal, +/* Generated */ optInTimePeriod, optInMAType, +/* Generated */ outBegIdx, outNBElement, tempBuffer1 ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ if( optInMAType == ENUM_VALUE(MAType,TA_MAType_SMA,Sma) ) +/* Generated */ { +/* Generated */ FUNCTION_CALL(INT_stddev_using_precalc_ma)( inReal, tempBuffer1, +/* Generated */ (int)VALUE_HANDLE_DEREF(outBegIdx), (int)VALUE_HANDLE_DEREF(outNBElement), +/* Generated */ optInTimePeriod, tempBuffer2 ); +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ retCode = FUNCTION_CALL(STDDEV)( (int)VALUE_HANDLE_DEREF(outBegIdx), endIdx, inReal, +/* Generated */ optInTimePeriod, 1.0, +/* Generated */ outBegIdx, outNBElement, tempBuffer2 ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ } +/* Generated */ #if !defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ if( tempBuffer1 != outRealMiddleBand ) +/* Generated */ { +/* Generated */ ARRAY_COPY( outRealMiddleBand, tempBuffer1, VALUE_HANDLE_DEREF(outNBElement) ); +/* Generated */ } +/* Generated */ #endif +/* Generated */ if( optInNbDevUp == optInNbDevDn ) +/* Generated */ { +/* Generated */ if( optInNbDevUp == 1.0 ) +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = tempBuffer2[i]; +/* Generated */ tempReal2 = outRealMiddleBand[i]; +/* Generated */ outRealUpperBand[i] = tempReal2 + tempReal; +/* Generated */ outRealLowerBand[i] = tempReal2 - tempReal; +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = tempBuffer2[i] * optInNbDevUp; +/* Generated */ tempReal2 = outRealMiddleBand[i]; +/* Generated */ outRealUpperBand[i] = tempReal2 + tempReal; +/* Generated */ outRealLowerBand[i] = tempReal2 - tempReal; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( optInNbDevUp == 1.0 ) +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = tempBuffer2[i]; +/* Generated */ tempReal2 = outRealMiddleBand[i]; +/* Generated */ outRealUpperBand[i] = tempReal2 + tempReal; +/* Generated */ outRealLowerBand[i] = tempReal2 - (tempReal * optInNbDevDn); +/* Generated */ } +/* Generated */ } +/* Generated */ else if( optInNbDevDn == 1.0 ) +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = tempBuffer2[i]; +/* Generated */ tempReal2 = outRealMiddleBand[i]; +/* Generated */ outRealLowerBand[i] = tempReal2 - tempReal; +/* Generated */ outRealUpperBand[i] = tempReal2 + (tempReal * optInNbDevUp); +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = tempBuffer2[i]; +/* Generated */ tempReal2 = outRealMiddleBand[i]; +/* Generated */ outRealUpperBand[i] = tempReal2 + (tempReal * optInNbDevUp); +/* Generated */ outRealLowerBand[i] = tempReal2 - (tempReal * optInNbDevDn); +/* Generated */ } +/* Generated */ } +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_BETA.c b/talib/ta_func/ta_BETA.c new file mode 100644 index 0000000..df2d430 --- /dev/null +++ b/talib/ta_func/ta_BETA.c @@ -0,0 +1,494 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MW Michael Williamson + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 122006 MW Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::BetaLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int betaLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_BETA_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_BETA - Beta + * + * Input = double, double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Beta( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Beta( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode beta( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal0[], +/* Generated */ double inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_BETA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal0[], +/* Generated */ const double inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + double S_xx = 0.0f; /* sum of x * x */ + double S_xy = 0.0f; /* sum of x * y */ + double S_x = 0.0f; /* sum of x */ + double S_y = 0.0f; /* sum of y */ + double last_price_x = 0.0f; /* the last price read from inReal0 */ + double last_price_y = 0.0f; /* the last price read from inReal1 */ + double trailing_last_price_x = 0.0f; /* same as last_price_x except used to remove elements from the trailing summation */ + double trailing_last_price_y = 0.0f; /* same as last_price_y except used to remove elements from the trailing summation */ + double tmp_real = 0.0f; /* temporary variable */ + double x; /* the 'x' value, which is the last change between values in inReal0 */ + double y; /* the 'y' value, which is the last change between values in inReal1 */ + double n = 0.0f; + int i, outIdx; + int trailingIdx, nbInitialElementNeeded; + + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /** DESCRIPTION OF ALGORITHM: + * The Beta 'algorithm' is a measure of a stocks volatility vs from index. The stock prices + * are given in inReal0 and the index prices are give in inReal1. The size of these vectors + * should be equal. The algorithm is to calculate the change between prices in both vectors + * and then 'plot' these changes are points in the Euclidean plane. The x value of the point + * is market return and the y value is the security return. The beta value is the slope of a + * linear regression through these points. A beta of 1 is simple the line y=x, so the stock + * varies percisely with the market. A beta of less than one means the stock varies less than + * the market and a beta of more than one means the stock varies more than market. A related + * value is the Alpha value (see TA_ALPHA) which is the Y-intercept of the same linear regression. + */ + + /* Validate the calculation method type and + * identify the minimum number of input + * consume before the first value is output.. + */ + nbInitialElementNeeded = optInTimePeriod; + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Consume first input. */ + trailingIdx = startIdx-nbInitialElementNeeded; + last_price_x = trailing_last_price_x = inReal0[trailingIdx]; + last_price_y = trailing_last_price_y = inReal1[trailingIdx]; + + /* Process remaining of lookback until ready to output the first value. */ + i = ++trailingIdx; + + while( i < startIdx ) + { + tmp_real = inReal0[i]; + if( !TA_IS_ZERO(last_price_x) ) + x = (tmp_real-last_price_x)/last_price_x; + else + x = 0.0; + last_price_x = tmp_real; + + tmp_real = inReal1[i++]; + if( !TA_IS_ZERO(last_price_y) ) + y = (tmp_real-last_price_y)/last_price_y; + else + y = 0.0; + last_price_y = tmp_real; + + S_xx += x*x; + S_xy += x*y; + S_x += x; + S_y += y; + } + + + outIdx = 0; /* First output always start at index zero */ + n = (double)optInTimePeriod; + do + { + tmp_real = inReal0[i]; + if( !TA_IS_ZERO(last_price_x) ) + x = (tmp_real-last_price_x)/last_price_x; + else + x = 0.0; + last_price_x = tmp_real; + + tmp_real = inReal1[i++]; + if( !TA_IS_ZERO(last_price_y) ) + y = (tmp_real-last_price_y)/last_price_y; + else + y = 0.0; + last_price_y = tmp_real; + + S_xx += x*x; + S_xy += x*y; + S_x += x; + S_y += y; + + /* Always read the trailing before writing the output because the input and output + * buffer can be the same. + */ + tmp_real = inReal0[trailingIdx]; + if( !TA_IS_ZERO(trailing_last_price_x) ) + x = (tmp_real-trailing_last_price_x)/trailing_last_price_x; + else + x = 0.0; + trailing_last_price_x = tmp_real; + + tmp_real = inReal1[trailingIdx++]; + if( !TA_IS_ZERO(trailing_last_price_y) ) + y = (tmp_real-trailing_last_price_y)/trailing_last_price_y; + else + y = 0.0; + trailing_last_price_y = tmp_real; + + /* Write the output */ + tmp_real = (n * S_xx) - (S_x * S_x); + if( !TA_IS_ZERO(tmp_real) ) + outReal[outIdx++] = ((n * S_xy) - (S_x * S_y)) / tmp_real; + else + outReal[outIdx++] = 0.0; + + /* Remove the calculation starting with the trailingIdx. */ + S_xx -= x*x; + S_xy -= x*y; + S_x -= x; + S_y -= y; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Beta( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Beta( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode beta( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal0[], +/* Generated */ float inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_BETA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal0[], +/* Generated */ const float inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double S_xx = 0.0f; +/* Generated */ double S_xy = 0.0f; +/* Generated */ double S_x = 0.0f; +/* Generated */ double S_y = 0.0f; +/* Generated */ double last_price_x = 0.0f; +/* Generated */ double last_price_y = 0.0f; +/* Generated */ double trailing_last_price_x = 0.0f; +/* Generated */ double trailing_last_price_y = 0.0f; +/* Generated */ double tmp_real = 0.0f; +/* Generated */ double x; +/* Generated */ double y; +/* Generated */ double n = 0.0f; +/* Generated */ int i, outIdx; +/* Generated */ int trailingIdx, nbInitialElementNeeded; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = optInTimePeriod; +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ last_price_x = trailing_last_price_x = inReal0[trailingIdx]; +/* Generated */ last_price_y = trailing_last_price_y = inReal1[trailingIdx]; +/* Generated */ i = ++trailingIdx; +/* Generated */ while( i < startIdx ) +/* Generated */ { +/* Generated */ tmp_real = inReal0[i]; +/* Generated */ if( !TA_IS_ZERO(last_price_x) ) +/* Generated */ x = (tmp_real-last_price_x)/last_price_x; +/* Generated */ else +/* Generated */ x = 0.0; +/* Generated */ last_price_x = tmp_real; +/* Generated */ tmp_real = inReal1[i++]; +/* Generated */ if( !TA_IS_ZERO(last_price_y) ) +/* Generated */ y = (tmp_real-last_price_y)/last_price_y; +/* Generated */ else +/* Generated */ y = 0.0; +/* Generated */ last_price_y = tmp_real; +/* Generated */ S_xx += x*x; +/* Generated */ S_xy += x*y; +/* Generated */ S_x += x; +/* Generated */ S_y += y; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ n = (double)optInTimePeriod; +/* Generated */ do +/* Generated */ { +/* Generated */ tmp_real = inReal0[i]; +/* Generated */ if( !TA_IS_ZERO(last_price_x) ) +/* Generated */ x = (tmp_real-last_price_x)/last_price_x; +/* Generated */ else +/* Generated */ x = 0.0; +/* Generated */ last_price_x = tmp_real; +/* Generated */ tmp_real = inReal1[i++]; +/* Generated */ if( !TA_IS_ZERO(last_price_y) ) +/* Generated */ y = (tmp_real-last_price_y)/last_price_y; +/* Generated */ else +/* Generated */ y = 0.0; +/* Generated */ last_price_y = tmp_real; +/* Generated */ S_xx += x*x; +/* Generated */ S_xy += x*y; +/* Generated */ S_x += x; +/* Generated */ S_y += y; +/* Generated */ tmp_real = inReal0[trailingIdx]; +/* Generated */ if( !TA_IS_ZERO(trailing_last_price_x) ) +/* Generated */ x = (tmp_real-trailing_last_price_x)/trailing_last_price_x; +/* Generated */ else +/* Generated */ x = 0.0; +/* Generated */ trailing_last_price_x = tmp_real; +/* Generated */ tmp_real = inReal1[trailingIdx++]; +/* Generated */ if( !TA_IS_ZERO(trailing_last_price_y) ) +/* Generated */ y = (tmp_real-trailing_last_price_y)/trailing_last_price_y; +/* Generated */ else +/* Generated */ y = 0.0; +/* Generated */ trailing_last_price_y = tmp_real; +/* Generated */ tmp_real = (n * S_xx) - (S_x * S_x); +/* Generated */ if( !TA_IS_ZERO(tmp_real) ) +/* Generated */ outReal[outIdx++] = ((n * S_xy) - (S_x * S_y)) / tmp_real; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ S_xx -= x*x; +/* Generated */ S_xy -= x*y; +/* Generated */ S_x -= x; +/* Generated */ S_y -= y; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_BOP.c b/talib/ta_func/ta_BOP.c new file mode 100644 index 0000000..4725712 --- /dev/null +++ b/talib/ta_func/ta_BOP.c @@ -0,0 +1,290 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112605 MF Initial coding. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::BopLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int bopLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_BOP_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_BOP - Balance Of Power + * + * Input = Open, High, Low, Close + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Bop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Bop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode bop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_BOP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx, i; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* BOP = (Close - Open)/(High - Low) */ + + outIdx = 0; + + for( i=startIdx; i <= endIdx; i++ ) + { + tempReal = inHigh[i]-inLow[i]; + if( TA_IS_ZERO_OR_NEG(tempReal) ) + outReal[outIdx++] = 0.0; + else + outReal[outIdx++] = (inClose[i] - inOpen[i])/tempReal; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Bop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Bop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode bop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_BOP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ for( i=startIdx; i <= endIdx; i++ ) +/* Generated */ { +/* Generated */ tempReal = inHigh[i]-inLow[i]; +/* Generated */ if( TA_IS_ZERO_OR_NEG(tempReal) ) +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = (inClose[i] - inOpen[i])/tempReal; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CCI.c b/talib/ta_func/ta_CCI.c new file mode 100644 index 0000000..de895c5 --- /dev/null +++ b/talib/ta_func/ta_CCI.c @@ -0,0 +1,427 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 031202 MF Template creation. + * 052603 MF Port to managed C++. Change to use CIRCBUF macros. + * 061704 MF Lower limit for period to 2, and correct algorithm + * to avoid cummulative error when value are close to + * the floating point epsilon. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CciLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cciLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CCI_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CCI - Commodity Channel Index + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cci( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cci( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cci( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CCI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + + /* insert local variable here */ + double tempReal, tempReal2, theAverage, lastValue; + int i, j, outIdx, lookbackTotal; + + /* This ptr will points on a circular buffer of + * at least "optInTimePeriod" element. + */ + CIRCBUF_PROLOG(circBuffer,double,30); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Allocate a circular buffer equal to the requested + * period. + */ + CIRCBUF_INIT( circBuffer, double, optInTimePeriod ); + + /* Do the MA calculation using tight loops. */ + + /* Add-up the initial period, except for the last value. + * Fill up the circular buffer at the same time. + */ + i=startIdx-lookbackTotal; + if( optInTimePeriod > 1 ) + { + while( i < startIdx ) + { + circBuffer[circBuffer_Idx] = (inHigh[i]+inLow[i]+inClose[i])/3; + i++; + CIRCBUF_NEXT(circBuffer); + } + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the inReal and + * outReal to be the same buffer. + */ + outIdx = 0; + do + { + lastValue = (inHigh[i]+inLow[i]+inClose[i])/3; + circBuffer[circBuffer_Idx] = lastValue; + + /* Calculate the average for the whole period. */ + theAverage = 0; + for( j=0; j < optInTimePeriod; j++ ) + theAverage += circBuffer[j]; + theAverage /= optInTimePeriod; + + /* Do the summation of the ABS(TypePrice-average) + * for the whole period. + */ + tempReal2 = 0; + for( j=0; j < optInTimePeriod; j++ ) + tempReal2 += std_fabs(circBuffer[j]-theAverage); + + /* And finally, the CCI... */ + tempReal = lastValue-theAverage; + + if( (tempReal != 0.0) && (tempReal2 != 0.0) ) + { + outReal[outIdx++] = tempReal/(0.015*(tempReal2/optInTimePeriod)); + } + else + outReal[outIdx++] = 0.0; + + /* Move forward the circular buffer indexes. */ + CIRCBUF_NEXT(circBuffer); + + i++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Free the circular buffer if it was dynamically allocated. */ + CIRCBUF_DESTROY(circBuffer); + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cci( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cci( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cci( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CCI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double tempReal, tempReal2, theAverage, lastValue; +/* Generated */ int i, j, outIdx, lookbackTotal; +/* Generated */ CIRCBUF_PROLOG(circBuffer,double,30); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = (optInTimePeriod-1); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ CIRCBUF_INIT( circBuffer, double, optInTimePeriod ); +/* Generated */ i=startIdx-lookbackTotal; +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ { +/* Generated */ while( i < startIdx ) +/* Generated */ { +/* Generated */ circBuffer[circBuffer_Idx] = (inHigh[i]+inLow[i]+inClose[i])/3; +/* Generated */ i++; +/* Generated */ CIRCBUF_NEXT(circBuffer); +/* Generated */ } +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ lastValue = (inHigh[i]+inLow[i]+inClose[i])/3; +/* Generated */ circBuffer[circBuffer_Idx] = lastValue; +/* Generated */ theAverage = 0; +/* Generated */ for( j=0; j < optInTimePeriod; j++ ) +/* Generated */ theAverage += circBuffer[j]; +/* Generated */ theAverage /= optInTimePeriod; +/* Generated */ tempReal2 = 0; +/* Generated */ for( j=0; j < optInTimePeriod; j++ ) +/* Generated */ tempReal2 += std_fabs(circBuffer[j]-theAverage); +/* Generated */ tempReal = lastValue-theAverage; +/* Generated */ if( (tempReal != 0.0) && (tempReal2 != 0.0) ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = tempReal/(0.015*(tempReal2/optInTimePeriod)); +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ CIRCBUF_NEXT(circBuffer); +/* Generated */ i++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ CIRCBUF_DESTROY(circBuffer); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL2CROWS.c b/talib/ta_func/ta_CDL2CROWS.c new file mode 100644 index 0000000..81018e7 --- /dev/null +++ b/talib/ta_func/ta_CDL2CROWS.c @@ -0,0 +1,374 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl2CrowsLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl2CrowsLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL2CROWS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(BodyLong) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL2CROWS - Two Crows + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL2CROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal; + int i, outIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL2CROWS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white candle + * - second candle: black real body + * - gap between the first and the second candle's real bodies + * - third candle: black candle that opens within the second real body and closes within the first real body + * The meaning of "long" is specified with TA_SetCandleSettings + * outInteger is negative (-1 to -100): two crows is always bearish; + * the user should consider that two crows is significant when it appears in an uptrend, while this function + * does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-2) == 1 && // 1st: white + TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // long + TA_CANDLECOLOR(i-1) == -1 && // 2nd: black + TA_REALBODYGAPUP(i-1,i-2) && // gapping up + TA_CANDLECOLOR(i) == -1 && // 3rd: black + inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // opening within 2nd rb + inClose[i] > inOpen[i-2] && inClose[i] < inClose[i-2] // closing within 1st rb + ) +#endif + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + i++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL2CROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL2CROWS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-2) == 1 && // 1st: white +/* Generated */ TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // long +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd: black +/* Generated */ TA_REALBODYGAPUP(i-1,i-2) && // gapping up +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd: black +/* Generated */ inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // opening within 2nd rb +/* Generated */ inClose[i] > inOpen[i-2] && inClose[i] < inClose[i-2] // closing within 1st rb +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL3BLACKCROWS.c b/talib/ta_func/ta_CDL3BLACKCROWS.c new file mode 100644 index 0000000..685b3f3 --- /dev/null +++ b/talib/ta_func/ta_CDL3BLACKCROWS.c @@ -0,0 +1,402 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 103004 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl3BlackCrowsLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl3BlackCrowsLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL3BLACKCROWS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(ShadowVeryShort) + 3; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL3BLACKCROWS - Three Black Crows + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3BlackCrows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3BlackCrows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3BlackCrows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL3BLACKCROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3); + int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL3BLACKCROWS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal[2] = 0; + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortPeriodTotal[0] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - three consecutive and declining black candlesticks + * - each candle must have no or very short lower shadow + * - each candle after the first must open within the prior candle's real body + * - the first candle's close should be under the prior white candle's high + * The meaning of "very short" is specified with TA_SetCandleSettings + * outInteger is negative (-1 to -100): three black crows is always bearish; + * the user should consider that 3 black crows is significant when it appears after a mature advance or at high levels, + * while this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-3) == 1 && // white + TA_CANDLECOLOR(i-2) == -1 && // 1st black + TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && + // very short lower shadow + TA_CANDLECOLOR(i-1) == -1 && // 2nd black + TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + // very short lower shadow + TA_CANDLECOLOR(i) == -1 && // 3rd black + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + // very short lower shadow + inOpen[i-1] < inOpen[i-2] && inOpen[i-1] > inClose[i-2] && // 2nd black opens within 1st black's rb + inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // 3rd black opens within 2nd black's rb + inHigh[i-3] > inClose[i-2] && // 1st black closes under prior candle's high + inClose[i-2] > inClose[i-1] && // three declining + inClose[i-1] > inClose[i] // three declining + ) +#endif + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 2; totIdx >= 0; --totIdx) + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + i++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3BlackCrows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3BlackCrows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3BlackCrows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL3BLACKCROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3); +/* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL3BLACKCROWS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal[2] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[0] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-3) == 1 && // white +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // 1st black +/* Generated */ TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && +/* Generated */ // very short lower shadow +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd black +/* Generated */ TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ // very short lower shadow +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd black +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ // very short lower shadow +/* Generated */ inOpen[i-1] < inOpen[i-2] && inOpen[i-1] > inClose[i-2] && // 2nd black opens within 1st black's rb +/* Generated */ inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // 3rd black opens within 2nd black's rb +/* Generated */ inHigh[i-3] > inClose[i-2] && // 1st black closes under prior candle's high +/* Generated */ inClose[i-2] > inClose[i-1] && // three declining +/* Generated */ inClose[i-1] > inClose[i] // three declining +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ for (totIdx = 2; totIdx >= 0; --totIdx) +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL3INSIDE.c b/talib/ta_func/ta_CDL3INSIDE.c new file mode 100644 index 0000000..5f77ff1 --- /dev/null +++ b/talib/ta_func/ta_CDL3INSIDE.c @@ -0,0 +1,393 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl3InsideLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl3InsideLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL3INSIDE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL3INSIDE - Three Inside Up/Down + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3Inside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3Inside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3Inside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL3INSIDE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL3INSIDE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx-1 ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white (black) real body + * - second candle: short real body totally engulfed by the first + * - third candle: black (white) candle that closes lower (higher) than the first candle's open + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) for the three inside up or negative (-1 to -100) for the three inside down; + * the user should consider that a three inside up is significant when it appears in a downtrend and a three inside + * down is significant when it appears in an uptrend, while this function does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // 2nd: short + max( inClose[i-1], inOpen[i-1] ) < max( inClose[i-2], inOpen[i-2] ) && // engulfed by 1st + min( inClose[i-1], inOpen[i-1] ) > min( inClose[i-2], inOpen[i-2] ) && + ( ( TA_CANDLECOLOR(i-2) == 1 && TA_CANDLECOLOR(i) == -1 && inClose[i] < inOpen[i-2] ) // 3rd: opposite to 1st + || // and closing out + ( TA_CANDLECOLOR(i-2) == -1 && TA_CANDLECOLOR(i) == 1 && inClose[i] > inOpen[i-2] ) + ) + ) +#endif + outInteger[outIdx++] = -TA_CANDLECOLOR(i-2) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3Inside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3Inside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3Inside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL3INSIDE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL3INSIDE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // 2nd: short +/* Generated */ max( inClose[i-1], inOpen[i-1] ) < max( inClose[i-2], inOpen[i-2] ) && // engulfed by 1st +/* Generated */ min( inClose[i-1], inOpen[i-1] ) > min( inClose[i-2], inOpen[i-2] ) && +/* Generated */ ( ( TA_CANDLECOLOR(i-2) == 1 && TA_CANDLECOLOR(i) == -1 && inClose[i] < inOpen[i-2] ) // 3rd: opposite to 1st +/* Generated */ || // and closing out +/* Generated */ ( TA_CANDLECOLOR(i-2) == -1 && TA_CANDLECOLOR(i) == 1 && inClose[i] > inOpen[i-2] ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = -TA_CANDLECOLOR(i-2) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL3LINESTRIKE.c b/talib/ta_func/ta_CDL3LINESTRIKE.c new file mode 100644 index 0000000..7cb8c1b --- /dev/null +++ b/talib/ta_func/ta_CDL3LINESTRIKE.c @@ -0,0 +1,414 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl3LineStrikeLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl3LineStrikeLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL3LINESTRIKE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(Near) + 3; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL3LINESTRIKE - Three-Line Strike + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3LineStrike( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3LineStrike( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3LineStrike( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL3LINESTRIKE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(NearPeriodTotal,4); + int i, outIdx, totIdx, NearTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL3LINESTRIKE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + NearPeriodTotal[3] = 0; + NearPeriodTotal[2] = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal[3] += TA_CANDLERANGE( Near, i-3 ); + NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - three white soldiers (three black crows): three white (black) candlesticks with consecutively higher (lower) closes, + * each opening within or near the previous real body + * - fourth candle: black (white) candle that opens above (below) prior candle's close and closes below (above) + * the first candle's open + * The meaning of "near" is specified with TA_SetCandleSettings; + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that 3-line strike is significant when it appears in a trend in the same direction of + * the first three candles, while this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-3) == TA_CANDLECOLOR(i-2) && // three with same color + TA_CANDLECOLOR(i-2) == TA_CANDLECOLOR(i-1) && + TA_CANDLECOLOR(i) == -TA_CANDLECOLOR(i-1) && // 4th opposite color + // 2nd opens within/near 1st rb + inOpen[i-2] >= min( inOpen[i-3], inClose[i-3] ) - TA_CANDLEAVERAGE( Near, NearPeriodTotal[3], i-3 ) && + inOpen[i-2] <= max( inOpen[i-3], inClose[i-3] ) + TA_CANDLEAVERAGE( Near, NearPeriodTotal[3], i-3 ) && + // 3rd opens within/near 2nd rb + inOpen[i-1] >= min( inOpen[i-2], inClose[i-2] ) - TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && + inOpen[i-1] <= max( inOpen[i-2], inClose[i-2] ) + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && + ( + ( // if three white + TA_CANDLECOLOR(i-1) == 1 && + inClose[i-1] > inClose[i-2] && inClose[i-2] > inClose[i-3] && // consecutive higher closes + inOpen[i] > inClose[i-1] && // 4th opens above prior close + inClose[i] < inOpen[i-3] // 4th closes below 1st open + ) || + ( // if three black + TA_CANDLECOLOR(i-1) == -1 && + inClose[i-1] < inClose[i-2] && inClose[i-2] < inClose[i-3] && // consecutive lower closes + inOpen[i] < inClose[i-1] && // 4th opens below prior close + inClose[i] > inOpen[i-3] // 4th closes above 1st open + ) + ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i-1) * 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 3; totIdx >= 2; --totIdx) + NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) + - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); + i++; + NearTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3LineStrike( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3LineStrike( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3LineStrike( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL3LINESTRIKE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(NearPeriodTotal,4); +/* Generated */ int i, outIdx, totIdx, NearTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL3LINESTRIKE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ NearPeriodTotal[3] = 0; +/* Generated */ NearPeriodTotal[2] = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal[3] += TA_CANDLERANGE( Near, i-3 ); +/* Generated */ NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-3) == TA_CANDLECOLOR(i-2) && // three with same color +/* Generated */ TA_CANDLECOLOR(i-2) == TA_CANDLECOLOR(i-1) && +/* Generated */ TA_CANDLECOLOR(i) == -TA_CANDLECOLOR(i-1) && // 4th opposite color +/* Generated */ // 2nd opens within/near 1st rb +/* Generated */ inOpen[i-2] >= min( inOpen[i-3], inClose[i-3] ) - TA_CANDLEAVERAGE( Near, NearPeriodTotal[3], i-3 ) && +/* Generated */ inOpen[i-2] <= max( inOpen[i-3], inClose[i-3] ) + TA_CANDLEAVERAGE( Near, NearPeriodTotal[3], i-3 ) && +/* Generated */ // 3rd opens within/near 2nd rb +/* Generated */ inOpen[i-1] >= min( inOpen[i-2], inClose[i-2] ) - TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && +/* Generated */ inOpen[i-1] <= max( inOpen[i-2], inClose[i-2] ) + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && +/* Generated */ ( +/* Generated */ ( // if three white +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && +/* Generated */ inClose[i-1] > inClose[i-2] && inClose[i-2] > inClose[i-3] && // consecutive higher closes +/* Generated */ inOpen[i] > inClose[i-1] && // 4th opens above prior close +/* Generated */ inClose[i] < inOpen[i-3] // 4th closes below 1st open +/* Generated */ ) || +/* Generated */ ( // if three black +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && +/* Generated */ inClose[i-1] < inClose[i-2] && inClose[i-2] < inClose[i-3] && // consecutive lower closes +/* Generated */ inOpen[i] < inClose[i-1] && // 4th opens below prior close +/* Generated */ inClose[i] > inOpen[i-3] // 4th closes above 1st open +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i-1) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ for (totIdx = 3; totIdx >= 2; --totIdx) +/* Generated */ NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ NearTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL3OUTSIDE.c b/talib/ta_func/ta_CDL3OUTSIDE.c new file mode 100644 index 0000000..abc79d9 --- /dev/null +++ b/talib/ta_func/ta_CDL3OUTSIDE.c @@ -0,0 +1,356 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl3OutsideLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl3OutsideLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL3OUTSIDE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return 3; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL3OUTSIDE - Three Outside Up/Down + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3Outside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3Outside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3Outside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL3OUTSIDE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int i, outIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL3OUTSIDE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first: black (white) real body + * - second: white (black) real body that engulfs the prior real body + * - third: candle that closes higher (lower) than the second candle + * outInteger is positive (1 to 100) for the three outside up or negative (-1 to -100) for the three outside down; + * the user should consider that a three outside up must appear in a downtrend and three outside down must appear + * in an uptrend, while this function does not consider it + */ + outIdx = 0; + do + { + if( ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLECOLOR(i-2) == -1 && // white engulfs black + inClose[i-1] > inOpen[i-2] && inOpen[i-1] < inClose[i-2] && + inClose[i] > inClose[i-1] // third candle higher + ) + || + ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLECOLOR(i-2) == 1 && // black engulfs white + inOpen[i-1] > inClose[i-2] && inClose[i-1] < inOpen[i-2] && + inClose[i] < inClose[i-1] // third candle lower + ) + ) + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + outInteger[outIdx++] = TA_CANDLECOLOR(i-1) * 100; +#endif + } + else + outInteger[outIdx++] = 0; + i++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3Outside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3Outside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3Outside( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL3OUTSIDE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i, outIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL3OUTSIDE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLECOLOR(i-2) == -1 && // white engulfs black +/* Generated */ inClose[i-1] > inOpen[i-2] && inOpen[i-1] < inClose[i-2] && +/* Generated */ inClose[i] > inClose[i-1] // third candle higher +/* Generated */ ) +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLECOLOR(i-2) == 1 && // black engulfs white +/* Generated */ inOpen[i-1] > inClose[i-2] && inClose[i-1] < inOpen[i-2] && +/* Generated */ inClose[i] < inClose[i-1] // third candle lower +/* Generated */ ) +/* Generated */ ) +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i-1) * 100; +/* Generated */ #endif +/* Generated */ } +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ i++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL3STARSINSOUTH.c b/talib/ta_func/ta_CDL3STARSINSOUTH.c new file mode 100644 index 0000000..1ed96ac --- /dev/null +++ b/talib/ta_func/ta_CDL3STARSINSOUTH.c @@ -0,0 +1,470 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 022705 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl3StarsInSouthLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl3StarsInSouthLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL3STARSINSOUTH_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(ShadowLong) ), + max( TA_CANDLEAVGPERIOD(BodyLong), TA_CANDLEAVGPERIOD(BodyShort) ) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL3STARSINSOUTH - Three Stars In The South + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3StarsInSouth( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3StarsInSouth( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3StarsInSouth( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL3STARSINSOUTH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal, BodyShortPeriodTotal, ShadowLongPeriodTotal; + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2); + int i, outIdx, totIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, + lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL3STARSINSOUTH)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortPeriodTotal[0] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + BodyShortPeriodTotal = 0; + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i-2 ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle with long lower shadow + * - second candle: smaller black candle that opens higher than prior close but within prior candle's range + * and trades lower than prior close but not lower than prior low and closes off of its low (it has a shadow) + * - third candle: small black marubozu (or candle with very short shadows) engulfed by prior candle's range + * The meanings of "long body", "short body", "very short shadow" are specified with TA_SetCandleSettings; + * outInteger is positive (1 to 100): 3 stars in the south is always bullish; + * the user should consider that 3 stars in the south is significant when it appears in downtrend, while this function + * does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-2) == -1 && // 1st black + TA_CANDLECOLOR(i-1) == -1 && // 2nd black + TA_CANDLECOLOR(i) == -1 && // 3rd black + // 1st: long + TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && + // with long lower shadow + TA_LOWERSHADOW(i-2) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i-2 ) && + TA_REALBODY(i-1) < TA_REALBODY(i-2) && // 2nd: smaller candle + inOpen[i-1] > inClose[i-2] && inOpen[i-1] <= inHigh[i-2] && // that opens higher but within 1st range + inLow[i-1] < inClose[i-2] && // and trades lower than 1st close + inLow[i-1] >= inLow[i-2] && // but not lower than 1st low + // and has a lower shadow + TA_LOWERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + // 3rd: small marubozu + TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + inLow[i] > inLow[i-1] && inHigh[i] < inHigh[i-1] // engulfed by prior candle's range + ) +#endif + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-2 ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i-2 ) + - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx-2 ); + for (totIdx = 1; totIdx >= 0; --totIdx) + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) + - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + ShadowLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3StarsInSouth( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3StarsInSouth( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3StarsInSouth( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL3STARSINSOUTH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal, BodyShortPeriodTotal, ShadowLongPeriodTotal; +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2); +/* Generated */ int i, outIdx, totIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, +/* Generated */ lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL3STARSINSOUTH)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[0] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i-2 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-2) == -1 && // 1st black +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd black +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd black +/* Generated */ // 1st: long +/* Generated */ TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && +/* Generated */ // with long lower shadow +/* Generated */ TA_LOWERSHADOW(i-2) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i-2 ) && +/* Generated */ TA_REALBODY(i-1) < TA_REALBODY(i-2) && // 2nd: smaller candle +/* Generated */ inOpen[i-1] > inClose[i-2] && inOpen[i-1] <= inHigh[i-2] && // that opens higher but within 1st range +/* Generated */ inLow[i-1] < inClose[i-2] && // and trades lower than 1st close +/* Generated */ inLow[i-1] >= inLow[i-2] && // but not lower than 1st low +/* Generated */ // and has a lower shadow +/* Generated */ TA_LOWERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ // 3rd: small marubozu +/* Generated */ TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ inLow[i] > inLow[i-1] && inHigh[i] < inHigh[i-1] // engulfed by prior candle's range +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-2 ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i-2 ) +/* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx-2 ); +/* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDL3WHITESOLDIERS.c b/talib/ta_func/ta_CDL3WHITESOLDIERS.c new file mode 100644 index 0000000..ed9a985 --- /dev/null +++ b/talib/ta_func/ta_CDL3WHITESOLDIERS.c @@ -0,0 +1,494 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120404 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Cdl3WhiteSoldiersLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdl3WhiteSoldiersLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDL3WHITESOLDIERS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(BodyShort) ), + max( TA_CANDLEAVGPERIOD(Far), TA_CANDLEAVGPERIOD(Near) ) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDL3WHITESOLDIERS - Three Advancing White Soldiers + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3WhiteSoldiers( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3WhiteSoldiers( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3WhiteSoldiers( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDL3WHITESOLDIERS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3); + ARRAY_LOCAL(NearPeriodTotal,3); + ARRAY_LOCAL(FarPeriodTotal,3); + double BodyShortPeriodTotal; + int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, FarTrailingIdx, BodyShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDL3WHITESOLDIERS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal[2] = 0; + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortPeriodTotal[0] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + NearPeriodTotal[2] = 0; + NearPeriodTotal[1] = 0; + NearPeriodTotal[0] = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + FarPeriodTotal[2] = 0; + FarPeriodTotal[1] = 0; + FarPeriodTotal[0] = 0; + FarTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Far); + BodyShortPeriodTotal = 0; + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); + NearPeriodTotal[1] += TA_CANDLERANGE( Near, i-1 ); + i++; + } + i = FarTrailingIdx; + while( i < startIdx ) { + FarPeriodTotal[2] += TA_CANDLERANGE( Far, i-2 ); + FarPeriodTotal[1] += TA_CANDLERANGE( Far, i-1 ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - three white candlesticks with consecutively higher closes + * - Greg Morris wants them to be long, Steve Nison doesn't; anyway they should not be short + * - each candle opens within or near the previous white real body + * - each candle must have no or very short upper shadow + * - to differentiate this pattern from advance block, each candle must not be far shorter than the prior candle + * The meanings of "not short", "very short shadow", "far" and "near" are specified with TA_SetCandleSettings; + * here the 3 candles must be not short, if you want them to be long use TA_SetCandleSettings on BodyShort; + * outInteger is positive (1 to 100): advancing 3 white soldiers is always bullish; + * the user should consider that 3 white soldiers is significant when it appears in downtrend, while this function + * does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-2) == 1 && // 1st white + TA_UPPERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && + // very short upper shadow + TA_CANDLECOLOR(i-1) == 1 && // 2nd white + TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + // very short upper shadow + TA_CANDLECOLOR(i) == 1 && // 3rd white + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + // very short upper shadow + inClose[i] > inClose[i-1] && inClose[i-1] > inClose[i-2] && // consecutive higher closes + inOpen[i-1] > inOpen[i-2] && // 2nd opens within/near 1st real body + inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && + inOpen[i] > inOpen[i-1] && // 3rd opens within/near 2nd real body + inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) && + TA_REALBODY(i-1) > TA_REALBODY(i-2) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[2], i-2 ) && + // 2nd not far shorter than 1st + TA_REALBODY(i) > TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[1], i-1 ) && + // 3rd not far shorter than 2nd + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) // not short real body + ) +#endif + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 2; totIdx >= 0; --totIdx) + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + for (totIdx = 2; totIdx >= 1; --totIdx) { + FarPeriodTotal[totIdx] += TA_CANDLERANGE( Far, i-totIdx ) + - TA_CANDLERANGE( Far, FarTrailingIdx-totIdx ); + NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) + - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); + } + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + ShadowVeryShortTrailingIdx++; + NearTrailingIdx++; + FarTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cdl3WhiteSoldiers( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cdl3WhiteSoldiers( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdl3WhiteSoldiers( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDL3WHITESOLDIERS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3); +/* Generated */ ARRAY_LOCAL(NearPeriodTotal,3); +/* Generated */ ARRAY_LOCAL(FarPeriodTotal,3); +/* Generated */ double BodyShortPeriodTotal; +/* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, FarTrailingIdx, BodyShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDL3WHITESOLDIERS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal[2] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[0] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ NearPeriodTotal[2] = 0; +/* Generated */ NearPeriodTotal[1] = 0; +/* Generated */ NearPeriodTotal[0] = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ FarPeriodTotal[2] = 0; +/* Generated */ FarPeriodTotal[1] = 0; +/* Generated */ FarPeriodTotal[0] = 0; +/* Generated */ FarTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Far); +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); +/* Generated */ NearPeriodTotal[1] += TA_CANDLERANGE( Near, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = FarTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ FarPeriodTotal[2] += TA_CANDLERANGE( Far, i-2 ); +/* Generated */ FarPeriodTotal[1] += TA_CANDLERANGE( Far, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-2) == 1 && // 1st white +/* Generated */ TA_UPPERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && +/* Generated */ // very short upper shadow +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && // 2nd white +/* Generated */ TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ // very short upper shadow +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 3rd white +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ // very short upper shadow +/* Generated */ inClose[i] > inClose[i-1] && inClose[i-1] > inClose[i-2] && // consecutive higher closes +/* Generated */ inOpen[i-1] > inOpen[i-2] && // 2nd opens within/near 1st real body +/* Generated */ inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && +/* Generated */ inOpen[i] > inOpen[i-1] && // 3rd opens within/near 2nd real body +/* Generated */ inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) && +/* Generated */ TA_REALBODY(i-1) > TA_REALBODY(i-2) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[2], i-2 ) && +/* Generated */ // 2nd not far shorter than 1st +/* Generated */ TA_REALBODY(i) > TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[1], i-1 ) && +/* Generated */ // 3rd not far shorter than 2nd +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) // not short real body +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ for (totIdx = 2; totIdx >= 0; --totIdx) +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ for (totIdx = 2; totIdx >= 1; --totIdx) { +/* Generated */ FarPeriodTotal[totIdx] += TA_CANDLERANGE( Far, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Far, FarTrailingIdx-totIdx ); +/* Generated */ NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); +/* Generated */ } +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ NearTrailingIdx++; +/* Generated */ FarTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLABANDONEDBABY.c b/talib/ta_func/ta_CDLABANDONEDBABY.c new file mode 100644 index 0000000..f1df52e --- /dev/null +++ b/talib/ta_func/ta_CDLABANDONEDBABY.c @@ -0,0 +1,477 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 102304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlAbandonedBabyLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlAbandonedBabyLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLABANDONEDBABY_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + + return max( max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(BodyLong) ), + TA_CANDLEAVGPERIOD(BodyShort) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLABANDONEDBABY - Abandoned Baby + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlAbandonedBaby( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlAbandonedBaby( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlAbandonedBaby( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLABANDONEDBABY( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLABANDONEDBABY)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyDojiPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji); + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyDojiTrailingIdx; + while( i < startIdx-1 ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white (black) real body + * - second candle: doji + * - third candle: black (white) real body that moves well within the first candle's real body + * - upside (downside) gap between the first candle and the doji (the shadows of the two candles don't touch) + * - downside (upside) gap between the doji and the third candle (the shadows of the two candles don't touch) + * The meaning of "doji" and "long" is specified with TA_SetCandleSettings + * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should + * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want + * it to be relatively long + * outInteger is positive (1 to 100) when it's an abandoned baby bottom or negative (-1 to -100) when it's + * an abandoned baby top; the user should consider that an abandoned baby is significant when it appears in + * an uptrend or downtrend, while this function does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short + ( ( TA_CANDLECOLOR(i-2) == 1 && // 1st white + TA_CANDLECOLOR(i) == -1 && // 3rd black + inClose[i] < inClose[i-2] - TA_REALBODY(i-2) * optInPenetration && // 3rd closes well within 1st rb + TA_CANDLEGAPUP(i-1,i-2) && // upside gap between 1st and 2nd + TA_CANDLEGAPDOWN(i,i-1) // downside gap between 2nd and 3rd + ) + || + ( + TA_CANDLECOLOR(i-2) == -1 && // 1st black + TA_CANDLECOLOR(i) == 1 && // 3rd white + inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration && // 3rd closes well within 1st rb + TA_CANDLEGAPDOWN(i-1,i-2) && // downside gap between 1st and 2nd + TA_CANDLEGAPUP(i,i-1) // upside gap between 2nd and 3rd + ) + ) + ) + { + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + } + else + { + outInteger[outIdx++] = 0; + } +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyDojiTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlAbandonedBaby( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlAbandonedBaby( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlAbandonedBaby( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLABANDONEDBABY( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLABANDONEDBABY)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short +/* Generated */ ( ( TA_CANDLECOLOR(i-2) == 1 && // 1st white +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd black +/* Generated */ inClose[i] < inClose[i-2] - TA_REALBODY(i-2) * optInPenetration && // 3rd closes well within 1st rb +/* Generated */ TA_CANDLEGAPUP(i-1,i-2) && // upside gap between 1st and 2nd +/* Generated */ TA_CANDLEGAPDOWN(i,i-1) // downside gap between 2nd and 3rd +/* Generated */ ) +/* Generated */ || +/* Generated */ ( +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // 1st black +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 3rd white +/* Generated */ inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration && // 3rd closes well within 1st rb +/* Generated */ TA_CANDLEGAPDOWN(i-1,i-2) && // downside gap between 1st and 2nd +/* Generated */ TA_CANDLEGAPUP(i,i-1) // upside gap between 2nd and 3rd +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ { +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ } +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLADVANCEBLOCK.c b/talib/ta_func/ta_CDLADVANCEBLOCK.c new file mode 100644 index 0000000..3aefcae --- /dev/null +++ b/talib/ta_func/ta_CDLADVANCEBLOCK.c @@ -0,0 +1,566 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120404 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlAdvanceBlockLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlAdvanceBlockLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLADVANCEBLOCK_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( max( TA_CANDLEAVGPERIOD(ShadowLong), TA_CANDLEAVGPERIOD(ShadowShort) ), + max( TA_CANDLEAVGPERIOD(Far), TA_CANDLEAVGPERIOD(Near) ) ), + TA_CANDLEAVGPERIOD(BodyLong) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLADVANCEBLOCK - Advance Block + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlAdvanceBlock( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlAdvanceBlock( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlAdvanceBlock( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLADVANCEBLOCK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowShortPeriodTotal,3); + ARRAY_LOCAL(ShadowLongPeriodTotal,2); + ARRAY_LOCAL(NearPeriodTotal,3); + ARRAY_LOCAL(FarPeriodTotal,3); + double BodyLongPeriodTotal; + int i, outIdx, totIdx, BodyLongTrailingIdx, ShadowShortTrailingIdx, ShadowLongTrailingIdx, NearTrailingIdx, + FarTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLADVANCEBLOCK)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowShortPeriodTotal[2] = 0; + ShadowShortPeriodTotal[1] = 0; + ShadowShortPeriodTotal[0] = 0; + ShadowShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowShort); + ShadowLongPeriodTotal[1] = 0; + ShadowLongPeriodTotal[0] = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + NearPeriodTotal[2] = 0; + NearPeriodTotal[1] = 0; + NearPeriodTotal[0] = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + FarPeriodTotal[2] = 0; + FarPeriodTotal[1] = 0; + FarPeriodTotal[0] = 0; + FarTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Far); + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = ShadowShortTrailingIdx; + while( i < startIdx ) { + ShadowShortPeriodTotal[2] += TA_CANDLERANGE( ShadowShort, i-2 ); + ShadowShortPeriodTotal[1] += TA_CANDLERANGE( ShadowShort, i-1 ); + ShadowShortPeriodTotal[0] += TA_CANDLERANGE( ShadowShort, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal[1] += TA_CANDLERANGE( ShadowLong, i-1 ); + ShadowLongPeriodTotal[0] += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); + NearPeriodTotal[1] += TA_CANDLERANGE( Near, i-1 ); + i++; + } + i = FarTrailingIdx; + while( i < startIdx ) { + FarPeriodTotal[2] += TA_CANDLERANGE( Far, i-2 ); + FarPeriodTotal[1] += TA_CANDLERANGE( Far, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - three white candlesticks with consecutively higher closes + * - each candle opens within or near the previous white real body + * - first candle: long white with no or very short upper shadow (a short shadow is accepted too for more flexibility) + * - second and third candles, or only third candle, show signs of weakening: progressively smaller white real bodies + * and/or relatively long upper shadows; see below for specific conditions + * The meanings of "long body", "short shadow", "far" and "near" are specified with TA_SetCandleSettings; + * outInteger is negative (-1 to -100): advance block is always bearish; + * the user should consider that advance block is significant when it appears in uptrend, while this function + * does not consider it + */ + outIdx = 0; + do + { + if( TA_CANDLECOLOR(i-2) == 1 && // 1st white + TA_CANDLECOLOR(i-1) == 1 && // 2nd white + TA_CANDLECOLOR(i) == 1 && // 3rd white + inClose[i] > inClose[i-1] && inClose[i-1] > inClose[i-2] && // consecutive higher closes + inOpen[i-1] > inOpen[i-2] && // 2nd opens within/near 1st real body +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && + inOpen[i] > inOpen[i-1] && // 3rd opens within/near 2nd real body +#endif + inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) && + TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long real body + TA_UPPERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowShort, ShadowShortPeriodTotal[2], i-2 ) && + // 1st: short upper shadow + ( + // ( 2 far smaller than 1 && 3 not longer than 2 ) + // advance blocked with the 2nd, 3rd must not carry on the advance + ( + TA_REALBODY(i-1) < TA_REALBODY(i-2) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[2], i-2 ) && + TA_REALBODY(i) < TA_REALBODY(i-1) + TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) + ) || + // 3 far smaller than 2 + // advance blocked with the 3rd + ( + TA_REALBODY(i) < TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[1], i-1 ) + ) || + // ( 3 smaller than 2 && 2 smaller than 1 && (3 or 2 not short upper shadow) ) + // advance blocked with progressively smaller real bodies and some upper shadows + ( + TA_REALBODY(i) < TA_REALBODY(i-1) && + TA_REALBODY(i-1) < TA_REALBODY(i-2) && + ( + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowShort, ShadowShortPeriodTotal[0], i ) || + TA_UPPERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowShort, ShadowShortPeriodTotal[1], i-1 ) + ) + ) || + // ( 3 smaller than 2 && 3 long upper shadow ) + // advance blocked with 3rd candle's long upper shadow and smaller body + ( + TA_REALBODY(i) < TA_REALBODY(i-1) && + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal[0], i ) + ) + ) + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 2; totIdx >= 0; --totIdx) + ShadowShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowShort, i-totIdx ) + - TA_CANDLERANGE( ShadowShort, ShadowShortTrailingIdx-totIdx ); + for (totIdx = 1; totIdx >= 0; --totIdx) + ShadowLongPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowLong, i-totIdx ) + - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx-totIdx ); + for (totIdx = 2; totIdx >= 1; --totIdx) { + FarPeriodTotal[totIdx] += TA_CANDLERANGE( Far, i-totIdx ) + - TA_CANDLERANGE( Far, FarTrailingIdx-totIdx ); + NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) + - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); + } + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-2 ); + i++; + ShadowShortTrailingIdx++; + ShadowLongTrailingIdx++; + NearTrailingIdx++; + FarTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlAdvanceBlock( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlAdvanceBlock( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlAdvanceBlock( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLADVANCEBLOCK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowShortPeriodTotal,3); +/* Generated */ ARRAY_LOCAL(ShadowLongPeriodTotal,2); +/* Generated */ ARRAY_LOCAL(NearPeriodTotal,3); +/* Generated */ ARRAY_LOCAL(FarPeriodTotal,3); +/* Generated */ double BodyLongPeriodTotal; +/* Generated */ int i, outIdx, totIdx, BodyLongTrailingIdx, ShadowShortTrailingIdx, ShadowLongTrailingIdx, NearTrailingIdx, +/* Generated */ FarTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLADVANCEBLOCK)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowShortPeriodTotal[2] = 0; +/* Generated */ ShadowShortPeriodTotal[1] = 0; +/* Generated */ ShadowShortPeriodTotal[0] = 0; +/* Generated */ ShadowShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowShort); +/* Generated */ ShadowLongPeriodTotal[1] = 0; +/* Generated */ ShadowLongPeriodTotal[0] = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ NearPeriodTotal[2] = 0; +/* Generated */ NearPeriodTotal[1] = 0; +/* Generated */ NearPeriodTotal[0] = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ FarPeriodTotal[2] = 0; +/* Generated */ FarPeriodTotal[1] = 0; +/* Generated */ FarPeriodTotal[0] = 0; +/* Generated */ FarTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Far); +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = ShadowShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowShortPeriodTotal[2] += TA_CANDLERANGE( ShadowShort, i-2 ); +/* Generated */ ShadowShortPeriodTotal[1] += TA_CANDLERANGE( ShadowShort, i-1 ); +/* Generated */ ShadowShortPeriodTotal[0] += TA_CANDLERANGE( ShadowShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal[1] += TA_CANDLERANGE( ShadowLong, i-1 ); +/* Generated */ ShadowLongPeriodTotal[0] += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); +/* Generated */ NearPeriodTotal[1] += TA_CANDLERANGE( Near, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = FarTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ FarPeriodTotal[2] += TA_CANDLERANGE( Far, i-2 ); +/* Generated */ FarPeriodTotal[1] += TA_CANDLERANGE( Far, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-2) == 1 && // 1st white +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && // 2nd white +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 3rd white +/* Generated */ inClose[i] > inClose[i-1] && inClose[i-1] > inClose[i-2] && // consecutive higher closes +/* Generated */ inOpen[i-1] > inOpen[i-2] && // 2nd opens within/near 1st real body +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && +/* Generated */ inOpen[i] > inOpen[i-1] && // 3rd opens within/near 2nd real body +/* Generated */ #endif +/* Generated */ inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) && +/* Generated */ TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long real body +/* Generated */ TA_UPPERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowShort, ShadowShortPeriodTotal[2], i-2 ) && +/* Generated */ // 1st: short upper shadow +/* Generated */ ( +/* Generated */ // ( 2 far smaller than 1 && 3 not longer than 2 ) +/* Generated */ // advance blocked with the 2nd, 3rd must not carry on the advance +/* Generated */ ( +/* Generated */ TA_REALBODY(i-1) < TA_REALBODY(i-2) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[2], i-2 ) && +/* Generated */ TA_REALBODY(i) < TA_REALBODY(i-1) + TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) +/* Generated */ ) || +/* Generated */ // 3 far smaller than 2 +/* Generated */ // advance blocked with the 3rd +/* Generated */ ( +/* Generated */ TA_REALBODY(i) < TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Far, FarPeriodTotal[1], i-1 ) +/* Generated */ ) || +/* Generated */ // ( 3 smaller than 2 && 2 smaller than 1 && (3 or 2 not short upper shadow) ) +/* Generated */ // advance blocked with progressively smaller real bodies and some upper shadows +/* Generated */ ( +/* Generated */ TA_REALBODY(i) < TA_REALBODY(i-1) && +/* Generated */ TA_REALBODY(i-1) < TA_REALBODY(i-2) && +/* Generated */ ( +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowShort, ShadowShortPeriodTotal[0], i ) || +/* Generated */ TA_UPPERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowShort, ShadowShortPeriodTotal[1], i-1 ) +/* Generated */ ) +/* Generated */ ) || +/* Generated */ // ( 3 smaller than 2 && 3 long upper shadow ) +/* Generated */ // advance blocked with 3rd candle's long upper shadow and smaller body +/* Generated */ ( +/* Generated */ TA_REALBODY(i) < TA_REALBODY(i-1) && +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal[0], i ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ for (totIdx = 2; totIdx >= 0; --totIdx) +/* Generated */ ShadowShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowShort, ShadowShortTrailingIdx-totIdx ); +/* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) +/* Generated */ ShadowLongPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowLong, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx-totIdx ); +/* Generated */ for (totIdx = 2; totIdx >= 1; --totIdx) { +/* Generated */ FarPeriodTotal[totIdx] += TA_CANDLERANGE( Far, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Far, FarTrailingIdx-totIdx ); +/* Generated */ NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-2 ); +/* Generated */ i++; +/* Generated */ ShadowShortTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ NearTrailingIdx++; +/* Generated */ FarTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLBELTHOLD.c b/talib/ta_func/ta_CDLBELTHOLD.c new file mode 100644 index 0000000..f61699f --- /dev/null +++ b/talib/ta_func/ta_CDLBELTHOLD.c @@ -0,0 +1,387 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlBeltHoldLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlBeltHoldLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLBELTHOLD_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyLong), TA_CANDLEAVGPERIOD(ShadowVeryShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLBELTHOLD - Belt-hold + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlBeltHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlBeltHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlBeltHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLBELTHOLD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLBELTHOLD)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - long white (black) real body + * - no or very short lower (upper) shadow + * The meaning of "long" and "very short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white (bullish), negative (-1 to -100) when black (bearish) + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && // long body + ( + ( // white body and very short lower shadow + TA_CANDLECOLOR(i) == 1 && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) || + ( // black body and very short upper shadow + TA_CANDLECOLOR(i) == -1 && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) + ) ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlBeltHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlBeltHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlBeltHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLBELTHOLD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLBELTHOLD)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && // long body +/* Generated */ ( +/* Generated */ ( // white body and very short lower shadow +/* Generated */ TA_CANDLECOLOR(i) == 1 && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) || +/* Generated */ ( // black body and very short upper shadow +/* Generated */ TA_CANDLECOLOR(i) == -1 && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) +/* Generated */ ) ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLBREAKAWAY.c b/talib/ta_func/ta_CDLBREAKAWAY.c new file mode 100644 index 0000000..6f3a080 --- /dev/null +++ b/talib/ta_func/ta_CDLBREAKAWAY.c @@ -0,0 +1,401 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlBreakawayLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlBreakawayLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLBREAKAWAY_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(BodyLong) + 4; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLBREAKAWAY - Breakaway + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlBreakaway( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlBreakaway( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlBreakaway( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLBREAKAWAY( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal; + int i, outIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLBREAKAWAY)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-4 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black (white) + * - second candle: black (white) day whose body gaps down (up) + * - third candle: black or white day with lower (higher) high and lower (higher) low than prior candle's + * - fourth candle: black (white) day with lower (higher) high and lower (higher) low than prior candle's + * - fifth candle: white (black) day that closes inside the gap, erasing the prior 3 days + * The meaning of "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that breakaway is significant in a trend opposite to the last candle, while this + * function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-4) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-4 ) && // 1st long + TA_CANDLECOLOR(i-4) == TA_CANDLECOLOR(i-3) && // 1st, 2nd, 4th same color, 5th opposite + TA_CANDLECOLOR(i-3) == TA_CANDLECOLOR(i-1) && + TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && + ( + ( TA_CANDLECOLOR(i-4) == -1 && // when 1st is black: + TA_REALBODYGAPDOWN(i-3,i-4) && // 2nd gaps down + inHigh[i-2] < inHigh[i-3] && inLow[i-2] < inLow[i-3] && // 3rd has lower high and low than 2nd + inHigh[i-1] < inHigh[i-2] && inLow[i-1] < inLow[i-2] && // 4th has lower high and low than 3rd + inClose[i] > inOpen[i-3] && inClose[i] < inClose[i-4] // 5th closes inside the gap + ) + || + ( TA_CANDLECOLOR(i-4) == 1 && // when 1st is white: + TA_REALBODYGAPUP(i-3,i-4) && // 2nd gaps up + inHigh[i-2] > inHigh[i-3] && inLow[i-2] > inLow[i-3] && // 3rd has higher high and low than 2nd + inHigh[i-1] > inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 4th has higher high and low than 3rd + inClose[i] < inOpen[i-3] && inClose[i] > inClose[i-4] // 5th closes inside the gap + ) + ) + ) +#endif + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-4 ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-4 ); + i++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlBreakaway( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlBreakaway( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlBreakaway( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLBREAKAWAY( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLBREAKAWAY)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-4 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-4) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-4 ) && // 1st long +/* Generated */ TA_CANDLECOLOR(i-4) == TA_CANDLECOLOR(i-3) && // 1st, 2nd, 4th same color, 5th opposite +/* Generated */ TA_CANDLECOLOR(i-3) == TA_CANDLECOLOR(i-1) && +/* Generated */ TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && +/* Generated */ ( +/* Generated */ ( TA_CANDLECOLOR(i-4) == -1 && // when 1st is black: +/* Generated */ TA_REALBODYGAPDOWN(i-3,i-4) && // 2nd gaps down +/* Generated */ inHigh[i-2] < inHigh[i-3] && inLow[i-2] < inLow[i-3] && // 3rd has lower high and low than 2nd +/* Generated */ inHigh[i-1] < inHigh[i-2] && inLow[i-1] < inLow[i-2] && // 4th has lower high and low than 3rd +/* Generated */ inClose[i] > inOpen[i-3] && inClose[i] < inClose[i-4] // 5th closes inside the gap +/* Generated */ ) +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i-4) == 1 && // when 1st is white: +/* Generated */ TA_REALBODYGAPUP(i-3,i-4) && // 2nd gaps up +/* Generated */ inHigh[i-2] > inHigh[i-3] && inLow[i-2] > inLow[i-3] && // 3rd has higher high and low than 2nd +/* Generated */ inHigh[i-1] > inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 4th has higher high and low than 3rd +/* Generated */ inClose[i] < inOpen[i-3] && inClose[i] > inClose[i-4] // 5th closes inside the gap +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-4 ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-4 ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLCLOSINGMARUBOZU.c b/talib/ta_func/ta_CDLCLOSINGMARUBOZU.c new file mode 100644 index 0000000..169397a --- /dev/null +++ b/talib/ta_func/ta_CDLCLOSINGMARUBOZU.c @@ -0,0 +1,408 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 022005 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlClosingMarubozuLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlClosingMarubozuLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLCLOSINGMARUBOZU_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyLong), TA_CANDLEAVGPERIOD(ShadowVeryShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLCLOSINGMARUBOZU - Closing Marubozu + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlClosingMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlClosingMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlClosingMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLCLOSINGMARUBOZU( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLCLOSINGMARUBOZU)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - long white (black) real body + * - no or very short upper (lower) shadow + * The meaning of "long" and "very short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white (bullish), negative (-1 to -100) when black (bearish) + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && // long body + ( + ( // white body and very short lower shadow + TA_CANDLECOLOR(i) == 1 && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) || + ( // black body and very short upper shadow + TA_CANDLECOLOR(i) == -1 && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) + ) ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; +#endif + + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlClosingMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlClosingMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlClosingMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLCLOSINGMARUBOZU( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLCLOSINGMARUBOZU)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && // long body +/* Generated */ ( +/* Generated */ ( // white body and very short lower shadow +/* Generated */ TA_CANDLECOLOR(i) == 1 && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) || +/* Generated */ ( // black body and very short upper shadow +/* Generated */ TA_CANDLECOLOR(i) == -1 && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) +/* Generated */ ) ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLCONCEALBABYSWALL.c b/talib/ta_func/ta_CDLCONCEALBABYSWALL.c new file mode 100644 index 0000000..1b47f92 --- /dev/null +++ b/talib/ta_func/ta_CDLCONCEALBABYSWALL.c @@ -0,0 +1,415 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 022705 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlConcealBabysWallLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlConcealBabysWallLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLCONCEALBABYSWALL_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(ShadowVeryShort) + 3; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLCONCEALBABYSWALL - Concealing Baby Swallow + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlConcealBabysWall( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlConcealBabysWall( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlConcealBabysWall( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLCONCEALBABYSWALL( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,4); + int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLCONCEALBABYSWALL)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal[3] = 0; + ShadowVeryShortPeriodTotal[2] = 0; + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[3] += TA_CANDLERANGE( ShadowVeryShort, i-3 ); + ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: black marubozu (very short shadows) + * - second candle: black marubozu (very short shadows) + * - third candle: black candle that opens gapping down but has an upper shadow that extends into the prior body + * - fourth candle: black candle that completely engulfs the third candle, including the shadows + * The meanings of "very short shadow" are specified with TA_SetCandleSettings; + * outInteger is positive (1 to 100): concealing baby swallow is always bullish; + * the user should consider that concealing baby swallow is significant when it appears in downtrend, while + * this function does not consider it + */ + outIdx = 0; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-3) == -1 && // 1st black + TA_CANDLECOLOR(i-2) == -1 && // 2nd black + TA_CANDLECOLOR(i-1) == -1 && // 3rd black + TA_CANDLECOLOR(i) == -1 && // 4th black + // 1st: marubozu + TA_LOWERSHADOW(i-3) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[3], i-3 ) && + TA_UPPERSHADOW(i-3) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[3], i-3 ) && + // 2nd: marubozu + TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && + TA_UPPERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && + TA_REALBODYGAPDOWN(i-1,i-2) && // 3rd: opens gapping down + // and HAS an upper shadow + TA_UPPERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + inHigh[i-1] > inClose[i-2] && // that extends into the prior body + inHigh[i] > inHigh[i-1] && inLow[i] < inLow[i-1] // 4th: engulfs the 3rd including the shadows + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 3; totIdx >= 1; --totIdx) + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + i++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlConcealBabysWall( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlConcealBabysWall( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlConcealBabysWall( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLCONCEALBABYSWALL( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,4); +/* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLCONCEALBABYSWALL)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal[3] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[2] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[3] += TA_CANDLERANGE( ShadowVeryShort, i-3 ); +/* Generated */ ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-3) == -1 && // 1st black +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // 2nd black +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 3rd black +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 4th black +/* Generated */ // 1st: marubozu +/* Generated */ TA_LOWERSHADOW(i-3) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[3], i-3 ) && +/* Generated */ TA_UPPERSHADOW(i-3) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[3], i-3 ) && +/* Generated */ // 2nd: marubozu +/* Generated */ TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && +/* Generated */ TA_UPPERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && +/* Generated */ TA_REALBODYGAPDOWN(i-1,i-2) && // 3rd: opens gapping down +/* Generated */ // and HAS an upper shadow +/* Generated */ TA_UPPERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ inHigh[i-1] > inClose[i-2] && // that extends into the prior body +/* Generated */ inHigh[i] > inHigh[i-1] && inLow[i] < inLow[i-1] // 4th: engulfs the 3rd including the shadows +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ for (totIdx = 3; totIdx >= 1; --totIdx) +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLCOUNTERATTACK.c b/talib/ta_func/ta_CDLCOUNTERATTACK.c new file mode 100644 index 0000000..1bc9a01 --- /dev/null +++ b/talib/ta_func/ta_CDLCOUNTERATTACK.c @@ -0,0 +1,402 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlCounterAttackLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlCounterAttackLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLCOUNTERATTACK_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(Equal), TA_CANDLEAVGPERIOD(BodyLong) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLCOUNTERATTACK - Counterattack + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlCounterAttack( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlCounterAttack( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlCounterAttack( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLCOUNTERATTACK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double EqualPeriodTotal; + ARRAY_LOCAL(BodyLongPeriodTotal,2); + int i, outIdx, totIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLCOUNTERATTACK)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + BodyLongPeriodTotal[1] = 0; + BodyLongPeriodTotal[0] = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); + BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black (white) + * - second candle: long white (black) with close equal to the prior close + * The meaning of "equal" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that counterattack is significant in a trend, while this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && // 1st long + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && // 2nd long + inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // equal closes + inClose[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + for (totIdx = 1; totIdx >= 0; --totIdx) + BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); + i++; + EqualTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlCounterAttack( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlCounterAttack( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlCounterAttack( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLCOUNTERATTACK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double EqualPeriodTotal; +/* Generated */ ARRAY_LOCAL(BodyLongPeriodTotal,2); +/* Generated */ int i, outIdx, totIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLCOUNTERATTACK)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ BodyLongPeriodTotal[1] = 0; +/* Generated */ BodyLongPeriodTotal[0] = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && // 1st long +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && // 2nd long +/* Generated */ inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // equal closes +/* Generated */ inClose[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) +/* Generated */ BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLDARKCLOUDCOVER.c b/talib/ta_func/ta_CDLDARKCLOUDCOVER.c new file mode 100644 index 0000000..30ac5e9 --- /dev/null +++ b/talib/ta_func/ta_CDLDARKCLOUDCOVER.c @@ -0,0 +1,403 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120904 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlDarkCloudCoverLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlDarkCloudCoverLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLDARKCLOUDCOVER_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 5.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + + return TA_CANDLEAVGPERIOD(BodyLong) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLDARKCLOUDCOVER - Dark Cloud Cover + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDarkCloudCover( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDarkCloudCover( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDarkCloudCover( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLDARKCLOUDCOVER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal; + int i, outIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 5.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLDARKCLOUDCOVER)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white candle + * - second candle: black candle that opens above previous day high and closes within previous day real body; + * Greg Morris wants the close to be below the midpoint of the previous real body + * The meaning of "long" is specified with TA_SetCandleSettings, the penetration of the first real body is specified + * with optInPenetration + * outInteger is negative (-1 to -100): dark cloud cover is always bearish + * the user should consider that a dark cloud cover is significant when it appears in an uptrend, while + * this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-1) == 1 && // 1st: white + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long + TA_CANDLECOLOR(i) == -1 && // 2nd: black + inOpen[i] > inHigh[i-1] && // open above prior high + inClose[i] > inOpen[i-1] && // close within prior body + inClose[i] < inClose[i-1] - TA_REALBODY(i-1) * optInPenetration + ) +#endif + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); + i++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDarkCloudCover( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDarkCloudCover( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDarkCloudCover( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLDARKCLOUDCOVER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 5.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLDARKCLOUDCOVER)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-1) == 1 && // 1st: white +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 2nd: black +/* Generated */ inOpen[i] > inHigh[i-1] && // open above prior high +/* Generated */ inClose[i] > inOpen[i-1] && // close within prior body +/* Generated */ inClose[i] < inClose[i-1] - TA_REALBODY(i-1) * optInPenetration +/* Generated */ ) +/* Generated */ #endif +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLDOJI.c b/talib/ta_func/ta_CDLDOJI.c new file mode 100644 index 0000000..a49bb95 --- /dev/null +++ b/talib/ta_func/ta_CDLDOJI.c @@ -0,0 +1,366 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlDojiLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlDojiLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLDOJI_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(BodyDoji); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLDOJI - Doji + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, lookbackTotal; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLDOJI)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyDojiPeriodTotal = 0; + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * + * Must have: + * - open quite equal to close + * How much can be the maximum distance between open and close is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100) but this does not mean it is bullish: doji shows uncertainty and it is + * neither bullish nor bearish when considered alone + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + i++; + BodyDojiTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLDOJI)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLDOJISTAR.c b/talib/ta_func/ta_CDLDOJISTAR.c new file mode 100644 index 0000000..a519d9b --- /dev/null +++ b/talib/ta_func/ta_CDLDOJISTAR.c @@ -0,0 +1,392 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 100204 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlDojiStarLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlDojiStarLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLDOJISTAR_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(BodyLong) ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLDOJISTAR - Doji Star + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLDOJISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLDOJISTAR)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyDojiPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyLong); + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + + i = BodyLongTrailingIdx; + while( i < startIdx-1 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long real body + * - second candle: star (open gapping up in an uptrend or down in a downtrend) with a doji + * The meaning of "doji" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * it's defined bullish when the long candle is white and the star gaps up, bearish when the long candle + * is black and the star gaps down; the user should consider that a doji star is bullish when it appears + * in an uptrend and it's bearish when it appears in a downtrend, so to determine the bullishness or + * bearishness of the pattern the trend must be analyzed + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st: long real body + TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && // 2nd: doji + ( ( TA_CANDLECOLOR(i-1) == 1 && TA_REALBODYGAPUP(i,i-1) ) // that gaps up if 1st is white + || + ( TA_CANDLECOLOR(i-1) == -1 && TA_REALBODYGAPDOWN(i,i-1) ) // or down if 1st is black + ) ) + outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyDojiTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLDOJISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLDOJISTAR)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st: long real body +/* Generated */ TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && // 2nd: doji +/* Generated */ ( ( TA_CANDLECOLOR(i-1) == 1 && TA_REALBODYGAPUP(i,i-1) ) // that gaps up if 1st is white +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i-1) == -1 && TA_REALBODYGAPDOWN(i,i-1) ) // or down if 1st is black +/* Generated */ ) ) +/* Generated */ outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLDRAGONFLYDOJI.c b/talib/ta_func/ta_CDLDRAGONFLYDOJI.c new file mode 100644 index 0000000..4c6e6f7 --- /dev/null +++ b/talib/ta_func/ta_CDLDRAGONFLYDOJI.c @@ -0,0 +1,396 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlDragonflyDojiLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlDragonflyDojiLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLDRAGONFLYDOJI_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(ShadowVeryShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLDRAGONFLYDOJI - Dragonfly Doji + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDragonflyDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDragonflyDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDragonflyDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLDRAGONFLYDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLDRAGONFLYDOJI)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyDojiPeriodTotal = 0; + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * + * Must have: + * - doji body + * - open and close at the high of the day = no or very short upper shadow + * - lower shadow (to distinguish from other dojis, here lower shadow should not be very short) + * The meaning of "doji" and "very short" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100) but this does not mean it is bullish: dragonfly doji must be considered + * relatively to the trend + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && + TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyDojiTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlDragonflyDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlDragonflyDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlDragonflyDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLDRAGONFLYDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLDRAGONFLYDOJI)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLENGULFING.c b/talib/ta_func/ta_CDLENGULFING.c new file mode 100644 index 0000000..0101779 --- /dev/null +++ b/talib/ta_func/ta_CDLENGULFING.c @@ -0,0 +1,365 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 102404 AC Creation + * 040309 AC Increased flexibility to allow real bodies matching + * on one end (Greg Morris - "Candlestick charting explained") + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlEngulfingLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlEngulfingLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLENGULFING_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLENGULFING - Engulfing Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlEngulfing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlEngulfing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlEngulfing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLENGULFING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int i, outIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLENGULFING)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first: black (white) real body + * - second: white (black) real body that engulfs the prior real body + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish: + * - 100 is returned when the second candle's real body begins before and ends after the first candle's real body + * - 80 is returned when the two real bodies match on one end (Greg Morris contemplate this case in his book + * "Candlestick charting explained") + * The user should consider that an engulfing must appear in a downtrend if bullish or in an uptrend if bearish, + * while this function does not consider it + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( ( TA_CANDLECOLOR(i) == 1 && TA_CANDLECOLOR(i-1) == -1 && // white engulfs black + ( ( inClose[i] >= inOpen[i-1] && inOpen[i] < inClose[i-1] ) || + ( inClose[i] > inOpen[i-1] && inOpen[i] <= inClose[i-1] ) + ) + ) + || + ( TA_CANDLECOLOR(i) == -1 && TA_CANDLECOLOR(i-1) == 1 && // black engulfs white + ( ( inOpen[i] >= inClose[i-1] && inClose[i] < inOpen[i-1] ) || + ( inOpen[i] > inClose[i-1] && inClose[i] <= inOpen[i-1] ) + ) + ) + ) + if( inOpen[i] != inClose[i-1] && inClose[i] != inOpen[i-1] ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 80; + else + outInteger[outIdx++] = 0; + i++; + } while( i <= endIdx ); +#endif + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlEngulfing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlEngulfing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlEngulfing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLENGULFING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i, outIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLENGULFING)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( ( TA_CANDLECOLOR(i) == 1 && TA_CANDLECOLOR(i-1) == -1 && // white engulfs black +/* Generated */ ( ( inClose[i] >= inOpen[i-1] && inOpen[i] < inClose[i-1] ) || +/* Generated */ ( inClose[i] > inOpen[i-1] && inOpen[i] <= inClose[i-1] ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i) == -1 && TA_CANDLECOLOR(i-1) == 1 && // black engulfs white +/* Generated */ ( ( inOpen[i] >= inClose[i-1] && inClose[i] < inOpen[i-1] ) || +/* Generated */ ( inOpen[i] > inClose[i-1] && inClose[i] <= inOpen[i-1] ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ if( inOpen[i] != inClose[i-1] && inClose[i] != inOpen[i-1] ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 80; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ i++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLEVENINGDOJISTAR.c b/talib/ta_func/ta_CDLEVENINGDOJISTAR.c new file mode 100644 index 0000000..33cc485 --- /dev/null +++ b/talib/ta_func/ta_CDLEVENINGDOJISTAR.c @@ -0,0 +1,452 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 100304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlEveningDojiStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlEveningDojiStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLEVENINGDOJISTAR_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + + return max( max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(BodyLong) ), + TA_CANDLEAVGPERIOD(BodyShort) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLEVENINGDOJISTAR - Evening Doji Star + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlEveningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlEveningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlEveningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLEVENINGDOJISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLEVENINGDOJISTAR)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyDojiPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji); + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyDojiTrailingIdx; + while( i < startIdx-1 ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white real body + * - second candle: doji gapping up + * - third candle: black real body that moves well within the first candle's real body + * The meaning of "doji" and "long" is specified with TA_SetCandleSettings + * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should + * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want + * it to be relatively long + * outInteger is negative (-1 to -100): evening star is always bearish; + * the user should consider that an evening star is significant when it appears in an uptrend, + * while this function does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_CANDLECOLOR(i-2) == 1 && // white + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji + TA_REALBODYGAPUP(i-1,i-2) && // gapping up + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short + TA_CANDLECOLOR(i) == -1 && // black real body + inClose[i] < inClose[i-2] - TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; +#endif + + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyDojiTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlEveningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlEveningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlEveningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLEVENINGDOJISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLEVENINGDOJISTAR)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_CANDLECOLOR(i-2) == 1 && // white +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji +/* Generated */ TA_REALBODYGAPUP(i-1,i-2) && // gapping up +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short +/* Generated */ TA_CANDLECOLOR(i) == -1 && // black real body +/* Generated */ inClose[i] < inClose[i-2] - TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLEVENINGSTAR.c b/talib/ta_func/ta_CDLEVENINGSTAR.c new file mode 100644 index 0000000..0bc3f60 --- /dev/null +++ b/talib/ta_func/ta_CDLEVENINGSTAR.c @@ -0,0 +1,438 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 100304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlEveningStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlEveningStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLEVENINGSTAR_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLEVENINGSTAR - Evening Star + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlEveningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlEveningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlEveningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLEVENINGSTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal2; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLEVENINGSTAR)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyShortPeriodTotal2 = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx-1 ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i+1 ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white real body + * - second candle: star (short real body gapping up) + * - third candle: black real body that moves well within the first candle's real body + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should + * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want + * it to be relatively long + * outInteger is negative (-1 to -100): evening star is always bearish; + * the user should consider that an evening star is significant when it appears in an uptrend, + * while this function does not consider the trend + */ + outIdx = 0; + do + { + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_CANDLECOLOR(i-2) == 1 && // white + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // 2nd: short + TA_REALBODYGAPUP(i-1,i-2) && // gapping up + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal2, i ) && // 3rd: longer than short + TA_CANDLECOLOR(i) == -1 && // black real body + inClose[i] < inClose[i-2] - TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx+1 ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlEveningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlEveningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlEveningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLEVENINGSTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal2; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLEVENINGSTAR)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal2 = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i+1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_CANDLECOLOR(i-2) == 1 && // white +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // 2nd: short +/* Generated */ TA_REALBODYGAPUP(i-1,i-2) && // gapping up +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal2, i ) && // 3rd: longer than short +/* Generated */ TA_CANDLECOLOR(i) == -1 && // black real body +/* Generated */ inClose[i] < inClose[i-2] - TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx+1 ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLGAPSIDESIDEWHITE.c b/talib/ta_func/ta_CDLGAPSIDESIDEWHITE.c new file mode 100644 index 0000000..d39cee9 --- /dev/null +++ b/talib/ta_func/ta_CDLGAPSIDESIDEWHITE.c @@ -0,0 +1,396 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 020605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlGapSideSideWhiteLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlGapSideSideWhiteLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLGAPSIDESIDEWHITE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(Near), TA_CANDLEAVGPERIOD(Equal) ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLGAPSIDESIDEWHITE - Up/Down-gap side-by-side white lines + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlGapSideSideWhite( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLGAPSIDESIDEWHITE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double NearPeriodTotal, EqualPeriodTotal; + int i, outIdx, NearTrailingIdx, EqualTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLGAPSIDESIDEWHITE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + NearPeriodTotal = 0; + EqualPeriodTotal = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ); + i++; + } + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - upside or downside gap (between the bodies) + * - first candle after the window: white candlestick + * - second candle after the window: white candlestick with similar size (near the same) and about the same + * open (equal) of the previous candle + * - the second candle does not close the window + * The meaning of "near" and "equal" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) or negative (-1 to -100): the user should consider that upside + * or downside gap side-by-side white lines is significant when it appears in a trend, while this function + * does not consider the trend + */ + outIdx = 0; + do + { + if( + ( // upside or downside gap between the 1st candle and both the next 2 candles + ( TA_REALBODYGAPUP(i-1,i-2) && TA_REALBODYGAPUP(i,i-2) ) + || + ( TA_REALBODYGAPDOWN(i-1,i-2) && TA_REALBODYGAPDOWN(i,i-2) ) + ) && + TA_CANDLECOLOR(i-1) == 1 && // 2nd: white + TA_CANDLECOLOR(i) == 1 && // 3rd: white + TA_REALBODY(i) >= TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) && // same size 2 and 3 + TA_REALBODY(i) <= TA_REALBODY(i-1) + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) && + inOpen[i] >= inOpen[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // same open 2 and 3 + inOpen[i] <= inOpen[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) + ) + outInteger[outIdx++] = ( TA_REALBODYGAPUP(i-1,i-2) ? 100 : -100 ); + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) - TA_CANDLERANGE( Near, NearTrailingIdx-1 ); + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + i++; + NearTrailingIdx++; + EqualTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlGapSideSideWhite( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlGapSideSideWhite( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLGAPSIDESIDEWHITE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double NearPeriodTotal, EqualPeriodTotal; +/* Generated */ int i, outIdx, NearTrailingIdx, EqualTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLGAPSIDESIDEWHITE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ NearPeriodTotal = 0; +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( +/* Generated */ ( // upside or downside gap between the 1st candle and both the next 2 candles +/* Generated */ ( TA_REALBODYGAPUP(i-1,i-2) && TA_REALBODYGAPUP(i,i-2) ) +/* Generated */ || +/* Generated */ ( TA_REALBODYGAPDOWN(i-1,i-2) && TA_REALBODYGAPDOWN(i,i-2) ) +/* Generated */ ) && +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && // 2nd: white +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 3rd: white +/* Generated */ TA_REALBODY(i) >= TA_REALBODY(i-1) - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) && // same size 2 and 3 +/* Generated */ TA_REALBODY(i) <= TA_REALBODY(i-1) + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) && +/* Generated */ inOpen[i] >= inOpen[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // same open 2 and 3 +/* Generated */ inOpen[i] <= inOpen[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = ( TA_REALBODYGAPUP(i-1,i-2) ? 100 : -100 ); +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) - TA_CANDLERANGE( Near, NearTrailingIdx-1 ); +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ NearTrailingIdx++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLGRAVESTONEDOJI.c b/talib/ta_func/ta_CDLGRAVESTONEDOJI.c new file mode 100644 index 0000000..55f180b --- /dev/null +++ b/talib/ta_func/ta_CDLGRAVESTONEDOJI.c @@ -0,0 +1,376 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlGravestoneDojiLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlGravestoneDojiLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLGRAVESTONEDOJI_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(ShadowVeryShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLGRAVESTONEDOJI - Gravestone Doji + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlGravestoneDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlGravestoneDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlGravestoneDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLGRAVESTONEDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLGRAVESTONEDOJI)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyDojiPeriodTotal = 0; + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * + * Must have: + * - doji body + * - open and close at the low of the day = no or very short lower shadow + * - upper shadow (to distinguish from other dojis, here upper shadow should not be very short) + * The meaning of "doji" and "very short" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100) but this does not mean it is bullish: gravestone doji must be considered + * relatively to the trend + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyDojiTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlGravestoneDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlGravestoneDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlGravestoneDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLGRAVESTONEDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLGRAVESTONEDOJI)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHAMMER.c b/talib/ta_func/ta_CDLHAMMER.c new file mode 100644 index 0000000..e6922be --- /dev/null +++ b/talib/ta_func/ta_CDLHAMMER.c @@ -0,0 +1,425 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 102304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHammerLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHammerLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHAMMER_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowLong) ), + TA_CANDLEAVGPERIOD(ShadowVeryShort) ), + TA_CANDLEAVGPERIOD(Near) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHAMMER - Hammer + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHAMMER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal, NearPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHAMMER)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + NearPeriodTotal = 0; + NearTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(Near); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = NearTrailingIdx; + while( i < startIdx-1 ) { + NearPeriodTotal += TA_CANDLERANGE( Near, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - small real body + * - long lower shadow + * - no, or very short, upper shadow + * - body below or near the lows of the previous candle + * The meaning of "short", "long" and "near the lows" is specified with TA_SetCandleSettings; + * outInteger is positive (1 to 100): hammer is always bullish; + * the user should consider that a hammer must appear in a downtrend, while this function does not consider it + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb + TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long lower shadow + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short upper shadow + min( inClose[i], inOpen[i] ) <= inLow[i-1] + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) // rb near the prior candle's lows + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) + - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) + - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) + - TA_CANDLERANGE( Near, NearTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + NearTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHAMMER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal, NearPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHAMMER)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ NearPeriodTotal = 0; +/* Generated */ NearTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb +/* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long lower shadow +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short upper shadow +/* Generated */ min( inClose[i], inOpen[i] ) <= inLow[i-1] + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) // rb near the prior candle's lows +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) +/* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) +/* Generated */ - TA_CANDLERANGE( Near, NearTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ NearTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHANGINGMAN.c b/talib/ta_func/ta_CDLHANGINGMAN.c new file mode 100644 index 0000000..9099bc5 --- /dev/null +++ b/talib/ta_func/ta_CDLHANGINGMAN.c @@ -0,0 +1,425 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 102304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHangingManLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHangingManLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHANGINGMAN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowLong) ), + TA_CANDLEAVGPERIOD(ShadowVeryShort) ), + TA_CANDLEAVGPERIOD(Near) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHANGINGMAN - Hanging Man + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHangingMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHangingMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHangingMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHANGINGMAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal, NearPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHANGINGMAN)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + NearPeriodTotal = 0; + NearTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(Near); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = NearTrailingIdx; + while( i < startIdx-1 ) { + NearPeriodTotal += TA_CANDLERANGE( Near, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - small real body + * - long lower shadow + * - no, or very short, upper shadow + * - body above or near the highs of the previous candle + * The meaning of "short", "long" and "near the highs" is specified with TA_SetCandleSettings; + * outInteger is negative (-1 to -100): hanging man is always bearish; + * the user should consider that a hanging man must appear in an uptrend, while this function does not consider it + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb + TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long lower shadow + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short upper shadow + min( inClose[i], inOpen[i] ) >= inHigh[i-1] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) // rb near the prior candle's highs + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) + - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) + - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) + - TA_CANDLERANGE( Near, NearTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + NearTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHangingMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHangingMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHangingMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHANGINGMAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal, NearPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHANGINGMAN)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ NearPeriodTotal = 0; +/* Generated */ NearTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb +/* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long lower shadow +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short upper shadow +/* Generated */ min( inClose[i], inOpen[i] ) >= inHigh[i-1] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) // rb near the prior candle's highs +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) +/* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) +/* Generated */ - TA_CANDLERANGE( Near, NearTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ NearTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHARAMI.c b/talib/ta_func/ta_CDLHARAMI.c new file mode 100644 index 0000000..7bcfeb0 --- /dev/null +++ b/talib/ta_func/ta_CDLHARAMI.c @@ -0,0 +1,411 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 102404 AC Creation + * 040309 AC Increased flexibility to allow real bodies matching + * on one end (Greg Morris - "Candlestick charting explained") + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHaramiLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHaramiLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHARAMI_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHARAMI - Harami Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHarami( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHarami( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHarami( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHARAMI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHARAMI)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-1 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white (black) real body + * - second candle: short real body totally engulfed by the first + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish: + * - 100 is returned when the first candle's real body begins before and ends after the second candle's real body + * - 80 is returned when the two real bodies match on one end (Greg Morris contemplate this case in his book + * "Candlestick charting explained") + * The user should consider that a harami is significant when it appears in a downtrend if bullish or + * in an uptrend when bearish, while this function does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st: long + TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) // 2nd: short + ) + if ( max( inClose[i], inOpen[i] ) < max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st + min( inClose[i], inOpen[i] ) > min( inClose[i-1], inOpen[i-1] ) + ) + outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 100; + else + if ( max( inClose[i], inOpen[i] ) <= max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st + min( inClose[i], inOpen[i] ) >= min( inClose[i-1], inOpen[i-1] ) // (one end of real body can match; + ) // engulfing guaranteed by "long" and "short") + outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 80; + else + outInteger[outIdx++] = 0; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHarami( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHarami( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHarami( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHARAMI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHARAMI)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st: long +/* Generated */ TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) // 2nd: short +/* Generated */ ) +/* Generated */ if ( max( inClose[i], inOpen[i] ) < max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st +/* Generated */ min( inClose[i], inOpen[i] ) > min( inClose[i-1], inOpen[i-1] ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 100; +/* Generated */ else +/* Generated */ if ( max( inClose[i], inOpen[i] ) <= max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st +/* Generated */ min( inClose[i], inOpen[i] ) >= min( inClose[i-1], inOpen[i-1] ) // (one end of real body can match; +/* Generated */ ) // engulfing guaranteed by "long" and "short") +/* Generated */ outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 80; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHARAMICROSS.c b/talib/ta_func/ta_CDLHARAMICROSS.c new file mode 100644 index 0000000..3a54647 --- /dev/null +++ b/talib/ta_func/ta_CDLHARAMICROSS.c @@ -0,0 +1,406 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 102404 AC Creation + * 040309 AC Increased flexibility to allow real bodies matching + * on one end (Greg Morris - "Candlestick charting explained") + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHaramiCrossLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHaramiCrossLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHARAMICROSS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(BodyLong) ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHARAMICROSS - Harami Cross Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHaramiCross( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHaramiCross( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHaramiCross( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHARAMICROSS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHARAMICROSS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyDojiPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyLong); + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + + i = BodyLongTrailingIdx; + while( i < startIdx-1 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white (black) real body + * - second candle: doji totally engulfed by the first + * The meaning of "doji" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that a harami cross is significant when it appears in a downtrend if bullish or + * in an uptrend when bearish, while this function does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st: long + TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) ) // 2nd: doji + if ( max( inClose[i], inOpen[i] ) < max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st + min( inClose[i], inOpen[i] ) > min( inClose[i-1], inOpen[i-1] ) + ) + outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 100; + else + if ( max( inClose[i], inOpen[i] ) <= max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st + min( inClose[i], inOpen[i] ) >= min( inClose[i-1], inOpen[i-1] ) // (one end of real body can match; + ) // engulfing guaranteed by "long" and "doji") + outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 80; + else + outInteger[outIdx++] = 0; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyDojiTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHaramiCross( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHaramiCross( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHaramiCross( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHARAMICROSS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHARAMICROSS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st: long +/* Generated */ TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) ) // 2nd: doji +/* Generated */ if ( max( inClose[i], inOpen[i] ) < max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st +/* Generated */ min( inClose[i], inOpen[i] ) > min( inClose[i-1], inOpen[i-1] ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 100; +/* Generated */ else +/* Generated */ if ( max( inClose[i], inOpen[i] ) <= max( inClose[i-1], inOpen[i-1] ) && // 2nd is engulfed by 1st +/* Generated */ min( inClose[i], inOpen[i] ) >= min( inClose[i-1], inOpen[i-1] ) // (one end of real body can match; +/* Generated */ ) // engulfing guaranteed by "long" and "doji") +/* Generated */ outInteger[outIdx++] = -TA_CANDLECOLOR(i-1) * 80; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHIGHWAVE.c b/talib/ta_func/ta_CDLHIGHWAVE.c new file mode 100644 index 0000000..5c2f8c0 --- /dev/null +++ b/talib/ta_func/ta_CDLHIGHWAVE.c @@ -0,0 +1,370 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 072404 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHignWaveLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHignWaveLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHIGHWAVE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowVeryLong) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHIGHWAVE - High-Wave Candle + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHignWave( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHignWave( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHignWave( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHIGHWAVE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHIGHWAVE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowPeriodTotal = 0; + ShadowTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryLong); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowTrailingIdx; + while( i < startIdx ) { + ShadowPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - short real body + * - very long upper and lower shadow + * The meaning of "short" and "very long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white or negative (-1 to -100) when black; + * it does not mean bullish or bearish + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowPeriodTotal, i ) && + TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowPeriodTotal, i ) ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + ShadowPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ) - TA_CANDLERANGE( ShadowVeryLong, ShadowTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHignWave( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHignWave( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHignWave( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHIGHWAVE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHIGHWAVE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowPeriodTotal = 0; +/* Generated */ ShadowTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryLong); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowPeriodTotal, i ) ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ ShadowPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ) - TA_CANDLERANGE( ShadowVeryLong, ShadowTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHIKKAKE.c b/talib/ta_func/ta_CDLHIKKAKE.c new file mode 100644 index 0000000..1c838f4 --- /dev/null +++ b/talib/ta_func/ta_CDLHIKKAKE.c @@ -0,0 +1,410 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120305 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHikkakeLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHikkakeLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHIKKAKE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return 5; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHIKKAKE - Hikkake Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHikkake( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHIKKAKE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int i, outIdx, lookbackTotal, patternIdx, patternResult; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHIKKAKE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + patternIdx = 0; + patternResult = 0; + + i = startIdx - 3; + while( i < startIdx ) { + /* copy here the pattern recognition code below */ + if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low + ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low + || + ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low + ) + ) { + patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); + patternIdx = i; + } else + /* search for confirmation if hikkake was no more than 3 bars ago */ + if( i <= patternIdx+3 && + ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd + || + ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd + ) + ) + patternIdx = 0; + i++; + } + + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first and second candle: inside bar (2nd has lower high and higher low than 1st) + * - third candle: lower high and lower low than 2nd (higher high and higher low than 2nd) + * outInteger[hikkakebar] is positive (1 to 100) or negative (-1 to -100) meaning bullish or bearish hikkake + * Confirmation could come in the next 3 days with: + * - a day that closes higher than the high (lower than the low) of the 2nd candle + * outInteger[confirmationbar] is equal to 100 + the bullish hikkake result or -100 - the bearish hikkake result + * Note: if confirmation and a new hikkake come at the same bar, only the new hikkake is reported (the new hikkake + * overwrites the confirmation of the old hikkake) + */ + outIdx = 0; + do + { + if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low + ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low + || + ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low + ) + ) { + patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); + patternIdx = i; + outInteger[outIdx++] = patternResult; + } else + /* search for confirmation if hikkake was no more than 3 bars ago */ + if( i <= patternIdx+3 && + ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd + || + ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd + ) + ) { + outInteger[outIdx++] = patternResult + 100 * ( patternResult > 0 ? 1 : -1 ); + patternIdx = 0; + } else + outInteger[outIdx++] = 0; + i++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHikkake( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHikkake( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHIKKAKE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i, outIdx, lookbackTotal, patternIdx, patternResult; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHIKKAKE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ patternIdx = 0; +/* Generated */ patternResult = 0; +/* Generated */ i = startIdx - 3; +/* Generated */ while( i < startIdx ) { +/* Generated */ if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low +/* Generated */ ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low +/* Generated */ || +/* Generated */ ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low +/* Generated */ ) +/* Generated */ ) { +/* Generated */ patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); +/* Generated */ patternIdx = i; +/* Generated */ } else +/* Generated */ if( i <= patternIdx+3 && +/* Generated */ ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd +/* Generated */ || +/* Generated */ ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd +/* Generated */ ) +/* Generated */ ) +/* Generated */ patternIdx = 0; +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 1st + 2nd: lower high and higher low +/* Generated */ ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] ) // (bull) 3rd: lower high and lower low +/* Generated */ || +/* Generated */ ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] ) // (bear) 3rd: higher high and higher low +/* Generated */ ) +/* Generated */ ) { +/* Generated */ patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); +/* Generated */ patternIdx = i; +/* Generated */ outInteger[outIdx++] = patternResult; +/* Generated */ } else +/* Generated */ if( i <= patternIdx+3 && +/* Generated */ ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 2nd +/* Generated */ || +/* Generated */ ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 2nd +/* Generated */ ) +/* Generated */ ) { +/* Generated */ outInteger[outIdx++] = patternResult + 100 * ( patternResult > 0 ? 1 : -1 ); +/* Generated */ patternIdx = 0; +/* Generated */ } else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ i++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHIKKAKEMOD.c b/talib/ta_func/ta_CDLHIKKAKEMOD.c new file mode 100644 index 0000000..eebcd62 --- /dev/null +++ b/talib/ta_func/ta_CDLHIKKAKEMOD.c @@ -0,0 +1,468 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 122605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHikkakeModLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHikkakeModLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHIKKAKEMOD_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( 1, TA_CANDLEAVGPERIOD(Near) ) + 5; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHIKKAKEMOD - Modified Hikkake Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHikkakeMod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHikkakeMod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHikkakeMod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHIKKAKEMOD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double NearPeriodTotal; + int i, outIdx, NearTrailingIdx, lookbackTotal, patternIdx, patternResult; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHIKKAKEMOD)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + NearPeriodTotal = 0; + NearTrailingIdx = startIdx - 3 - TA_CANDLEAVGPERIOD(Near); + i = NearTrailingIdx; + while( i < startIdx - 3 ) { + NearPeriodTotal += TA_CANDLERANGE( Near, i-2 ); + i++; + } + + patternIdx = 0; + patternResult = 0; + + i = startIdx - 3; + while( i < startIdx ) { + /* copy here the pattern recognition code below */ + if( inHigh[i-2] < inHigh[i-3] && inLow[i-2] > inLow[i-3] && // 2nd: lower high and higher low than 1st + inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 3rd: lower high and higher low than 2nd + ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] && // (bull) 4th: lower high and lower low + inClose[i-2] <= inLow[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) + // (bull) 2nd: close near the low + ) + || + ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] && // (bear) 4th: higher high and higher low + inClose[i-2] >= inHigh[i-2] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) + // (bull) 2nd: close near the top + ) + ) + ) { + patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); + patternIdx = i; + } else + /* search for confirmation if modified hikkake was no more than 3 bars ago */ + if( i <= patternIdx+3 && + ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 3rd + || + ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 3rd + ) + ) + patternIdx = 0; + NearPeriodTotal += TA_CANDLERANGE( Near, i-2 ) - TA_CANDLERANGE( Near, NearTrailingIdx-2 ); + NearTrailingIdx++; + i++; + } + + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle + * - second candle: candle with range less than first candle and close near the bottom (near the top) + * - third candle: lower high and higher low than 2nd + * - fourth candle: lower high and lower low (higher high and higher low) than 3rd + * outInteger[hikkake bar] is positive (1 to 100) or negative (-1 to -100) meaning bullish or bearish hikkake + * Confirmation could come in the next 3 days with: + * - a day that closes higher than the high (lower than the low) of the 3rd candle + * outInteger[confirmationbar] is equal to 100 + the bullish hikkake result or -100 - the bearish hikkake result + * Note: if confirmation and a new hikkake come at the same bar, only the new hikkake is reported (the new hikkake + * overwrites the confirmation of the old hikkake); + * the user should consider that modified hikkake is a reversal pattern, while hikkake could be both a reversal + * or a continuation pattern, so bullish (bearish) modified hikkake is significant when appearing in a downtrend + * (uptrend) + */ + outIdx = 0; + do + { + if( inHigh[i-2] < inHigh[i-3] && inLow[i-2] > inLow[i-3] && // 2nd: lower high and higher low than 1st + inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 3rd: lower high and higher low than 2nd + ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] && // (bull) 4th: lower high and lower low + inClose[i-2] <= inLow[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) + // (bull) 2nd: close near the low + ) + || + ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] && // (bear) 4th: higher high and higher low + inClose[i-2] >= inHigh[i-2] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) + // (bull) 2nd: close near the top + ) + ) + ) { + patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); + patternIdx = i; + outInteger[outIdx++] = patternResult; + } else + /* search for confirmation if modified hikkake was no more than 3 bars ago */ + if( i <= patternIdx+3 && + ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 3rd + || + ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 3rd + ) + ) { + outInteger[outIdx++] = patternResult + 100 * ( patternResult > 0 ? 1 : -1 ); + patternIdx = 0; + } else + outInteger[outIdx++] = 0; + NearPeriodTotal += TA_CANDLERANGE( Near, i-2 ) - TA_CANDLERANGE( Near, NearTrailingIdx-2 ); + NearTrailingIdx++; + i++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHikkakeMod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHikkakeMod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHikkakeMod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHIKKAKEMOD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double NearPeriodTotal; +/* Generated */ int i, outIdx, NearTrailingIdx, lookbackTotal, patternIdx, patternResult; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHIKKAKEMOD)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ NearPeriodTotal = 0; +/* Generated */ NearTrailingIdx = startIdx - 3 - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx - 3 ) { +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-2 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ patternIdx = 0; +/* Generated */ patternResult = 0; +/* Generated */ i = startIdx - 3; +/* Generated */ while( i < startIdx ) { +/* Generated */ if( inHigh[i-2] < inHigh[i-3] && inLow[i-2] > inLow[i-3] && // 2nd: lower high and higher low than 1st +/* Generated */ inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 3rd: lower high and higher low than 2nd +/* Generated */ ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] && // (bull) 4th: lower high and lower low +/* Generated */ inClose[i-2] <= inLow[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) +/* Generated */ // (bull) 2nd: close near the low +/* Generated */ ) +/* Generated */ || +/* Generated */ ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] && // (bear) 4th: higher high and higher low +/* Generated */ inClose[i-2] >= inHigh[i-2] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) +/* Generated */ // (bull) 2nd: close near the top +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) { +/* Generated */ patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); +/* Generated */ patternIdx = i; +/* Generated */ } else +/* Generated */ if( i <= patternIdx+3 && +/* Generated */ ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 3rd +/* Generated */ || +/* Generated */ ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 3rd +/* Generated */ ) +/* Generated */ ) +/* Generated */ patternIdx = 0; +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-2 ) - TA_CANDLERANGE( Near, NearTrailingIdx-2 ); +/* Generated */ NearTrailingIdx++; +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( inHigh[i-2] < inHigh[i-3] && inLow[i-2] > inLow[i-3] && // 2nd: lower high and higher low than 1st +/* Generated */ inHigh[i-1] < inHigh[i-2] && inLow[i-1] > inLow[i-2] && // 3rd: lower high and higher low than 2nd +/* Generated */ ( ( inHigh[i] < inHigh[i-1] && inLow[i] < inLow[i-1] && // (bull) 4th: lower high and lower low +/* Generated */ inClose[i-2] <= inLow[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) +/* Generated */ // (bull) 2nd: close near the low +/* Generated */ ) +/* Generated */ || +/* Generated */ ( inHigh[i] > inHigh[i-1] && inLow[i] > inLow[i-1] && // (bear) 4th: higher high and higher low +/* Generated */ inClose[i-2] >= inHigh[i-2] - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-2 ) +/* Generated */ // (bull) 2nd: close near the top +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) { +/* Generated */ patternResult = 100 * ( inHigh[i] < inHigh[i-1] ? 1 : -1 ); +/* Generated */ patternIdx = i; +/* Generated */ outInteger[outIdx++] = patternResult; +/* Generated */ } else +/* Generated */ if( i <= patternIdx+3 && +/* Generated */ ( ( patternResult > 0 && inClose[i] > inHigh[patternIdx-1] ) // close higher than the high of 3rd +/* Generated */ || +/* Generated */ ( patternResult < 0 && inClose[i] < inLow[patternIdx-1] ) // close lower than the low of 3rd +/* Generated */ ) +/* Generated */ ) { +/* Generated */ outInteger[outIdx++] = patternResult + 100 * ( patternResult > 0 ? 1 : -1 ); +/* Generated */ patternIdx = 0; +/* Generated */ } else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-2 ) - TA_CANDLERANGE( Near, NearTrailingIdx-2 ); +/* Generated */ NearTrailingIdx++; +/* Generated */ i++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLHOMINGPIGEON.c b/talib/ta_func/ta_CDLHOMINGPIGEON.c new file mode 100644 index 0000000..d30396a --- /dev/null +++ b/talib/ta_func/ta_CDLHOMINGPIGEON.c @@ -0,0 +1,395 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 032005 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlHomingPigeonLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlHomingPigeonLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLHOMINGPIGEON_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLHOMINGPIGEON - Homing Pigeon + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHomingPigeon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHomingPigeon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHomingPigeon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLHOMINGPIGEON( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLHOMINGPIGEON)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle + * - second candle: short black real body completely inside the previous day's body + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100): homing pigeon is always bullish; + * the user should consider that homing pigeon is significant when it appears in a downtrend, + * while this function does not consider the trend + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-1) == -1 && // 1st black + TA_CANDLECOLOR(i) == -1 && // 2nd black + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st long + TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 2nd short + inOpen[i] < inOpen[i-1] && // 2nd engulfed by 1st + inClose[i] > inClose[i-1] + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; +#endif + + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlHomingPigeon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlHomingPigeon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlHomingPigeon( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLHOMINGPIGEON( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLHOMINGPIGEON)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // 1st black +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 2nd black +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // 1st long +/* Generated */ TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 2nd short +/* Generated */ inOpen[i] < inOpen[i-1] && // 2nd engulfed by 1st +/* Generated */ inClose[i] > inClose[i-1] +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLIDENTICAL3CROWS.c b/talib/ta_func/ta_CDLIDENTICAL3CROWS.c new file mode 100644 index 0000000..9ff41ab --- /dev/null +++ b/talib/ta_func/ta_CDLIDENTICAL3CROWS.c @@ -0,0 +1,443 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 103104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlIdentical3CrowsLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlIdentical3CrowsLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLIDENTICAL3CROWS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(Equal) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLIDENTICAL3CROWS - Identical Three Crows + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlIdentical3Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlIdentical3Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlIdentical3Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLIDENTICAL3CROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3); + ARRAY_LOCAL(EqualPeriodTotal,3); + int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, EqualTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLIDENTICAL3CROWS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal[2] = 0; + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortPeriodTotal[0] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + EqualPeriodTotal[2] = 0; + EqualPeriodTotal[1] = 0; + EqualPeriodTotal[0] = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal[2] += TA_CANDLERANGE( Equal, i-2 ); + EqualPeriodTotal[1] += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - three consecutive and declining black candlesticks + * - each candle must have no or very short lower shadow + * - each candle after the first must open at or very close to the prior candle's close + * The meaning of "very short" is specified with TA_SetCandleSettings; + * the meaning of "very close" is specified with TA_SetCandleSettings (Equal); + * outInteger is negative (-1 to -100): identical three crows is always bearish; + * the user should consider that identical 3 crows is significant when it appears after a mature advance or at high levels, + * while this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-2) == -1 && // 1st black + // very short lower shadow + TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && + TA_CANDLECOLOR(i-1) == -1 && // 2nd black + // very short lower shadow + TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + TA_CANDLECOLOR(i) == -1 && // 3rd black + // very short lower shadow + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + inClose[i-2] > inClose[i-1] && // three declining + inClose[i-1] > inClose[i] && + // 2nd black opens very close to 1st close + inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) && + inOpen[i-1] >= inClose[i-2] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) && + // 3rd black opens very close to 2nd close + inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 ) && + inOpen[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 ) + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 2; totIdx >= 0; --totIdx) + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + for (totIdx = 2; totIdx >= 1; --totIdx) + EqualPeriodTotal[totIdx] += TA_CANDLERANGE( Equal, i-totIdx ) + - TA_CANDLERANGE( Equal, EqualTrailingIdx-totIdx ); + i++; + ShadowVeryShortTrailingIdx++; + EqualTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlIdentical3Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlIdentical3Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlIdentical3Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLIDENTICAL3CROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,3); +/* Generated */ ARRAY_LOCAL(EqualPeriodTotal,3); +/* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, EqualTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLIDENTICAL3CROWS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal[2] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[0] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ EqualPeriodTotal[2] = 0; +/* Generated */ EqualPeriodTotal[1] = 0; +/* Generated */ EqualPeriodTotal[0] = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[2] += TA_CANDLERANGE( ShadowVeryShort, i-2 ); +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal[2] += TA_CANDLERANGE( Equal, i-2 ); +/* Generated */ EqualPeriodTotal[1] += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-2) == -1 && // 1st black +/* Generated */ // very short lower shadow +/* Generated */ TA_LOWERSHADOW(i-2) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[2], i-2 ) && +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd black +/* Generated */ // very short lower shadow +/* Generated */ TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd black +/* Generated */ // very short lower shadow +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ inClose[i-2] > inClose[i-1] && // three declining +/* Generated */ inClose[i-1] > inClose[i] && +/* Generated */ // 2nd black opens very close to 1st close +/* Generated */ inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) && +/* Generated */ inOpen[i-1] >= inClose[i-2] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[2], i-2 ) && +/* Generated */ // 3rd black opens very close to 2nd close +/* Generated */ inOpen[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 ) && +/* Generated */ inOpen[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal[1], i-1 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ for (totIdx = 2; totIdx >= 0; --totIdx) +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ for (totIdx = 2; totIdx >= 1; --totIdx) +/* Generated */ EqualPeriodTotal[totIdx] += TA_CANDLERANGE( Equal, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Equal, EqualTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLINNECK.c b/talib/ta_func/ta_CDLINNECK.c new file mode 100644 index 0000000..c5860e2 --- /dev/null +++ b/talib/ta_func/ta_CDLINNECK.c @@ -0,0 +1,397 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlInNeckLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlInNeckLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLINNECK_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(Equal), TA_CANDLEAVGPERIOD(BodyLong) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLINNECK - In-Neck Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlInNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLINNECK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double EqualPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLINNECK)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); + i++; + } + i = startIdx; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle + * - second candle: white candle with open below previous day low and close slightly into previous day body + * The meaning of "equal" is specified with TA_SetCandleSettings + * outInteger is negative (-1 to -100): in-neck is always bearish + * the user should consider that in-neck is significant when it appears in a downtrend, while this function + * does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long + TA_CANDLECOLOR(i) == 1 && // 2nd: white + inOpen[i] < inLow[i-1] && // open below prior low + inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close slightly into prior body + inClose[i] >= inClose[i-1] + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); + i++; + EqualTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlInNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlInNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLINNECK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double EqualPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLINNECK)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 2nd: white +/* Generated */ inOpen[i] < inLow[i-1] && // open below prior low +/* Generated */ inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close slightly into prior body +/* Generated */ inClose[i] >= inClose[i-1] +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLINVERTEDHAMMER.c b/talib/ta_func/ta_CDLINVERTEDHAMMER.c new file mode 100644 index 0000000..10b05a5 --- /dev/null +++ b/talib/ta_func/ta_CDLINVERTEDHAMMER.c @@ -0,0 +1,413 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 103004 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlInvertedHammerLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlInvertedHammerLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLINVERTEDHAMMER_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowLong) ), + TA_CANDLEAVGPERIOD(ShadowVeryShort) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLINVERTEDHAMMER - Inverted Hammer + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlInvertedHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLINVERTEDHAMMER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLINVERTEDHAMMER)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + /* Proceed with the calculation for the requested range. + * Must have: + * - small real body + * - long upper shadow + * - no, or very short, lower shadow + * - gap down + * The meaning of "short", "very short" and "long" is specified with TA_SetCandleSettings; + * outInteger is positive (1 to 100): inverted hammer is always bullish; + * the user should consider that an inverted hammer must appear in a downtrend, while this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long upper shadow + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short lower shadow + TA_REALBODYGAPDOWN(i, i-1) ) // gap down + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) + - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) + - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlInvertedHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlInvertedHammer( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLINVERTEDHAMMER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLINVERTEDHAMMER)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long upper shadow +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short lower shadow +/* Generated */ TA_REALBODYGAPDOWN(i, i-1) ) // gap down +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) +/* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLKICKING.c b/talib/ta_func/ta_CDLKICKING.c new file mode 100644 index 0000000..e1bfa26 --- /dev/null +++ b/talib/ta_func/ta_CDLKICKING.c @@ -0,0 +1,424 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010705 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlKickingLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlKickingLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLKICKING_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(BodyLong) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLKICKING - Kicking + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlKicking( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlKicking( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlKicking( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLKICKING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2); + ARRAY_LOCAL(BodyLongPeriodTotal,2); + int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLKICKING)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortPeriodTotal[0] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + BodyLongPeriodTotal[1] = 0; + BodyLongPeriodTotal[0] = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); + BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: marubozu + * - second candle: opposite color marubozu + * - gap between the two candles: upside gap if black then white, downside gap if white then black + * The meaning of "long body" and "very short shadow" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles + // 1st marubozu + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && + TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + // 2nd marubozu + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + // gap + ( + ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLEGAPUP(i,i-1) ) + || + ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLEGAPDOWN(i,i-1) ) + ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 1; totIdx >= 0; --totIdx) { + BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + } + i++; + ShadowVeryShortTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlKicking( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlKicking( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlKicking( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLKICKING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2); +/* Generated */ ARRAY_LOCAL(BodyLongPeriodTotal,2); +/* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLKICKING)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[0] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ BodyLongPeriodTotal[1] = 0; +/* Generated */ BodyLongPeriodTotal[0] = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles +/* Generated */ // 1st marubozu +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && +/* Generated */ TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ // 2nd marubozu +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ // gap +/* Generated */ ( +/* Generated */ ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLEGAPUP(i,i-1) ) +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLEGAPDOWN(i,i-1) ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) { +/* Generated */ BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ } +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLKICKINGBYLENGTH.c b/talib/ta_func/ta_CDLKICKINGBYLENGTH.c new file mode 100644 index 0000000..eff6969 --- /dev/null +++ b/talib/ta_func/ta_CDLKICKINGBYLENGTH.c @@ -0,0 +1,426 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlKickingByLengthLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlKickingByLengthLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLKICKINGBYLENGTH_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(BodyLong) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLKICKINGBYLENGTH - Kicking - bull/bear determined by the longer marubozu + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlKickingByLength( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlKickingByLength( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlKickingByLength( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLKICKINGBYLENGTH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2); + ARRAY_LOCAL(BodyLongPeriodTotal,2); + int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLKICKINGBYLENGTH)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal[1] = 0; + ShadowVeryShortPeriodTotal[0] = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + BodyLongPeriodTotal[1] = 0; + BodyLongPeriodTotal[0] = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); + BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: marubozu + * - second candle: opposite color marubozu + * - gap between the two candles: upside gap if black then white, downside gap if white then black + * The meaning of "long body" and "very short shadow" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; the longer of the two + * marubozu determines the bullishness or bearishness of this pattern + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles + // 1st marubozu + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && + TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && + // 2nd marubozu + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && + // gap + ( + ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLEGAPUP(i,i-1) ) + || + ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLEGAPDOWN(i,i-1) ) + ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR( ( TA_REALBODY(i) > TA_REALBODY(i-1) ? i : i-1 ) ) * 100; + else + outInteger[outIdx++] = 0; +#endif + + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 1; totIdx >= 0; --totIdx) { + BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); + ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); + } + i++; + ShadowVeryShortTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlKickingByLength( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlKickingByLength( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlKickingByLength( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLKICKINGBYLENGTH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(ShadowVeryShortPeriodTotal,2); +/* Generated */ ARRAY_LOCAL(BodyLongPeriodTotal,2); +/* Generated */ int i, outIdx, totIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLKICKINGBYLENGTH)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal[1] = 0; +/* Generated */ ShadowVeryShortPeriodTotal[0] = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ BodyLongPeriodTotal[1] = 0; +/* Generated */ BodyLongPeriodTotal[0] = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal[1] += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ ShadowVeryShortPeriodTotal[0] += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles +/* Generated */ // 1st marubozu +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && +/* Generated */ TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ TA_LOWERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[1], i-1 ) && +/* Generated */ // 2nd marubozu +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal[0], i ) && +/* Generated */ // gap +/* Generated */ ( +/* Generated */ ( TA_CANDLECOLOR(i-1) == -1 && TA_CANDLEGAPUP(i,i-1) ) +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i-1) == 1 && TA_CANDLEGAPDOWN(i,i-1) ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR( ( TA_REALBODY(i) > TA_REALBODY(i-1) ? i : i-1 ) ) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) { +/* Generated */ BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); +/* Generated */ ShadowVeryShortPeriodTotal[totIdx] += TA_CANDLERANGE( ShadowVeryShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-totIdx ); +/* Generated */ } +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLLADDERBOTTOM.c b/talib/ta_func/ta_CDLLADDERBOTTOM.c new file mode 100644 index 0000000..b2bff27 --- /dev/null +++ b/talib/ta_func/ta_CDLLADDERBOTTOM.c @@ -0,0 +1,379 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 032005 AC Creation + * 041305 MF Minor modification for a compiler warning + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlLadderBottomLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlLadderBottomLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLLADDERBOTTOM_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(ShadowVeryShort) + 4; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLLADDERBOTTOM - Ladder Bottom + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlLadderBottom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlLadderBottom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlLadderBottom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLLADDERBOTTOM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double ShadowVeryShortPeriodTotal; + int i, outIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLLADDERBOTTOM)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - three black candlesticks with consecutively lower opens and closes + * - fourth candle: black candle with an upper shadow (it's supposed to be not very short) + * - fifth candle: white candle that opens above prior candle's body and closes above prior candle's high + * The meaning of "very short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100): ladder bottom is always bullish; + * the user should consider that ladder bottom is significant when it appears in a downtrend, + * while this function does not consider it + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( + TA_CANDLECOLOR(i-4) == -1 && TA_CANDLECOLOR(i-3) == -1 && TA_CANDLECOLOR(i-2) == -1 && // 3 black candlesticks + inOpen[i-4] > inOpen[i-3] && inOpen[i-3] > inOpen[i-2] && // with consecutively lower opens + inClose[i-4] > inClose[i-3] && inClose[i-3] > inClose[i-2] && // and closes + TA_CANDLECOLOR(i-1) == -1 && // 4th: black with an upper shadow + TA_UPPERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i-1 ) && + TA_CANDLECOLOR(i) == 1 && // 5th: white + inOpen[i] > inOpen[i-1] && // that opens above prior candle's body + inClose[i] > inHigh[i-1] // and closes above prior candle's high + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-1 ); + i++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlLadderBottom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlLadderBottom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlLadderBottom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLLADDERBOTTOM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLLADDERBOTTOM)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( +/* Generated */ TA_CANDLECOLOR(i-4) == -1 && TA_CANDLECOLOR(i-3) == -1 && TA_CANDLECOLOR(i-2) == -1 && // 3 black candlesticks +/* Generated */ inOpen[i-4] > inOpen[i-3] && inOpen[i-3] > inOpen[i-2] && // with consecutively lower opens +/* Generated */ inClose[i-4] > inClose[i-3] && inClose[i-3] > inClose[i-2] && // and closes +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 4th: black with an upper shadow +/* Generated */ TA_UPPERSHADOW(i-1) > TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i-1 ) && +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 5th: white +/* Generated */ inOpen[i] > inOpen[i-1] && // that opens above prior candle's body +/* Generated */ inClose[i] > inHigh[i-1] // and closes above prior candle's high +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLLONGLEGGEDDOJI.c b/talib/ta_func/ta_CDLLONGLEGGEDDOJI.c new file mode 100644 index 0000000..bf49bb9 --- /dev/null +++ b/talib/ta_func/ta_CDLLONGLEGGEDDOJI.c @@ -0,0 +1,376 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlLongLeggedDojiLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlLongLeggedDojiLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLLONGLEGGEDDOJI_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(ShadowLong) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLLONGLEGGEDDOJI - Long Legged Doji + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlLongLeggedDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlLongLeggedDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlLongLeggedDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLLONGLEGGEDDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, ShadowLongPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, ShadowLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLLONGLEGGEDDOJI)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyDojiPeriodTotal = 0; + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * + * Must have: + * - doji body + * - one or two long shadows + * The meaning of "doji" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100) but this does not mean it is bullish: long legged doji shows uncertainty + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && + ( TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) + || + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) + ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); + i++; + BodyDojiTrailingIdx++; + ShadowLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlLongLeggedDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlLongLeggedDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlLongLeggedDoji( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLLONGLEGGEDDOJI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, ShadowLongPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, ShadowLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLLONGLEGGEDDOJI)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && +/* Generated */ ( TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) +/* Generated */ || +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLLONGLINE.c b/talib/ta_func/ta_CDLLONGLINE.c new file mode 100644 index 0000000..89daa3a --- /dev/null +++ b/talib/ta_func/ta_CDLLONGLINE.c @@ -0,0 +1,377 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 071704 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlLongLineLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlLongLineLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLLONGLINE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyLong), TA_CANDLEAVGPERIOD(ShadowShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLLONGLINE - Long Line Candle + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlLongLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlLongLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlLongLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLLONGLINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLLONGLINE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + ShadowPeriodTotal = 0; + ShadowTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowShort); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = ShadowTrailingIdx; + while( i < startIdx ) { + ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - long real body + * - short upper and lower shadow + * The meaning of "long" and "short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white (bullish), negative (-1 to -100) when black (bearish) + */ + outIdx = 0; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal, i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyTrailingIdx ); + ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ) - TA_CANDLERANGE( ShadowShort, ShadowTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlLongLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlLongLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlLongLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLLONGLINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLLONGLINE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ ShadowPeriodTotal = 0; +/* Generated */ ShadowTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowShort); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyTrailingIdx ); +/* Generated */ ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ) - TA_CANDLERANGE( ShadowShort, ShadowTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLMARUBOZU.c b/talib/ta_func/ta_CDLMARUBOZU.c new file mode 100644 index 0000000..c57f7c9 --- /dev/null +++ b/talib/ta_func/ta_CDLMARUBOZU.c @@ -0,0 +1,371 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlMarubozuLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlMarubozuLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLMARUBOZU_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyLong), TA_CANDLEAVGPERIOD(ShadowVeryShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLMARUBOZU - Marubozu + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLMARUBOZU( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyLongPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLMARUBOZU)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - long real body + * - no or very short upper and lower shadow + * The meaning of "long" and "very short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white (bullish), negative (-1 to -100) when black (bearish) + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMarubozu( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLMARUBOZU( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyLongPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLMARUBOZU)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLMATCHINGLOW.c b/talib/ta_func/ta_CDLMATCHINGLOW.c new file mode 100644 index 0000000..5728d89 --- /dev/null +++ b/talib/ta_func/ta_CDLMATCHINGLOW.c @@ -0,0 +1,364 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 032605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlMatchingLowLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlMatchingLowLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLMATCHINGLOW_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(Equal) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLMATCHINGLOW - Matching Low + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMatchingLow( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMatchingLow( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMatchingLow( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLMATCHINGLOW( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double EqualPeriodTotal; + int i, outIdx, EqualTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLMATCHINGLOW)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: black candle + * - second candle: black candle with the close equal to the previous close + * The meaning of "equal" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100): matching low is always bullish; + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_CANDLECOLOR(i-1) == -1 && // first black + TA_CANDLECOLOR(i) == -1 && // second black + inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // 1st and 2nd same close + inClose[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + i++; + EqualTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMatchingLow( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMatchingLow( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMatchingLow( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLMATCHINGLOW( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double EqualPeriodTotal; +/* Generated */ int i, outIdx, EqualTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLMATCHINGLOW)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // first black +/* Generated */ TA_CANDLECOLOR(i) == -1 && // second black +/* Generated */ inClose[i] <= inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // 1st and 2nd same close +/* Generated */ inClose[i] >= inClose[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLMATHOLD.c b/talib/ta_func/ta_CDLMATHOLD.c new file mode 100644 index 0000000..ff12d3b --- /dev/null +++ b/talib/ta_func/ta_CDLMATHOLD.c @@ -0,0 +1,474 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 022005 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlMatHoldLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlMatHoldLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLMATHOLD_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 5.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 4; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLMATHOLD - Mat Hold + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMatHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMatHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMatHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLMATHOLD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(BodyPeriodTotal,5); + int i, outIdx, totIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 5.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLMATHOLD)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal[4] = 0; + BodyPeriodTotal[3] = 0; + BodyPeriodTotal[2] = 0; + BodyPeriodTotal[1] = 0; + BodyPeriodTotal[0] = 0; + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal[3] += TA_CANDLERANGE( BodyShort, i-3 ); + BodyPeriodTotal[2] += TA_CANDLERANGE( BodyShort, i-2 ); + BodyPeriodTotal[1] += TA_CANDLERANGE( BodyShort, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white candle + * - upside gap between the first and the second bodies + * - second candle: small black candle + * - third and fourth candles: falling small real body candlesticks (commonly black) that hold within the long + * white candle's body and are higher than the reaction days of the rising three methods + * - fifth candle: white candle that opens above the previous small candle's close and closes higher than the + * high of the highest reaction day + * The meaning of "short" and "long" is specified with TA_SetCandleSettings; + * "hold within" means "a part of the real body must be within"; + * optInPenetration is the maximum percentage of the first white body the reaction days can penetrate (it is + * to specify how much the reaction days should be "higher than the reaction days of the rising three methods") + * outInteger is positive (1 to 100): mat hold is always bullish + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( // 1st long, then 3 small + TA_REALBODY(i-4) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal[4], i-4 ) && + TA_REALBODY(i-3) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[3], i-3 ) && + TA_REALBODY(i-2) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[2], i-2 ) && + TA_REALBODY(i-1) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[1], i-1 ) && + // white, black, 2 black or white, white + TA_CANDLECOLOR(i-4) == 1 && + TA_CANDLECOLOR(i-3) == -1 && + TA_CANDLECOLOR(i) == 1 && + // upside gap 1st to 2nd + TA_REALBODYGAPUP(i-3,i-4) && + // 3rd to 4th hold within 1st: a part of the real body must be within 1st real body + min(inOpen[i-2], inClose[i-2]) < inClose[i-4] && + min(inOpen[i-1], inClose[i-1]) < inClose[i-4] && + // reaction days penetrate first body less than optInPenetration percent + min(inOpen[i-2], inClose[i-2]) > inClose[i-4] - TA_REALBODY(i-4) * optInPenetration && + min(inOpen[i-1], inClose[i-1]) > inClose[i-4] - TA_REALBODY(i-4) * optInPenetration && + // 2nd to 4th are falling + max(inClose[i-2], inOpen[i-2]) < inOpen[i-3] && + max(inClose[i-1], inOpen[i-1]) < max(inClose[i-2], inOpen[i-2]) && + // 5th opens above the prior close + inOpen[i] > inClose[i-1] && + // 5th closes above the highest high of the reaction days + inClose[i] > max(max(inHigh[i-3], inHigh[i-2]), inHigh[i-1]) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; +#endif + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-4 ); + for (totIdx = 3; totIdx >= 1; --totIdx) + BodyPeriodTotal[totIdx] += TA_CANDLERANGE( BodyShort, i-totIdx ) + - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx-totIdx ); + i++; + BodyShortTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMatHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMatHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMatHold( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLMATHOLD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(BodyPeriodTotal,5); +/* Generated */ int i, outIdx, totIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 5.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLMATHOLD)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal[4] = 0; +/* Generated */ BodyPeriodTotal[3] = 0; +/* Generated */ BodyPeriodTotal[2] = 0; +/* Generated */ BodyPeriodTotal[1] = 0; +/* Generated */ BodyPeriodTotal[0] = 0; +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal[3] += TA_CANDLERANGE( BodyShort, i-3 ); +/* Generated */ BodyPeriodTotal[2] += TA_CANDLERANGE( BodyShort, i-2 ); +/* Generated */ BodyPeriodTotal[1] += TA_CANDLERANGE( BodyShort, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( // 1st long, then 3 small +/* Generated */ TA_REALBODY(i-4) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal[4], i-4 ) && +/* Generated */ TA_REALBODY(i-3) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[3], i-3 ) && +/* Generated */ TA_REALBODY(i-2) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[2], i-2 ) && +/* Generated */ TA_REALBODY(i-1) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[1], i-1 ) && +/* Generated */ // white, black, 2 black or white, white +/* Generated */ TA_CANDLECOLOR(i-4) == 1 && +/* Generated */ TA_CANDLECOLOR(i-3) == -1 && +/* Generated */ TA_CANDLECOLOR(i) == 1 && +/* Generated */ // upside gap 1st to 2nd +/* Generated */ TA_REALBODYGAPUP(i-3,i-4) && +/* Generated */ // 3rd to 4th hold within 1st: a part of the real body must be within 1st real body +/* Generated */ min(inOpen[i-2], inClose[i-2]) < inClose[i-4] && +/* Generated */ min(inOpen[i-1], inClose[i-1]) < inClose[i-4] && +/* Generated */ // reaction days penetrate first body less than optInPenetration percent +/* Generated */ min(inOpen[i-2], inClose[i-2]) > inClose[i-4] - TA_REALBODY(i-4) * optInPenetration && +/* Generated */ min(inOpen[i-1], inClose[i-1]) > inClose[i-4] - TA_REALBODY(i-4) * optInPenetration && +/* Generated */ // 2nd to 4th are falling +/* Generated */ max(inClose[i-2], inOpen[i-2]) < inOpen[i-3] && +/* Generated */ max(inClose[i-1], inOpen[i-1]) < max(inClose[i-2], inOpen[i-2]) && +/* Generated */ // 5th opens above the prior close +/* Generated */ inOpen[i] > inClose[i-1] && +/* Generated */ // 5th closes above the highest high of the reaction days +/* Generated */ inClose[i] > max(max(inHigh[i-3], inHigh[i-2]), inHigh[i-1]) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ #endif +/* Generated */ BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-4 ); +/* Generated */ for (totIdx = 3; totIdx >= 1; --totIdx) +/* Generated */ BodyPeriodTotal[totIdx] += TA_CANDLERANGE( BodyShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLMORNINGDOJISTAR.c b/talib/ta_func/ta_CDLMORNINGDOJISTAR.c new file mode 100644 index 0000000..20d8230 --- /dev/null +++ b/talib/ta_func/ta_CDLMORNINGDOJISTAR.c @@ -0,0 +1,444 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 100304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlMorningDojiStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlMorningDojiStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLMORNINGDOJISTAR_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + return max( max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(BodyLong) ), + TA_CANDLEAVGPERIOD(BodyShort) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLMORNINGDOJISTAR - Morning Doji Star + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMorningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLMORNINGDOJISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLMORNINGDOJISTAR)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyDojiPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji); + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyDojiTrailingIdx; + while( i < startIdx-1 ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black real body + * - second candle: doji gapping down + * - third candle: white real body that moves well within the first candle's real body + * The meaning of "doji" and "long" is specified with TA_SetCandleSettings + * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should + * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want + * it to be relatively long + * outInteger is positive (1 to 100): morning doji star is always bullish; + * the user should consider that a morning star is significant when it appears in a downtrend, + * while this function does not consider the trend + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_CANDLECOLOR(i-2) == -1 && // black + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji + TA_REALBODYGAPDOWN(i-1,i-2) && // gapping down + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short + TA_CANDLECOLOR(i) == 1 && // white real body + inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyDojiTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMorningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMorningDojiStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLMORNINGDOJISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLMORNINGDOJISTAR)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyDojiTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // black +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i-1 ) && // 2nd: doji +/* Generated */ TA_REALBODYGAPDOWN(i-1,i-2) && // gapping down +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: longer than short +/* Generated */ TA_CANDLECOLOR(i) == 1 && // white real body +/* Generated */ inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i-1 ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLMORNINGSTAR.c b/talib/ta_func/ta_CDLMORNINGSTAR.c new file mode 100644 index 0000000..0f81fd7 --- /dev/null +++ b/talib/ta_func/ta_CDLMORNINGSTAR.c @@ -0,0 +1,423 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 100304 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlMorningStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlMorningStarLookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLMORNINGSTAR_Lookback( double optInPenetration ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInPenetration); + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLMORNINGSTAR - Morning Star + * + * Input = Open, High, Low, Close + * Output = int + * + * Optional Parameters + * ------------------- + * optInPenetration:(From 0 to TA_REAL_MAX) + * Percentage of penetration of a candle within another candle + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMorningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMorningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMorningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLMORNINGSTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal2; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) ||/* Generated */ (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLMORNINGSTAR)(optInPenetration); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyShortPeriodTotal2 = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx-1 ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i+1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black real body + * - second candle: star (Short real body gapping down) + * - third candle: white real body that moves well within the first candle's real body + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * The meaning of "moves well within" is specified with optInPenetration and "moves" should mean the real body should + * not be short ("short" is specified with TA_SetCandleSettings) - Greg Morris wants it to be long, someone else want + * it to be relatively long + * outInteger is positive (1 to 100): morning star is always bullish; + * the user should consider that a morning star is significant when it appears in a downtrend, + * while this function does not consider the trend + */ + outIdx = 0; + do + { + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_CANDLECOLOR(i-2) == -1 && // black + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // 2nd: short + TA_REALBODYGAPDOWN(i-1,i-2) && // gapping down + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal2, i ) && // 3rd: longer than short + TA_CANDLECOLOR(i) == 1 && // black real body + inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx+1 ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlMorningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlMorningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlMorningStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLMORNINGSTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ double optInPenetration, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal, BodyShortPeriodTotal2; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInPenetration == TA_REAL_DEFAULT ) +/* Generated */ optInPenetration = 3.000000e-1; +/* Generated */ else if( (optInPenetration < 0.000000e+0) || (optInPenetration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLMORNINGSTAR)(optInPenetration); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal2 = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i+1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // black +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // 2nd: short +/* Generated */ TA_REALBODYGAPDOWN(i-1,i-2) && // gapping down +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal2, i ) && // 3rd: longer than short +/* Generated */ TA_CANDLECOLOR(i) == 1 && // black real body +/* Generated */ inClose[i] > inClose[i-2] + TA_REALBODY(i-2) * optInPenetration // closing well within 1st rb +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ BodyShortPeriodTotal2 += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx+1 ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLONNECK.c b/talib/ta_func/ta_CDLONNECK.c new file mode 100644 index 0000000..4596daf --- /dev/null +++ b/talib/ta_func/ta_CDLONNECK.c @@ -0,0 +1,384 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlOnNeckLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlOnNeckLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLONNECK_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(Equal), TA_CANDLEAVGPERIOD(BodyLong) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLONNECK - On-Neck Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlOnNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlOnNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlOnNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLONNECK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double EqualPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLONNECK)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle + * - second candle: white candle with open below previous day low and close equal to previous day low + * The meaning of "equal" is specified with TA_SetCandleSettings + * outInteger is negative (-1 to -100): on-neck is always bearish + * the user should consider that on-neck is significant when it appears in a downtrend, while this function + * does not consider it + */ + outIdx = 0; + do + { + if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long + TA_CANDLECOLOR(i) == 1 && // 2nd: white + inOpen[i] < inLow[i-1] && // open below prior low + inClose[i] <= inLow[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close equal to prior low + inClose[i] >= inLow[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); + i++; + EqualTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlOnNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlOnNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlOnNeck( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLONNECK( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double EqualPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLONNECK)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 2nd: white +/* Generated */ inOpen[i] < inLow[i-1] && // open below prior low +/* Generated */ inClose[i] <= inLow[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close equal to prior low +/* Generated */ inClose[i] >= inLow[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLPIERCING.c b/talib/ta_func/ta_CDLPIERCING.c new file mode 100644 index 0000000..020746a --- /dev/null +++ b/talib/ta_func/ta_CDLPIERCING.c @@ -0,0 +1,382 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120904 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlPiercingLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlPiercingLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLPIERCING_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(BodyLong) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLPIERCING - Piercing Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlPiercing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlPiercing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlPiercing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLPIERCING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(BodyLongPeriodTotal,2); + int i, outIdx, totIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLPIERCING)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal[1] = 0; + BodyLongPeriodTotal[0] = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); + BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle + * - second candle: long white candle with open below previous day low and close at least at 50% of previous day + * real body + * The meaning of "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100): piercing pattern is always bullish + * the user should consider that a piercing pattern is significant when it appears in a downtrend, while + * this function does not consider it + */ + outIdx = 0; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && // long + TA_CANDLECOLOR(i) == 1 && // 2nd: white + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && // long + inOpen[i] < inLow[i-1] && // open below prior low + inClose[i] < inOpen[i-1] && // close within prior body + inClose[i] > inClose[i-1] + TA_REALBODY(i-1) * 0.5 // above midpoint + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 1; totIdx >= 0; --totIdx) + BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); + i++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlPiercing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlPiercing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlPiercing( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLPIERCING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(BodyLongPeriodTotal,2); +/* Generated */ int i, outIdx, totIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLPIERCING)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal[1] = 0; +/* Generated */ BodyLongPeriodTotal[0] = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ BodyLongPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && // long +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 2nd: white +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[0], i ) && // long +/* Generated */ inOpen[i] < inLow[i-1] && // open below prior low +/* Generated */ inClose[i] < inOpen[i-1] && // close within prior body +/* Generated */ inClose[i] > inClose[i-1] + TA_REALBODY(i-1) * 0.5 // above midpoint +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ for (totIdx = 1; totIdx >= 0; --totIdx) +/* Generated */ BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLRICKSHAWMAN.c b/talib/ta_func/ta_CDLRICKSHAWMAN.c new file mode 100644 index 0000000..1143ad7 --- /dev/null +++ b/talib/ta_func/ta_CDLRICKSHAWMAN.c @@ -0,0 +1,422 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlRickshawManLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlRickshawManLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLRICKSHAWMAN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(ShadowLong) ), + TA_CANDLEAVGPERIOD(Near) + ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLRICKSHAWMAN - Rickshaw Man + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlRickshawMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlRickshawMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlRickshawMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLRICKSHAWMAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, ShadowLongPeriodTotal, NearPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, ShadowLongTrailingIdx, NearTrailingIdx, lookbackTotal; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLRICKSHAWMAN)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyDojiPeriodTotal = 0; + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + NearPeriodTotal = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal += TA_CANDLERANGE( Near, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * + * Must have: + * - doji body + * - two long shadows + * - body near the midpoint of the high-low range + * The meaning of "doji" and "near" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100) but this does not mean it is bullish: rickshaw man shows uncertainty + */ + outIdx = 0; + do + { +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && // doji + TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow + ( // body near midpoint + min( inOpen[i], inClose[i] ) + <= inLow[i] + TA_HIGHLOWRANGE(i) / 2 + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i ) + && + max( inOpen[i], inClose[i] ) + >= inLow[i] + TA_HIGHLOWRANGE(i) / 2 - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i ) + ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); + NearPeriodTotal += TA_CANDLERANGE( Near, i ) - TA_CANDLERANGE( Near, NearTrailingIdx ); +#endif + + i++; + BodyDojiTrailingIdx++; + ShadowLongTrailingIdx++; + NearTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlRickshawMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlRickshawMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlRickshawMan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLRICKSHAWMAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, ShadowLongPeriodTotal, NearPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, ShadowLongTrailingIdx, NearTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLRICKSHAWMAN)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ NearPeriodTotal = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && // doji +/* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long shadow +/* Generated */ ( // body near midpoint +/* Generated */ min( inOpen[i], inClose[i] ) +/* Generated */ <= inLow[i] + TA_HIGHLOWRANGE(i) / 2 + TA_CANDLEAVERAGE( Near, NearPeriodTotal, i ) +/* Generated */ && +/* Generated */ max( inOpen[i], inClose[i] ) +/* Generated */ >= inLow[i] + TA_HIGHLOWRANGE(i) / 2 - TA_CANDLEAVERAGE( Near, NearPeriodTotal, i ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i ) - TA_CANDLERANGE( Near, NearTrailingIdx ); +/* Generated */ #endif +/* Generated */ i++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ NearTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLRISEFALL3METHODS.c b/talib/ta_func/ta_CDLRISEFALL3METHODS.c new file mode 100644 index 0000000..d4eaae2 --- /dev/null +++ b/talib/ta_func/ta_CDLRISEFALL3METHODS.c @@ -0,0 +1,441 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 020605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlRiseFall3MethodsLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlRiseFall3MethodsLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLRISEFALL3METHODS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 4; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLRISEFALL3METHODS - Rising/Falling Three Methods + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlRiseFall3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlRiseFall3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlRiseFall3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLRISEFALL3METHODS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(BodyPeriodTotal,5); + int i, outIdx, totIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLRISEFALL3METHODS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal[4] = 0; + BodyPeriodTotal[3] = 0; + BodyPeriodTotal[2] = 0; + BodyPeriodTotal[1] = 0; + BodyPeriodTotal[0] = 0; + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal[3] += TA_CANDLERANGE( BodyShort, i-3 ); + BodyPeriodTotal[2] += TA_CANDLERANGE( BodyShort, i-2 ); + BodyPeriodTotal[1] += TA_CANDLERANGE( BodyShort, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ); + BodyPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long white (black) candlestick + * - then: group of falling (rising) small real body candlesticks (commonly black (white)) that hold within + * the prior long candle's range: ideally they should be three but two or more than three are ok too + * - final candle: long white (black) candle that opens above (below) the previous small candle's close + * and closes above (below) the first long candle's close + * The meaning of "short" and "long" is specified with TA_SetCandleSettings; here only patterns with 3 small candles + * are considered; + * outInteger is positive (1 to 100) or negative (-1 to -100) + */ + outIdx = 0; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( // 1st long, then 3 small, 5th long + TA_REALBODY(i-4) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal[4], i-4 ) && + TA_REALBODY(i-3) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[3], i-3 ) && + TA_REALBODY(i-2) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[2], i-2 ) && + TA_REALBODY(i-1) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[1], i-1 ) && + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal[0], i ) && + // white, 3 black, white || black, 3 white, black + TA_CANDLECOLOR(i-4) == -TA_CANDLECOLOR(i-3) && + TA_CANDLECOLOR(i-3) == TA_CANDLECOLOR(i-2) && + TA_CANDLECOLOR(i-2) == TA_CANDLECOLOR(i-1) && + TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && + // 2nd to 4th hold within 1st: a part of the real body must be within 1st range + min(inOpen[i-3], inClose[i-3]) < inHigh[i-4] && max(inOpen[i-3], inClose[i-3]) > inLow[i-4] && + min(inOpen[i-2], inClose[i-2]) < inHigh[i-4] && max(inOpen[i-2], inClose[i-2]) > inLow[i-4] && + min(inOpen[i-1], inClose[i-1]) < inHigh[i-4] && max(inOpen[i-1], inClose[i-1]) > inLow[i-4] && + // 2nd to 4th are falling (rising) + inClose[i-2] * TA_CANDLECOLOR(i-4) < inClose[i-3] * TA_CANDLECOLOR(i-4) && + inClose[i-1] * TA_CANDLECOLOR(i-4) < inClose[i-2] * TA_CANDLECOLOR(i-4) && + // 5th opens above (below) the prior close + inOpen[i] * TA_CANDLECOLOR(i-4) > inClose[i-1] * TA_CANDLECOLOR(i-4) && + // 5th closes above (below) the 1st close + inClose[i] * TA_CANDLECOLOR(i-4) > inClose[i-4] * TA_CANDLECOLOR(i-4) + ) + outInteger[outIdx++] = 100 * TA_CANDLECOLOR(i-4); + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-4 ); + for (totIdx = 3; totIdx >= 1; --totIdx) + BodyPeriodTotal[totIdx] += TA_CANDLERANGE( BodyShort, i-totIdx ) + - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx-totIdx ); + BodyPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + + i++; + BodyShortTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); +#endif + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlRiseFall3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlRiseFall3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlRiseFall3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLRISEFALL3METHODS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(BodyPeriodTotal,5); +/* Generated */ int i, outIdx, totIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLRISEFALL3METHODS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal[4] = 0; +/* Generated */ BodyPeriodTotal[3] = 0; +/* Generated */ BodyPeriodTotal[2] = 0; +/* Generated */ BodyPeriodTotal[1] = 0; +/* Generated */ BodyPeriodTotal[0] = 0; +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal[3] += TA_CANDLERANGE( BodyShort, i-3 ); +/* Generated */ BodyPeriodTotal[2] += TA_CANDLERANGE( BodyShort, i-2 ); +/* Generated */ BodyPeriodTotal[1] += TA_CANDLERANGE( BodyShort, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ); +/* Generated */ BodyPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( // 1st long, then 3 small, 5th long +/* Generated */ TA_REALBODY(i-4) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal[4], i-4 ) && +/* Generated */ TA_REALBODY(i-3) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[3], i-3 ) && +/* Generated */ TA_REALBODY(i-2) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[2], i-2 ) && +/* Generated */ TA_REALBODY(i-1) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal[1], i-1 ) && +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyPeriodTotal[0], i ) && +/* Generated */ // white, 3 black, white || black, 3 white, black +/* Generated */ TA_CANDLECOLOR(i-4) == -TA_CANDLECOLOR(i-3) && +/* Generated */ TA_CANDLECOLOR(i-3) == TA_CANDLECOLOR(i-2) && +/* Generated */ TA_CANDLECOLOR(i-2) == TA_CANDLECOLOR(i-1) && +/* Generated */ TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && +/* Generated */ // 2nd to 4th hold within 1st: a part of the real body must be within 1st range +/* Generated */ min(inOpen[i-3], inClose[i-3]) < inHigh[i-4] && max(inOpen[i-3], inClose[i-3]) > inLow[i-4] && +/* Generated */ min(inOpen[i-2], inClose[i-2]) < inHigh[i-4] && max(inOpen[i-2], inClose[i-2]) > inLow[i-4] && +/* Generated */ min(inOpen[i-1], inClose[i-1]) < inHigh[i-4] && max(inOpen[i-1], inClose[i-1]) > inLow[i-4] && +/* Generated */ // 2nd to 4th are falling (rising) +/* Generated */ inClose[i-2] * TA_CANDLECOLOR(i-4) < inClose[i-3] * TA_CANDLECOLOR(i-4) && +/* Generated */ inClose[i-1] * TA_CANDLECOLOR(i-4) < inClose[i-2] * TA_CANDLECOLOR(i-4) && +/* Generated */ // 5th opens above (below) the prior close +/* Generated */ inOpen[i] * TA_CANDLECOLOR(i-4) > inClose[i-1] * TA_CANDLECOLOR(i-4) && +/* Generated */ // 5th closes above (below) the 1st close +/* Generated */ inClose[i] * TA_CANDLECOLOR(i-4) > inClose[i-4] * TA_CANDLECOLOR(i-4) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100 * TA_CANDLECOLOR(i-4); +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal[4] += TA_CANDLERANGE( BodyLong, i-4 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-4 ); +/* Generated */ for (totIdx = 3; totIdx >= 1; --totIdx) +/* Generated */ BodyPeriodTotal[totIdx] += TA_CANDLERANGE( BodyShort, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx-totIdx ); +/* Generated */ BodyPeriodTotal[0] += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLSEPARATINGLINES.c b/talib/ta_func/ta_CDLSEPARATINGLINES.c new file mode 100644 index 0000000..d0c9d57 --- /dev/null +++ b/talib/ta_func/ta_CDLSEPARATINGLINES.c @@ -0,0 +1,417 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlSeperatingLinesLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlSeperatingLinesLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLSEPARATINGLINES_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(BodyLong) ), + TA_CANDLEAVGPERIOD(Equal) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLSEPARATINGLINES - Separating Lines + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlSeperatingLines( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlSeperatingLines( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlSeperatingLines( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLSEPARATINGLINES( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double ShadowVeryShortPeriodTotal, BodyLongPeriodTotal, EqualPeriodTotal; + int i, outIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, EqualTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLSEPARATINGLINES)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: black (white) candle + * - second candle: bullish (bearish) belt hold with the same open as the prior candle + * The meaning of "long body" and "very short shadow" of the belt hold is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that separating lines is significant when coming in a trend and the belt hold has + * the same direction of the trend, while this function does not consider it + */ + outIdx = 0; + do + { + if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles + inOpen[i] <= inOpen[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // same open + inOpen[i] >= inOpen[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && + TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && // belt hold: long body + ( + ( TA_CANDLECOLOR(i) == 1 && // with no lower shadow if bullish + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) + || + ( TA_CANDLECOLOR(i) == -1 && // with no upper shadow if bearish + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) + ) + ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + i++; + ShadowVeryShortTrailingIdx++; + BodyLongTrailingIdx++; + EqualTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlSeperatingLines( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlSeperatingLines( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlSeperatingLines( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLSEPARATINGLINES( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double ShadowVeryShortPeriodTotal, BodyLongPeriodTotal, EqualPeriodTotal; +/* Generated */ int i, outIdx, ShadowVeryShortTrailingIdx, BodyLongTrailingIdx, EqualTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLSEPARATINGLINES)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // opposite candles +/* Generated */ inOpen[i] <= inOpen[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // same open +/* Generated */ inOpen[i] >= inOpen[i-1] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && +/* Generated */ TA_REALBODY(i) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i ) && // belt hold: long body +/* Generated */ ( +/* Generated */ ( TA_CANDLECOLOR(i) == 1 && // with no lower shadow if bullish +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) +/* Generated */ || +/* Generated */ ( TA_CANDLECOLOR(i) == -1 && // with no upper shadow if bearish +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLSHOOTINGSTAR.c b/talib/ta_func/ta_CDLSHOOTINGSTAR.c new file mode 100644 index 0000000..9bf17b5 --- /dev/null +++ b/talib/ta_func/ta_CDLSHOOTINGSTAR.c @@ -0,0 +1,407 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 103004 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlShootingStarLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlShootingStarLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLSHOOTINGSTAR_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowLong) ), + TA_CANDLEAVGPERIOD(ShadowVeryShort) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLSHOOTINGSTAR - Shooting Star + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlShootingStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlShootingStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlShootingStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLSHOOTINGSTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLSHOOTINGSTAR)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowLongPeriodTotal = 0; + ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowLongTrailingIdx; + while( i < startIdx ) { + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - small real body + * - long upper shadow + * - no, or very short, lower shadow + * - gap up from prior real body + * The meaning of "short", "very short" and "long" is specified with TA_SetCandleSettings; + * outInteger is negative (-1 to -100): shooting star is always bearish; + * the user should consider that a shooting star must appear in an uptrend, while this function does not consider it + */ + outIdx = 0; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb + TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long upper shadow + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short lower shadow + TA_REALBODYGAPUP(i, i-1) ) // gap up + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) + - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) + - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowLongTrailingIdx++; + ShadowVeryShortTrailingIdx++; + } while( i <= endIdx ); +#endif + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlShootingStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlShootingStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlShootingStar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLSHOOTINGSTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowLongPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowLongTrailingIdx, ShadowVeryShortTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLSHOOTINGSTAR)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowLongPeriodTotal = 0; +/* Generated */ ShadowLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowLong); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && // small rb +/* Generated */ TA_UPPERSHADOW(i) > TA_CANDLEAVERAGE( ShadowLong, ShadowLongPeriodTotal, i ) && // long upper shadow +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && // very short lower shadow +/* Generated */ TA_REALBODYGAPUP(i, i-1) ) // gap up +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) +/* Generated */ - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ ShadowLongPeriodTotal += TA_CANDLERANGE( ShadowLong, i ) +/* Generated */ - TA_CANDLERANGE( ShadowLong, ShadowLongTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowLongTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLSHORTLINE.c b/talib/ta_func/ta_CDLSHORTLINE.c new file mode 100644 index 0000000..cda2d78 --- /dev/null +++ b/talib/ta_func/ta_CDLSHORTLINE.c @@ -0,0 +1,370 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 072404 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlShortLineLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlShortLineLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLSHORTLINE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(ShadowShort) ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLSHORTLINE - Short Line Candle + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlShortLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlShortLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlShortLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLSHORTLINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal, ShadowPeriodTotal; + int i, outIdx, BodyTrailingIdx, ShadowTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLSHORTLINE)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowPeriodTotal = 0; + ShadowTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowShort); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowTrailingIdx; + while( i < startIdx ) { + ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - short real body + * - short upper and lower shadow + * The meaning of "short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white, negative (-1 to -100) when black; + * it does not mean bullish or bearish + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) && + TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ) - TA_CANDLERANGE( ShadowShort, ShadowTrailingIdx ); + i++; + BodyTrailingIdx++; + ShadowTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlShortLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlShortLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlShortLine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLSHORTLINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal, ShadowPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, ShadowTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLSHORTLINE)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowPeriodTotal = 0; +/* Generated */ ShadowTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowShort); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) < TA_CANDLEAVERAGE( ShadowShort, ShadowPeriodTotal, i ) ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ ShadowPeriodTotal += TA_CANDLERANGE( ShadowShort, i ) - TA_CANDLERANGE( ShadowShort, ShadowTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ ShadowTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLSPINNINGTOP.c b/talib/ta_func/ta_CDLSPINNINGTOP.c new file mode 100644 index 0000000..ece023b --- /dev/null +++ b/talib/ta_func/ta_CDLSPINNINGTOP.c @@ -0,0 +1,354 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 071804 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlSpinningTopLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlSpinningTopLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLSPINNINGTOP_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(BodyShort); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLSPINNINGTOP - Spinning Top + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlSpinningTop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlSpinningTop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlSpinningTop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLSPINNINGTOP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal; + int i, outIdx, BodyTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLSPINNINGTOP)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyTrailingIdx; + while( i < startIdx ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - small real body + * - shadows longer than the real body + * The meaning of "short" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when white or negative (-1 to -100) when black; + * it does not mean bullish or bearish + */ + outIdx = 0; + do + { + if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && + TA_UPPERSHADOW(i) > TA_REALBODY(i) && + TA_LOWERSHADOW(i) > TA_REALBODY(i) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); + i++; + BodyTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlSpinningTop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlSpinningTop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlSpinningTop( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLSPINNINGTOP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLSPINNINGTOP)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) > TA_REALBODY(i) && +/* Generated */ TA_LOWERSHADOW(i) > TA_REALBODY(i) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLSTALLEDPATTERN.c b/talib/ta_func/ta_CDLSTALLEDPATTERN.c new file mode 100644 index 0000000..8d124b5 --- /dev/null +++ b/talib/ta_func/ta_CDLSTALLEDPATTERN.c @@ -0,0 +1,474 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120804 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlStalledPatternLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlStalledPatternLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLSTALLEDPATTERN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(BodyLong), TA_CANDLEAVGPERIOD(BodyShort) ), + max( TA_CANDLEAVGPERIOD(ShadowVeryShort), TA_CANDLEAVGPERIOD(Near) ) + ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLSTALLEDPATTERN - Stalled Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlStalledPattern( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlStalledPattern( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlStalledPattern( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLSTALLEDPATTERN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_LOCAL(BodyLongPeriodTotal,3); + ARRAY_LOCAL(NearPeriodTotal,3); + double BodyShortPeriodTotal, ShadowVeryShortPeriodTotal; + int i, outIdx, totIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, + lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLSTALLEDPATTERN)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal[2] = 0; + BodyLongPeriodTotal[1] = 0; + BodyLongPeriodTotal[0] = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortPeriodTotal = 0; + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + NearPeriodTotal[2] = 0; + NearPeriodTotal[1] = 0; + NearPeriodTotal[0] = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal[2] += TA_CANDLERANGE( BodyLong, i-2 ); + BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ); + i++; + } + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); + NearPeriodTotal[1] += TA_CANDLERANGE( Near, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - three white candlesticks with consecutively higher closes + * - first candle: long white + * - second candle: long white with no or very short upper shadow opening within or near the previous white real body + * and closing higher than the prior candle + * - third candle: small white that gaps away or "rides on the shoulder" of the prior long real body (= it's at + * the upper end of the prior real body) + * The meanings of "long", "very short", "short", "near" are specified with TA_SetCandleSettings; + * outInteger is negative (-1 to -100): stalled pattern is always bearish; + * the user should consider that stalled pattern is significant when it appears in uptrend, while this function + * does not consider it + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_CANDLECOLOR(i-2) == 1 && // 1st white + TA_CANDLECOLOR(i-1) == 1 && // 2nd white + TA_CANDLECOLOR(i) == 1 && // 3rd white + inClose[i] > inClose[i-1] && inClose[i-1] > inClose[i-2] && // consecutive higher closes + TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[2], i-2 ) && // 1st: long real body + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && // 2nd: long real body + // very short upper shadow + TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i-1 ) && + // opens within/near 1st real body + inOpen[i-1] > inOpen[i-2] && + inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && + TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: small real body + // rides on the shoulder of 2nd real body + inOpen[i] >= inClose[i-1] - TA_REALBODY(i) - TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + for (totIdx = 2; totIdx >= 1; --totIdx) { + BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); + NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) + - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); + } + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-1 ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + ShadowVeryShortTrailingIdx++; + NearTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlStalledPattern( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlStalledPattern( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlStalledPattern( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLSTALLEDPATTERN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_LOCAL(BodyLongPeriodTotal,3); +/* Generated */ ARRAY_LOCAL(NearPeriodTotal,3); +/* Generated */ double BodyShortPeriodTotal, ShadowVeryShortPeriodTotal; +/* Generated */ int i, outIdx, totIdx, BodyLongTrailingIdx, BodyShortTrailingIdx, ShadowVeryShortTrailingIdx, NearTrailingIdx, +/* Generated */ lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLSTALLEDPATTERN)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal[2] = 0; +/* Generated */ BodyLongPeriodTotal[1] = 0; +/* Generated */ BodyLongPeriodTotal[0] = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ NearPeriodTotal[2] = 0; +/* Generated */ NearPeriodTotal[1] = 0; +/* Generated */ NearPeriodTotal[0] = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal[2] += TA_CANDLERANGE( BodyLong, i-2 ); +/* Generated */ BodyLongPeriodTotal[1] += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal[2] += TA_CANDLERANGE( Near, i-2 ); +/* Generated */ NearPeriodTotal[1] += TA_CANDLERANGE( Near, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-2) == 1 && // 1st white +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && // 2nd white +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 3rd white +/* Generated */ inClose[i] > inClose[i-1] && inClose[i-1] > inClose[i-2] && // consecutive higher closes +/* Generated */ TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[2], i-2 ) && // 1st: long real body +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal[1], i-1 ) && // 2nd: long real body +/* Generated */ // very short upper shadow +/* Generated */ TA_UPPERSHADOW(i-1) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i-1 ) && +/* Generated */ // opens within/near 1st real body +/* Generated */ inOpen[i-1] > inOpen[i-2] && +/* Generated */ inOpen[i-1] <= inClose[i-2] + TA_CANDLEAVERAGE( Near, NearPeriodTotal[2], i-2 ) && +/* Generated */ TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: small real body +/* Generated */ // rides on the shoulder of 2nd real body +/* Generated */ inOpen[i] >= inClose[i-1] - TA_REALBODY(i) - TA_CANDLEAVERAGE( Near, NearPeriodTotal[1], i-1 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ for (totIdx = 2; totIdx >= 1; --totIdx) { +/* Generated */ BodyLongPeriodTotal[totIdx] += TA_CANDLERANGE( BodyLong, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-totIdx ); +/* Generated */ NearPeriodTotal[totIdx] += TA_CANDLERANGE( Near, i-totIdx ) +/* Generated */ - TA_CANDLERANGE( Near, NearTrailingIdx-totIdx ); +/* Generated */ } +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i-1 ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ NearTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLSTICKSANDWICH.c b/talib/ta_func/ta_CDLSTICKSANDWICH.c new file mode 100644 index 0000000..2703e16 --- /dev/null +++ b/talib/ta_func/ta_CDLSTICKSANDWICH.c @@ -0,0 +1,364 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 032005 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlStickSandwhichLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlStickSandwhichLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLSTICKSANDWICH_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(Equal) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLSTICKSANDWICH - Stick Sandwich + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlStickSandwhich( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlStickSandwhich( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlStickSandwhich( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLSTICKSANDWICH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double EqualPeriodTotal; + int i, outIdx, EqualTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLSTICKSANDWICH)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-2 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: black candle + * - second candle: white candle that trades only above the prior close (low > prior close) + * - third candle: black candle with the close equal to the first candle's close + * The meaning of "equal" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100): stick sandwich is always bullish; + * the user should consider that stick sandwich is significant when coming in a downtrend, + * while this function does not consider it + */ + outIdx = 0; + do + { + if( TA_CANDLECOLOR(i-2) == -1 && // first black + TA_CANDLECOLOR(i-1) == 1 && // second white + TA_CANDLECOLOR(i) == -1 && // third black + inLow[i-1] > inClose[i-2] && // 2nd low > prior close + inClose[i] <= inClose[i-2] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-2 ) && // 1st and 3rd same close + inClose[i] >= inClose[i-2] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-2 ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-2 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-2 ); + i++; + EqualTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlStickSandwhich( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlStickSandwhich( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlStickSandwhich( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLSTICKSANDWICH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double EqualPeriodTotal; +/* Generated */ int i, outIdx, EqualTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLSTICKSANDWICH)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-2 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-2) == -1 && // first black +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && // second white +/* Generated */ TA_CANDLECOLOR(i) == -1 && // third black +/* Generated */ inLow[i-1] > inClose[i-2] && // 2nd low > prior close +/* Generated */ inClose[i] <= inClose[i-2] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-2 ) && // 1st and 3rd same close +/* Generated */ inClose[i] >= inClose[i-2] - TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-2 ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-2 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-2 ); +/* Generated */ i++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLTAKURI.c b/talib/ta_func/ta_CDLTAKURI.c new file mode 100644 index 0000000..fe05088 --- /dev/null +++ b/talib/ta_func/ta_CDLTAKURI.c @@ -0,0 +1,406 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011505 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlTakuriLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlTakuriLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLTAKURI_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( max( TA_CANDLEAVGPERIOD(BodyDoji), TA_CANDLEAVGPERIOD(ShadowVeryShort) ), + TA_CANDLEAVGPERIOD(ShadowVeryLong) + ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLTAKURI - Takuri (Dragonfly Doji with very long lower shadow) + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlTakuri( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlTakuri( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlTakuri( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLTAKURI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal, ShadowVeryLongPeriodTotal; + int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, ShadowVeryLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLTAKURI)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyDojiPeriodTotal = 0; + BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); + ShadowVeryShortPeriodTotal = 0; + ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); + ShadowVeryLongPeriodTotal = 0; + ShadowVeryLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryLong); + + i = BodyDojiTrailingIdx; + while( i < startIdx ) { + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + i = ShadowVeryShortTrailingIdx; + while( i < startIdx ) { + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); + i++; + } + i = ShadowVeryLongTrailingIdx; + while( i < startIdx ) { + ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * + * Must have: + * - doji body + * - open and close at the high of the day = no or very short upper shadow + * - very long lower shadow + * The meaning of "doji", "very short" and "very long" is specified with TA_SetCandleSettings + * outInteger is always positive (1 to 100) but this does not mean it is bullish: takuri must be considered + * relatively to the trend + */ + outIdx = 0; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && + TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && + TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowVeryLongPeriodTotal, i ) + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); + ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) + - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); + ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ) + - TA_CANDLERANGE( ShadowVeryLong, ShadowVeryLongTrailingIdx ); + i++; + BodyDojiTrailingIdx++; + ShadowVeryShortTrailingIdx++; + ShadowVeryLongTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlTakuri( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlTakuri( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlTakuri( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLTAKURI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyDojiPeriodTotal, ShadowVeryShortPeriodTotal, ShadowVeryLongPeriodTotal; +/* Generated */ int i, outIdx, BodyDojiTrailingIdx, ShadowVeryShortTrailingIdx, ShadowVeryLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLTAKURI)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyDojiPeriodTotal = 0; +/* Generated */ BodyDojiTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ ShadowVeryShortPeriodTotal = 0; +/* Generated */ ShadowVeryShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryShort); +/* Generated */ ShadowVeryLongPeriodTotal = 0; +/* Generated */ ShadowVeryLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(ShadowVeryLong); +/* Generated */ i = BodyDojiTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = ShadowVeryLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyDojiPeriodTotal, i ) && +/* Generated */ TA_UPPERSHADOW(i) < TA_CANDLEAVERAGE( ShadowVeryShort, ShadowVeryShortPeriodTotal, i ) && +/* Generated */ TA_LOWERSHADOW(i) > TA_CANDLEAVERAGE( ShadowVeryLong, ShadowVeryLongPeriodTotal, i ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyDojiPeriodTotal += TA_CANDLERANGE( BodyDoji, i ) - TA_CANDLERANGE( BodyDoji, BodyDojiTrailingIdx ); +/* Generated */ ShadowVeryShortPeriodTotal += TA_CANDLERANGE( ShadowVeryShort, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryShort, ShadowVeryShortTrailingIdx ); +/* Generated */ ShadowVeryLongPeriodTotal += TA_CANDLERANGE( ShadowVeryLong, i ) +/* Generated */ - TA_CANDLERANGE( ShadowVeryLong, ShadowVeryLongTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyDojiTrailingIdx++; +/* Generated */ ShadowVeryShortTrailingIdx++; +/* Generated */ ShadowVeryLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLTASUKIGAP.c b/talib/ta_func/ta_CDLTASUKIGAP.c new file mode 100644 index 0000000..77dc35a --- /dev/null +++ b/talib/ta_func/ta_CDLTASUKIGAP.c @@ -0,0 +1,396 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlTasukiGapLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlTasukiGapLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLTASUKIGAP_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(Near) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLTASUKIGAP - Tasuki Gap + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlTasukiGap( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlTasukiGap( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlTasukiGap( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLTASUKIGAP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double NearPeriodTotal; + int i, outIdx, NearTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLTASUKIGAP)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + NearPeriodTotal = 0; + NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); + + i = NearTrailingIdx; + while( i < startIdx ) { + NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - upside (downside) gap + * - first candle after the window: white (black) candlestick + * - second candle: black (white) candlestick that opens within the previous real body and closes under (above) + * the previous real body inside the gap + * - the size of two real bodies should be near the same + * The meaning of "near" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that tasuki gap is significant when it appears in a trend, while this function does + * not consider it + */ + outIdx = 0; + do + { + if( + ( + TA_REALBODYGAPUP(i-1,i-2) && // upside gap + TA_CANDLECOLOR(i-1) == 1 && // 1st: white + TA_CANDLECOLOR(i) == -1 && // 2nd: black + inOpen[i] < inClose[i-1] && inOpen[i] > inOpen[i-1] && // that opens within the white rb + inClose[i] < inOpen[i-1] && // and closes under the white rb + inClose[i] > max(inClose[i-2], inOpen[i-2]) && // inside the gap + // size of 2 rb near the same + std_fabs(TA_REALBODY(i-1) - TA_REALBODY(i)) < TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) + ) || + ( + TA_REALBODYGAPDOWN(i-1,i-2) && // downside gap + TA_CANDLECOLOR(i-1) == -1 && // 1st: black + TA_CANDLECOLOR(i) == 1 && // 2nd: white + inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // that opens within the black rb + inClose[i] > inOpen[i-1] && // and closes above the black rb + inClose[i] < min(inClose[i-2], inOpen[i-2]) && // inside the gap + // size of 2 rb near the same + std_fabs(TA_REALBODY(i-1) - TA_REALBODY(i)) < TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) + ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i-1) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) - TA_CANDLERANGE( Near, NearTrailingIdx-1 ); + i++; + NearTrailingIdx++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlTasukiGap( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlTasukiGap( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlTasukiGap( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLTASUKIGAP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double NearPeriodTotal; +/* Generated */ int i, outIdx, NearTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLTASUKIGAP)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ NearPeriodTotal = 0; +/* Generated */ NearTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Near); +/* Generated */ i = NearTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( +/* Generated */ ( +/* Generated */ TA_REALBODYGAPUP(i-1,i-2) && // upside gap +/* Generated */ TA_CANDLECOLOR(i-1) == 1 && // 1st: white +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 2nd: black +/* Generated */ inOpen[i] < inClose[i-1] && inOpen[i] > inOpen[i-1] && // that opens within the white rb +/* Generated */ inClose[i] < inOpen[i-1] && // and closes under the white rb +/* Generated */ inClose[i] > max(inClose[i-2], inOpen[i-2]) && // inside the gap +/* Generated */ // size of 2 rb near the same +/* Generated */ std_fabs(TA_REALBODY(i-1) - TA_REALBODY(i)) < TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) +/* Generated */ ) || +/* Generated */ ( +/* Generated */ TA_REALBODYGAPDOWN(i-1,i-2) && // downside gap +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 1st: black +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 2nd: white +/* Generated */ inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // that opens within the black rb +/* Generated */ inClose[i] > inOpen[i-1] && // and closes above the black rb +/* Generated */ inClose[i] < min(inClose[i-2], inOpen[i-2]) && // inside the gap +/* Generated */ // size of 2 rb near the same +/* Generated */ std_fabs(TA_REALBODY(i-1) - TA_REALBODY(i)) < TA_CANDLEAVERAGE( Near, NearPeriodTotal, i-1 ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i-1) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ NearPeriodTotal += TA_CANDLERANGE( Near, i-1 ) - TA_CANDLERANGE( Near, NearTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ NearTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLTHRUSTING.c b/talib/ta_func/ta_CDLTHRUSTING.c new file mode 100644 index 0000000..8ce5796 --- /dev/null +++ b/talib/ta_func/ta_CDLTHRUSTING.c @@ -0,0 +1,393 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 121204 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlThrustingLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlThrustingLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLTHRUSTING_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(Equal), TA_CANDLEAVGPERIOD(BodyLong) + ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLTHRUSTING - Thrusting Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlThrusting( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlThrusting( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlThrusting( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLTHRUSTING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double EqualPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLTHRUSTING)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + EqualPeriodTotal = 0; + EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); + BodyLongPeriodTotal = 0; + BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); + + i = EqualTrailingIdx; + while( i < startIdx ) { + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); + i++; + } + i = BodyLongTrailingIdx; + while( i < startIdx ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle + * - second candle: white candle with open below previous day low and close into previous day body under the midpoint; + * to differentiate it from in-neck the close should not be equal to the black candle's close + * The meaning of "equal" is specified with TA_SetCandleSettings + * outInteger is negative (-1 to -100): thrusting pattern is always bearish + * the user should consider that the thrusting pattern is significant when it appears in a downtrend and it could be + * even bullish "when coming in an uptrend or occurring twice within several days" (Steve Nison says), while this + * function does not consider the trend + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black + TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long + TA_CANDLECOLOR(i) == 1 && // 2nd: white + inOpen[i] < inLow[i-1] && // open below prior low + inClose[i] > inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close into prior body + inClose[i] <= inClose[i-1] + TA_REALBODY(i-1) * 0.5 // under the midpoint + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) + - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); + i++; + EqualTrailingIdx++; + BodyLongTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlThrusting( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlThrusting( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlThrusting( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLTHRUSTING( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double EqualPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, EqualTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLTHRUSTING)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ EqualPeriodTotal = 0; +/* Generated */ EqualTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(Equal); +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ i = EqualTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-1) == -1 && // 1st: black +/* Generated */ TA_REALBODY(i-1) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-1 ) && // long +/* Generated */ TA_CANDLECOLOR(i) == 1 && // 2nd: white +/* Generated */ inOpen[i] < inLow[i-1] && // open below prior low +/* Generated */ inClose[i] > inClose[i-1] + TA_CANDLEAVERAGE( Equal, EqualPeriodTotal, i-1 ) && // close into prior body +/* Generated */ inClose[i] <= inClose[i-1] + TA_REALBODY(i-1) * 0.5 // under the midpoint +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ EqualPeriodTotal += TA_CANDLERANGE( Equal, i-1 ) - TA_CANDLERANGE( Equal, EqualTrailingIdx-1 ); +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-1 ) +/* Generated */ - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx-1 ); +/* Generated */ i++; +/* Generated */ EqualTrailingIdx++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLTRISTAR.c b/talib/ta_func/ta_CDLTRISTAR.c new file mode 100644 index 0000000..a36d6f2 --- /dev/null +++ b/talib/ta_func/ta_CDLTRISTAR.c @@ -0,0 +1,391 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * CSB Christopher Barnhouse + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 100204 AC Creation + * 051005 CSB,AC Fix #1199526 for out-of-bound write in output. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlTristarLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlTristarLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLTRISTAR_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return TA_CANDLEAVGPERIOD(BodyDoji) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLTRISTAR - Tristar Pattern + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlTristar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlTristar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlTristar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLTRISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyPeriodTotal; + int i, outIdx, BodyTrailingIdx, lookbackTotal; + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#endif + + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLTRISTAR)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyPeriodTotal = 0; + BodyTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyDoji); + + i = BodyTrailingIdx; + while( i < startIdx-2 ) { + BodyPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); + i++; + } + + /* Proceed with the calculation for the requested range. + * Must have: + * - 3 consecutive doji days + * - the second doji is a star + * The meaning of "doji" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish + */ + i = startIdx; + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i-2) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) && // 1st: doji + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) && // 2nd: doji + TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) ) { // 3rd: doji + outInteger[outIdx] = 0; + if ( TA_REALBODYGAPUP(i-1,i-2) // 2nd gaps up + && + max(inOpen[i],inClose[i]) < max(inOpen[i-1],inClose[i-1]) // 3rd is not higher than 2nd + ) + outInteger[outIdx] = -100; + if ( TA_REALBODYGAPDOWN(i-1,i-2) // 2nd gaps down + && + min(inOpen[i],inClose[i]) > min(inOpen[i-1],inClose[i-1]) // 3rd is not lower than 2nd + ) + outInteger[outIdx] = +100; + outIdx++; + } + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyPeriodTotal += TA_CANDLERANGE( BodyDoji, i-2 ) - TA_CANDLERANGE( BodyDoji, BodyTrailingIdx ); + i++; + BodyTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlTristar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlTristar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlTristar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLTRISTAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyPeriodTotal; +/* Generated */ int i, outIdx, BodyTrailingIdx, lookbackTotal; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLTRISTAR)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyPeriodTotal = 0; +/* Generated */ BodyTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyDoji); +/* Generated */ i = BodyTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyDoji, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i-2) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) && // 1st: doji +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) && // 2nd: doji +/* Generated */ TA_REALBODY(i) <= TA_CANDLEAVERAGE( BodyDoji, BodyPeriodTotal, i-2 ) ) { // 3rd: doji +/* Generated */ outInteger[outIdx] = 0; +/* Generated */ if ( TA_REALBODYGAPUP(i-1,i-2) // 2nd gaps up +/* Generated */ && +/* Generated */ max(inOpen[i],inClose[i]) < max(inOpen[i-1],inClose[i-1]) // 3rd is not higher than 2nd +/* Generated */ ) +/* Generated */ outInteger[outIdx] = -100; +/* Generated */ if ( TA_REALBODYGAPDOWN(i-1,i-2) // 2nd gaps down +/* Generated */ && +/* Generated */ min(inOpen[i],inClose[i]) > min(inOpen[i-1],inClose[i-1]) // 3rd is not lower than 2nd +/* Generated */ ) +/* Generated */ outInteger[outIdx] = +100; +/* Generated */ outIdx++; +/* Generated */ } +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyPeriodTotal += TA_CANDLERANGE( BodyDoji, i-2 ) - TA_CANDLERANGE( BodyDoji, BodyTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLUNIQUE3RIVER.c b/talib/ta_func/ta_CDLUNIQUE3RIVER.c new file mode 100644 index 0000000..e4502e4 --- /dev/null +++ b/talib/ta_func/ta_CDLUNIQUE3RIVER.c @@ -0,0 +1,392 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 022005 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlUnique3RiverLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlUnique3RiverLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLUNIQUE3RIVER_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLUNIQUE3RIVER - Unique 3 River + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlUnique3River( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlUnique3River( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlUnique3River( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLUNIQUE3RIVER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLUNIQUE3RIVER)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: long black candle + * - second candle: black harami candle with a lower low than the first candle's low + * - third candle: small white candle with open not lower than the second candle's low, better if its open and + * close are under the second candle's close + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * outInteger is positive (1 to 100): unique 3 river is always bullish and should appear in a downtrend + * to be significant, while this function does not consider the trend + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long + TA_CANDLECOLOR(i-2) == -1 && // black + TA_CANDLECOLOR(i-1) == -1 && // 2nd: black + inClose[i-1] > inClose[i-2] && inOpen[i-1] <= inOpen[i-2] && // harami + inLow[i-1] < inLow[i-2] && // lower low + TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: short + TA_CANDLECOLOR(i) == 1 && // white + inOpen[i] > inLow[i-1] // open not lower + ) + outInteger[outIdx++] = 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); +#endif + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlUnique3River( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlUnique3River( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlUnique3River( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLUNIQUE3RIVER( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLUNIQUE3RIVER)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // 1st: long +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // black +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd: black +/* Generated */ inClose[i-1] > inClose[i-2] && inOpen[i-1] <= inOpen[i-2] && // harami +/* Generated */ inLow[i-1] < inLow[i-2] && // lower low +/* Generated */ TA_REALBODY(i) < TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i ) && // 3rd: short +/* Generated */ TA_CANDLECOLOR(i) == 1 && // white +/* Generated */ inOpen[i] > inLow[i-1] // open not lower +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLUPSIDEGAP2CROWS.c b/talib/ta_func/ta_CDLUPSIDEGAP2CROWS.c new file mode 100644 index 0000000..af58c83 --- /dev/null +++ b/talib/ta_func/ta_CDLUPSIDEGAP2CROWS.c @@ -0,0 +1,395 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 110104 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlUpsideGap2CrowsLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlUpsideGap2CrowsLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLUPSIDEGAP2CROWS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return max( TA_CANDLEAVGPERIOD(BodyShort), TA_CANDLEAVGPERIOD(BodyLong) ) + 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLUPSIDEGAP2CROWS - Upside Gap Two Crows + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlUpsideGap2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlUpsideGap2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlUpsideGap2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLUPSIDEGAP2CROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double BodyShortPeriodTotal, BodyLongPeriodTotal; + int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLUPSIDEGAP2CROWS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + BodyLongPeriodTotal = 0; + BodyShortPeriodTotal = 0; + BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); + BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); + + i = BodyLongTrailingIdx; + while( i < startIdx-2 ) { + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); + i++; + } + i = BodyShortTrailingIdx; + while( i < startIdx-1 ) { + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); + i++; + } + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: white candle, usually long + * - second candle: small black real body + * - gap between the first and the second candle's real bodies + * - third candle: black candle with a real body that engulfs the preceding candle + * and closes above the white candle's close + * The meaning of "short" and "long" is specified with TA_SetCandleSettings + * outInteger is negative (-1 to -100): upside gap two crows is always bearish; + * the user should consider that an upside gap two crows is significant when it appears in an uptrend, + * while this function does not consider the trend + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + if( TA_CANDLECOLOR(i-2) == 1 && // 1st: white + TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // long + TA_CANDLECOLOR(i-1) == -1 && // 2nd: black + TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // short + TA_REALBODYGAPUP(i-1,i-2) && // gapping up + TA_CANDLECOLOR(i) == -1 && // 3rd: black + inOpen[i] > inOpen[i-1] && inClose[i] < inClose[i-1] && // 3rd: engulfing prior rb + inClose[i] > inClose[i-2] // closing above 1st + ) + outInteger[outIdx++] = -100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); + BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); + i++; + BodyLongTrailingIdx++; + BodyShortTrailingIdx++; + } while( i <= endIdx ); +#endif + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlUpsideGap2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlUpsideGap2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlUpsideGap2Crows( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLUPSIDEGAP2CROWS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double BodyShortPeriodTotal, BodyLongPeriodTotal; +/* Generated */ int i, outIdx, BodyShortTrailingIdx, BodyLongTrailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLUPSIDEGAP2CROWS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ BodyLongPeriodTotal = 0; +/* Generated */ BodyShortPeriodTotal = 0; +/* Generated */ BodyLongTrailingIdx = startIdx -2 - TA_CANDLEAVGPERIOD(BodyLong); +/* Generated */ BodyShortTrailingIdx = startIdx -1 - TA_CANDLEAVGPERIOD(BodyShort); +/* Generated */ i = BodyLongTrailingIdx; +/* Generated */ while( i < startIdx-2 ) { +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = BodyShortTrailingIdx; +/* Generated */ while( i < startIdx-1 ) { +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i ); +/* Generated */ i++; +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-2) == 1 && // 1st: white +/* Generated */ TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // long +/* Generated */ TA_CANDLECOLOR(i-1) == -1 && // 2nd: black +/* Generated */ TA_REALBODY(i-1) <= TA_CANDLEAVERAGE( BodyShort, BodyShortPeriodTotal, i-1 ) && // short +/* Generated */ TA_REALBODYGAPUP(i-1,i-2) && // gapping up +/* Generated */ TA_CANDLECOLOR(i) == -1 && // 3rd: black +/* Generated */ inOpen[i] > inOpen[i-1] && inClose[i] < inClose[i-1] && // 3rd: engulfing prior rb +/* Generated */ inClose[i] > inClose[i-2] // closing above 1st +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = -100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx ); +/* Generated */ BodyShortPeriodTotal += TA_CANDLERANGE( BodyShort, i-1 ) - TA_CANDLERANGE( BodyShort, BodyShortTrailingIdx ); +/* Generated */ i++; +/* Generated */ BodyLongTrailingIdx++; +/* Generated */ BodyShortTrailingIdx++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CDLXSIDEGAP3METHODS.c b/talib/ta_func/ta_CDLXSIDEGAP3METHODS.c new file mode 100644 index 0000000..fb60b82 --- /dev/null +++ b/talib/ta_func/ta_CDLXSIDEGAP3METHODS.c @@ -0,0 +1,361 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 011605 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CdlXSideGap3MethodsLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cdlXSideGap3MethodsLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CDLXSIDEGAP3METHODS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CDLXSIDEGAP3METHODS - Upside/Downside Gap Three Methods + * + * Input = Open, High, Low, Close + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlXSideGap3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlXSideGap3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlXSideGap3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CDLXSIDEGAP3METHODS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int i, outIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + + lookbackTotal = LOOKBACK_CALL(CDLXSIDEGAP3METHODS)(); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + i = startIdx; + + /* Proceed with the calculation for the requested range. + * Must have: + * - first candle: white (black) candle + * - second candle: white (black) candle + * - upside (downside) gap between the first and the second real bodies + * - third candle: black (white) candle that opens within the second real body and closes within the first real body + * outInteger is positive (1 to 100) when bullish or negative (-1 to -100) when bearish; + * the user should consider that up/downside gap 3 methods is significant when it appears in a trend, while this + * function does not consider it + */ + outIdx = 0; + do + { + if( TA_CANDLECOLOR(i-2) == TA_CANDLECOLOR(i-1) && // 1st and 2nd of same color + TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // 3rd opposite color + inOpen[i] < max(inClose[i-1], inOpen[i-1]) && // 3rd opens within 2nd rb + inOpen[i] > min(inClose[i-1], inOpen[i-1]) && + inClose[i] < max(inClose[i-2], inOpen[i-2]) && // 3rd closes within 1st rb + inClose[i] > min(inClose[i-2], inOpen[i-2]) && + ( ( + TA_CANDLECOLOR(i-2) == 1 && // when 1st is white + TA_REALBODYGAPUP(i-1,i-2) // upside gap + ) || + ( + TA_CANDLECOLOR(i-2) == -1 && // when 1st is black + TA_REALBODYGAPDOWN(i-1,i-2) // downside gap + ) + ) + ) + outInteger[outIdx++] = TA_CANDLECOLOR(i-2) * 100; + else + outInteger[outIdx++] = 0; + /* add the current range and subtract the first range: this is done after the pattern recognition + * when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle) + */ + i++; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::CdlXSideGap3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::CdlXSideGap3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cdlXSideGap3Methods( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CDLXSIDEGAP3METHODS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i, outIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(CDLXSIDEGAP3METHODS)(); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ i = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ if( TA_CANDLECOLOR(i-2) == TA_CANDLECOLOR(i-1) && // 1st and 2nd of same color +/* Generated */ TA_CANDLECOLOR(i-1) == -TA_CANDLECOLOR(i) && // 3rd opposite color +/* Generated */ inOpen[i] < max(inClose[i-1], inOpen[i-1]) && // 3rd opens within 2nd rb +/* Generated */ inOpen[i] > min(inClose[i-1], inOpen[i-1]) && +/* Generated */ inClose[i] < max(inClose[i-2], inOpen[i-2]) && // 3rd closes within 1st rb +/* Generated */ inClose[i] > min(inClose[i-2], inOpen[i-2]) && +/* Generated */ ( ( +/* Generated */ TA_CANDLECOLOR(i-2) == 1 && // when 1st is white +/* Generated */ TA_REALBODYGAPUP(i-1,i-2) // upside gap +/* Generated */ ) || +/* Generated */ ( +/* Generated */ TA_CANDLECOLOR(i-2) == -1 && // when 1st is black +/* Generated */ TA_REALBODYGAPDOWN(i-1,i-2) // downside gap +/* Generated */ ) +/* Generated */ ) +/* Generated */ ) +/* Generated */ outInteger[outIdx++] = TA_CANDLECOLOR(i-2) * 100; +/* Generated */ else +/* Generated */ outInteger[outIdx++] = 0; +/* Generated */ i++; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CEIL.c b/talib/ta_func/ta_CEIL.c new file mode 100644 index 0000000..9449492 --- /dev/null +++ b/talib/ta_func/ta_CEIL.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CeilLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int ceilLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CEIL_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CEIL - Vector Ceil + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ceil( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ceil( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ceil( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CEIL( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_ceil(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ceil( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ceil( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ceil( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CEIL( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_ceil(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CMO.c b/talib/ta_func/ta_CMO.c new file mode 100644 index 0000000..af2e110 --- /dev/null +++ b/talib/ta_func/ta_CMO.c @@ -0,0 +1,611 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * BT Barry Tsung + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112605 MF Initial version. + * 021806 MF,BT Fix #1434450 reported by BT. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CmoLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cmoLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CMO_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + retValue = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_CMO,Cmo); + if( TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_METASTOCK,Metastock) ) + retValue--; + + return retValue; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CMO - Chande Momentum Oscillator + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cmo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cmo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cmo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CMO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + int today, lookbackTotal, unstablePeriod, i; + double prevGain, prevLoss, prevValue, savePrevValue; + double tempValue1, tempValue2, tempValue3, tempValue4; + + #if defined( USE_SINGLE_PRECISION_INPUT ) + ARRAY_MEMMOVEMIX_VAR; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* CMO calculation is mostly identical to RSI. + * + * The only difference is in the last step of calculation: + * + * RSI = gain / (gain+loss) + * CMO = (gain-loss) / (gain+loss) + * + * See the RSI function for potentially some more info + * on this algo. + */ + + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(CMO)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + outIdx = 0; /* Index into the output. */ + + /* Trap special case where the period is '1'. + * In that case, just copy the input into the + * output for the requested range (as-is !) + */ + if( optInTimePeriod == 1 ) + { + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + i = (endIdx-startIdx)+1; + VALUE_HANDLE_DEREF(outNBElement) = i; + #if defined( USE_SINGLE_PRECISION_INPUT ) + ARRAY_MEMMOVEMIX( outReal, 0, inReal, startIdx, i ); + #else + ARRAY_MEMMOVE( outReal, 0, inReal, startIdx, i ); + #endif + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Accumulate Wilder's "Average Gain" and "Average Loss" + * among the initial period. + */ + today = startIdx-lookbackTotal; + prevValue = inReal[today]; + + unstablePeriod = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_CMO,Cmo); + + /* If there is no unstable period, + * calculate the 'additional' initial + * price bar who is particuliar to + * metastock. + * If there is an unstable period, + * no need to calculate since this + * first value will be surely skip. + */ + if( (unstablePeriod == 0) && + (TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_METASTOCK,Metastock))) + { + /* Preserve prevValue because it may get + * overwritten by the output. + *(because output ptr could be the same as input ptr). + */ + savePrevValue = prevValue; + + /* No unstable period, so must calculate first output + * particular to Metastock. + * (Metastock re-use the first price bar, so there + * is no loss/gain at first. Beats me why they + * are doing all this). + */ + prevGain = 0.0; + prevLoss = 0.0; + for( i=optInTimePeriod; i > 0; i-- ) + { + tempValue1 = inReal[today++]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + } + + + tempValue1 = prevLoss/optInTimePeriod; + tempValue2 = prevGain/optInTimePeriod; + tempValue3 = tempValue2-tempValue1; + tempValue4 = tempValue1+tempValue2; + + /* Write the output. */ + if( !TA_IS_ZERO(tempValue4) ) + outReal[outIdx++] = 100*(tempValue3/tempValue4); + else + outReal[outIdx++] = 0.0; + + /* Are we done? */ + if( today > endIdx ) + { + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Start over for the next price bar. */ + today -= optInTimePeriod; + prevValue = savePrevValue; + } + + + /* Remaining of the processing is identical + * for both Classic calculation and Metastock. + */ + prevGain = 0.0; + prevLoss = 0.0; + today++; + for( i=optInTimePeriod; i > 0; i-- ) + { + tempValue1 = inReal[today++]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + } + + + /* Subsequent prevLoss and prevGain are smoothed + * using the previous values (Wilder's approach). + * 1) Multiply the previous by 'period-1'. + * 2) Add today value. + * 3) Divide by 'period'. + */ + prevLoss /= optInTimePeriod; + prevGain /= optInTimePeriod; + + /* Often documentation present the RSI calculation as follow: + * RSI = 100 - (100 / 1 + (prevGain/prevLoss)) + * + * The following is equivalent: + * RSI = 100 * (prevGain/(prevGain+prevLoss)) + * + * The second equation is used here for speed optimization. + */ + if( today > startIdx ) + { + tempValue1 = prevGain+prevLoss; + if( !TA_IS_ZERO(tempValue1) ) + outReal[outIdx++] = 100.0*((prevGain-prevLoss)/tempValue1); + else + outReal[outIdx++] = 0.0; + } + else + { + /* Skip the unstable period. Do the processing + * but do not write it in the output. + */ + while( today < startIdx ) + { + tempValue1 = inReal[today]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + + prevLoss *= (optInTimePeriod-1); + prevGain *= (optInTimePeriod-1); + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + + prevLoss /= optInTimePeriod; + prevGain /= optInTimePeriod; + + today++; + } + } + + /* Unstable period skipped... now continue + * processing if needed. + */ + while( today <= endIdx ) + { + tempValue1 = inReal[today++]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + + prevLoss *= (optInTimePeriod-1); + prevGain *= (optInTimePeriod-1); + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + + prevLoss /= optInTimePeriod; + prevGain /= optInTimePeriod; + tempValue1 = prevGain+prevLoss; + if( !TA_IS_ZERO(tempValue1) ) + outReal[outIdx++] = 100.0*((prevGain-prevLoss)/tempValue1); + else + outReal[outIdx++] = 0.0; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cmo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cmo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cmo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CMO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal, unstablePeriod, i; +/* Generated */ double prevGain, prevLoss, prevValue, savePrevValue; +/* Generated */ double tempValue1, tempValue2, tempValue3, tempValue4; +/* Generated */ #if defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ ARRAY_MEMMOVEMIX_VAR; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackTotal = LOOKBACK_CALL(CMO)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ outIdx = 0; +/* Generated */ if( optInTimePeriod == 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ i = (endIdx-startIdx)+1; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = i; +/* Generated */ #if defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ ARRAY_MEMMOVEMIX( outReal, 0, inReal, startIdx, i ); +/* Generated */ #else +/* Generated */ ARRAY_MEMMOVE( outReal, 0, inReal, startIdx, i ); +/* Generated */ #endif +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ today = startIdx-lookbackTotal; +/* Generated */ prevValue = inReal[today]; +/* Generated */ unstablePeriod = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_CMO,Cmo); +/* Generated */ if( (unstablePeriod == 0) && +/* Generated */ (TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_METASTOCK,Metastock))) +/* Generated */ { +/* Generated */ savePrevValue = prevValue; +/* Generated */ prevGain = 0.0; +/* Generated */ prevLoss = 0.0; +/* Generated */ for( i=optInTimePeriod; i > 0; i-- ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today++]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ } +/* Generated */ tempValue1 = prevLoss/optInTimePeriod; +/* Generated */ tempValue2 = prevGain/optInTimePeriod; +/* Generated */ tempValue3 = tempValue2-tempValue1; +/* Generated */ tempValue4 = tempValue1+tempValue2; +/* Generated */ if( !TA_IS_ZERO(tempValue4) ) +/* Generated */ outReal[outIdx++] = 100*(tempValue3/tempValue4); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ if( today > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ today -= optInTimePeriod; +/* Generated */ prevValue = savePrevValue; +/* Generated */ } +/* Generated */ prevGain = 0.0; +/* Generated */ prevLoss = 0.0; +/* Generated */ today++; +/* Generated */ for( i=optInTimePeriod; i > 0; i-- ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today++]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ } +/* Generated */ prevLoss /= optInTimePeriod; +/* Generated */ prevGain /= optInTimePeriod; +/* Generated */ if( today > startIdx ) +/* Generated */ { +/* Generated */ tempValue1 = prevGain+prevLoss; +/* Generated */ if( !TA_IS_ZERO(tempValue1) ) +/* Generated */ outReal[outIdx++] = 100.0*((prevGain-prevLoss)/tempValue1); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ while( today < startIdx ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ prevLoss *= (optInTimePeriod-1); +/* Generated */ prevGain *= (optInTimePeriod-1); +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ prevLoss /= optInTimePeriod; +/* Generated */ prevGain /= optInTimePeriod; +/* Generated */ today++; +/* Generated */ } +/* Generated */ } +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today++]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ prevLoss *= (optInTimePeriod-1); +/* Generated */ prevGain *= (optInTimePeriod-1); +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ prevLoss /= optInTimePeriod; +/* Generated */ prevGain /= optInTimePeriod; +/* Generated */ tempValue1 = prevGain+prevLoss; +/* Generated */ if( !TA_IS_ZERO(tempValue1) ) +/* Generated */ outReal[outIdx++] = 100.0*((prevGain-prevLoss)/tempValue1); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_CORREL.c b/talib/ta_func/ta_CORREL.c new file mode 100644 index 0000000..0f06810 --- /dev/null +++ b/talib/ta_func/ta_CORREL.c @@ -0,0 +1,414 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 101003 MF Initial Coding + * 062804 MF Resolve div by zero bug on limit case. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CorrelLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int correlLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_CORREL_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_CORREL - Pearson's Correlation Coefficient (r) + * + * Input = double, double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Correl( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Correl( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode correl( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal0[], +/* Generated */ double inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_CORREL( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal0[], +/* Generated */ const double inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double sumXY, sumX, sumY, sumX2, sumY2, x, y, trailingX, trailingY; + double tempReal; + int lookbackTotal, today, trailingIdx, outIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Move up the start index if there is not + * enough initial data. + */ + lookbackTotal = optInTimePeriod-1; + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + trailingIdx = startIdx - lookbackTotal; + + /* Calculate the initial values. */ + sumXY = sumX = sumY = sumX2 = sumY2 = 0.0; + for( today=trailingIdx; today <= startIdx; today++ ) + { + x = inReal0[today]; + sumX += x; + sumX2 += x*x; + + y = inReal1[today]; + sumXY += x*y; + sumY += y; + sumY2 += y*y; + } + + /* Write the first output. + * Save first the trailing values since the input + * and output might be the same array, + */ + trailingX = inReal0[trailingIdx]; + trailingY = inReal1[trailingIdx++]; + tempReal = (sumX2-((sumX*sumX)/optInTimePeriod)) * (sumY2-((sumY*sumY)/optInTimePeriod)); + if( !TA_IS_ZERO_OR_NEG(tempReal) ) + outReal[0] = (sumXY-((sumX*sumY)/optInTimePeriod)) / std_sqrt(tempReal); + else + outReal[0] = 0.0; + + /* Tight loop to do subsequent values. */ + outIdx = 1; + while( today <= endIdx ) + { + /* Remove trailing values */ + sumX -= trailingX; + sumX2 -= trailingX*trailingX; + + sumXY -= trailingX*trailingY; + sumY -= trailingY; + sumY2 -= trailingY*trailingY; + + /* Add new values */ + x = inReal0[today]; + sumX += x; + sumX2 += x*x; + + y = inReal1[today++]; + sumXY += x*y; + sumY += y; + sumY2 += y*y; + + /* Output new coefficient. + * Save first the trailing values since the input + * and output might be the same array, + */ + trailingX = inReal0[trailingIdx]; + trailingY = inReal1[trailingIdx++]; + tempReal = (sumX2-((sumX*sumX)/optInTimePeriod)) * (sumY2-((sumY*sumY)/optInTimePeriod)); + if( !TA_IS_ZERO_OR_NEG(tempReal) ) + outReal[outIdx++] = (sumXY-((sumX*sumY)/optInTimePeriod)) / std_sqrt(tempReal); + else + outReal[outIdx++] = 0.0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Correl( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Correl( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode correl( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal0[], +/* Generated */ float inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_CORREL( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal0[], +/* Generated */ const float inReal1[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double sumXY, sumX, sumY, sumX2, sumY2, x, y, trailingX, trailingY; +/* Generated */ double tempReal; +/* Generated */ int lookbackTotal, today, trailingIdx, outIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = optInTimePeriod-1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingIdx = startIdx - lookbackTotal; +/* Generated */ sumXY = sumX = sumY = sumX2 = sumY2 = 0.0; +/* Generated */ for( today=trailingIdx; today <= startIdx; today++ ) +/* Generated */ { +/* Generated */ x = inReal0[today]; +/* Generated */ sumX += x; +/* Generated */ sumX2 += x*x; +/* Generated */ y = inReal1[today]; +/* Generated */ sumXY += x*y; +/* Generated */ sumY += y; +/* Generated */ sumY2 += y*y; +/* Generated */ } +/* Generated */ trailingX = inReal0[trailingIdx]; +/* Generated */ trailingY = inReal1[trailingIdx++]; +/* Generated */ tempReal = (sumX2-((sumX*sumX)/optInTimePeriod)) * (sumY2-((sumY*sumY)/optInTimePeriod)); +/* Generated */ if( !TA_IS_ZERO_OR_NEG(tempReal) ) +/* Generated */ outReal[0] = (sumXY-((sumX*sumY)/optInTimePeriod)) / std_sqrt(tempReal); +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ outIdx = 1; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ sumX -= trailingX; +/* Generated */ sumX2 -= trailingX*trailingX; +/* Generated */ sumXY -= trailingX*trailingY; +/* Generated */ sumY -= trailingY; +/* Generated */ sumY2 -= trailingY*trailingY; +/* Generated */ x = inReal0[today]; +/* Generated */ sumX += x; +/* Generated */ sumX2 += x*x; +/* Generated */ y = inReal1[today++]; +/* Generated */ sumXY += x*y; +/* Generated */ sumY += y; +/* Generated */ sumY2 += y*y; +/* Generated */ trailingX = inReal0[trailingIdx]; +/* Generated */ trailingY = inReal1[trailingIdx++]; +/* Generated */ tempReal = (sumX2-((sumX*sumX)/optInTimePeriod)) * (sumY2-((sumY*sumY)/optInTimePeriod)); +/* Generated */ if( !TA_IS_ZERO_OR_NEG(tempReal) ) +/* Generated */ outReal[outIdx++] = (sumXY-((sumX*sumY)/optInTimePeriod)) / std_sqrt(tempReal); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_COS.c b/talib/ta_func/ta_COS.c new file mode 100644 index 0000000..f5dcd98 --- /dev/null +++ b/talib/ta_func/ta_COS.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CosLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int cosLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_COS_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_COS - Vector Trigonometric Cos + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_COS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_cos(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cos( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_COS( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_cos(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_COSH.c b/talib/ta_func/ta_COSH.c new file mode 100644 index 0000000..1630d16 --- /dev/null +++ b/talib/ta_func/ta_COSH.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::CoshLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int coshLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_COSH_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_COSH - Vector Trigonometric Cosh + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cosh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cosh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cosh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_COSH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_cosh(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Cosh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Cosh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode cosh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_COSH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_cosh(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_DEMA.c b/talib/ta_func/ta_DEMA.c new file mode 100644 index 0000000..46a3279 --- /dev/null +++ b/talib/ta_func/ta_DEMA.c @@ -0,0 +1,496 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010102 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::DemaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int demaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_DEMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Get lookback for one EMA. + * Multiply by two (because double smoothing). + */ + return LOOKBACK_CALL(EMA)( optInTimePeriod ) * 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_DEMA - Double Exponential Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Dema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Dema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode dema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_DEMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_REF(firstEMA); + ARRAY_REF(secondEMA); + double k; + VALUE_HANDLE_INT(firstEMABegIdx); + VALUE_HANDLE_INT(firstEMANbElement); + VALUE_HANDLE_INT(secondEMABegIdx); + VALUE_HANDLE_INT(secondEMANbElement); + int tempInt, outIdx, firstEMAIdx, lookbackTotal, lookbackEMA; + ENUM_DECLARATION(RetCode) retCode; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* For an explanation of this function, please read + * + * Stocks & Commodities V. 12:1 (11-19): + * Smoothing Data With Faster Moving Averages + * Stocks & Commodities V. 12:2 (72-80): + * Smoothing Data With Less Lag + * + * Both magazine articles written by Patrick G. Mulloy + * + * Essentially, a DEMA of time serie 't' is: + * EMA2 = EMA(EMA(t,period),period) + * DEMA = 2*EMA(t,period)- EMA2 + * + * DEMA offers a moving average with less lags then the + * traditional EMA. + * + * Do not confuse a DEMA with the EMA2. Both are called + * "Double EMA" in the litterature, but EMA2 is a simple + * EMA of an EMA, while DEMA is a compostie of a single + * EMA with EMA2. + * + * TEMA is very similar (and from the same author). + */ + + /* Will change only on success. */ + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + + /* Adjust startIdx to account for the lookback period. */ + lookbackEMA = LOOKBACK_CALL(EMA)( optInTimePeriod ); + lookbackTotal = lookbackEMA * 2; + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + /* Allocate a temporary buffer for the firstEMA. + * + * When possible, re-use the outputBuffer for temp + * calculation. + */ + #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) + tempInt = lookbackTotal+(endIdx-startIdx)+1; + ARRAY_ALLOC(firstEMA, tempInt ); + #if !defined( _JAVA ) + if( !firstEMA ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + #else + if( inReal == outReal ) + firstEMA = outReal; + else + { + tempInt = lookbackTotal+(endIdx-startIdx)+1; + ARRAY_ALLOC(firstEMA, tempInt ); + #if !defined( _JAVA ) + if( !firstEMA ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + } + #endif + + /* Calculate the first EMA */ + k = PER_TO_K(optInTimePeriod); + retCode = FUNCTION_CALL(INT_EMA)( startIdx-lookbackEMA, endIdx, inReal, + optInTimePeriod, k, + VALUE_HANDLE_OUT(firstEMABegIdx), VALUE_HANDLE_OUT(firstEMANbElement), + firstEMA ); + + /* Verify for failure or if not enough data after + * calculating the first EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) || (VALUE_HANDLE_GET(firstEMANbElement) == 0) ) + { + ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); + return retCode; + } + + /* Allocate a temporary buffer for storing the EMA of the EMA. */ + ARRAY_ALLOC(secondEMA, VALUE_HANDLE_GET(firstEMANbElement)); + + #if !defined( _JAVA ) + if( !secondEMA ) + { + ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(firstEMANbElement)-1, firstEMA, + optInTimePeriod, k, + VALUE_HANDLE_OUT(secondEMABegIdx), VALUE_HANDLE_OUT(secondEMANbElement), + secondEMA ); + + /* Return empty output on failure or if not enough data after + * calculating the second EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) || (VALUE_HANDLE_GET(secondEMANbElement) == 0) ) + { + #if defined(USE_SINGLE_PRECISION_INPUT) + ARRAY_FREE( firstEMA ); + #else + ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); + #endif + ARRAY_FREE( secondEMA ); + return retCode; + } + + /* Iterate through the second EMA and write the DEMA into + * the output. + */ + firstEMAIdx = VALUE_HANDLE_GET(secondEMABegIdx); + outIdx = 0; + while( outIdx < VALUE_HANDLE_GET(secondEMANbElement) ) + { + outReal[outIdx] = (2.0*firstEMA[firstEMAIdx++]) - secondEMA[outIdx]; + outIdx++; + } + + #if defined(USE_SINGLE_PRECISION_INPUT) + ARRAY_FREE( firstEMA ); + #else + ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); + #endif + ARRAY_FREE( secondEMA ); + + /* Succeed. Indicate where the output starts relative to + * the caller input. + */ + VALUE_HANDLE_DEREF(outBegIdx) = VALUE_HANDLE_GET(firstEMABegIdx) + VALUE_HANDLE_GET(secondEMABegIdx); + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Dema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Dema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode dema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_DEMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(firstEMA); +/* Generated */ ARRAY_REF(secondEMA); +/* Generated */ double k; +/* Generated */ VALUE_HANDLE_INT(firstEMABegIdx); +/* Generated */ VALUE_HANDLE_INT(firstEMANbElement); +/* Generated */ VALUE_HANDLE_INT(secondEMABegIdx); +/* Generated */ VALUE_HANDLE_INT(secondEMANbElement); +/* Generated */ int tempInt, outIdx, firstEMAIdx, lookbackTotal, lookbackEMA; +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ lookbackEMA = LOOKBACK_CALL(EMA)( optInTimePeriod ); +/* Generated */ lookbackTotal = lookbackEMA * 2; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) +/* Generated */ tempInt = lookbackTotal+(endIdx-startIdx)+1; +/* Generated */ ARRAY_ALLOC(firstEMA, tempInt ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !firstEMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ #else +/* Generated */ if( inReal == outReal ) +/* Generated */ firstEMA = outReal; +/* Generated */ else +/* Generated */ { +/* Generated */ tempInt = lookbackTotal+(endIdx-startIdx)+1; +/* Generated */ ARRAY_ALLOC(firstEMA, tempInt ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !firstEMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ } +/* Generated */ #endif +/* Generated */ k = PER_TO_K(optInTimePeriod); +/* Generated */ retCode = FUNCTION_CALL(INT_EMA)( startIdx-lookbackEMA, endIdx, inReal, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(firstEMABegIdx), VALUE_HANDLE_OUT(firstEMANbElement), +/* Generated */ firstEMA ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) || (VALUE_HANDLE_GET(firstEMANbElement) == 0) ) +/* Generated */ { +/* Generated */ ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ ARRAY_ALLOC(secondEMA, VALUE_HANDLE_GET(firstEMANbElement)); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !secondEMA ) +/* Generated */ { +/* Generated */ ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(firstEMANbElement)-1, firstEMA, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(secondEMABegIdx), VALUE_HANDLE_OUT(secondEMANbElement), +/* Generated */ secondEMA ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) || (VALUE_HANDLE_GET(secondEMANbElement) == 0) ) +/* Generated */ { +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ #else +/* Generated */ ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); +/* Generated */ #endif +/* Generated */ ARRAY_FREE( secondEMA ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ firstEMAIdx = VALUE_HANDLE_GET(secondEMABegIdx); +/* Generated */ outIdx = 0; +/* Generated */ while( outIdx < VALUE_HANDLE_GET(secondEMANbElement) ) +/* Generated */ { +/* Generated */ outReal[outIdx] = (2.0*firstEMA[firstEMAIdx++]) - secondEMA[outIdx]; +/* Generated */ outIdx++; +/* Generated */ } +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ #else +/* Generated */ ARRAY_FREE_COND( firstEMA != outReal, firstEMA ); +/* Generated */ #endif +/* Generated */ ARRAY_FREE( secondEMA ); +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = VALUE_HANDLE_GET(firstEMABegIdx) + VALUE_HANDLE_GET(secondEMABegIdx); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_DIV.c b/talib/ta_func/ta_DIV.c new file mode 100644 index 0000000..fd1528c --- /dev/null +++ b/talib/ta_func/ta_DIV.c @@ -0,0 +1,270 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::DivLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int divLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_DIV_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_DIV - Vector Arithmetic Div + * + * Input = double, double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Div( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Div( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode div( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal0[], +/* Generated */ double inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_DIV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal0[], +/* Generated */ const double inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = inReal0[i]/inReal1[i]; + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Div( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Div( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode div( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal0[], +/* Generated */ float inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_DIV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal0[], +/* Generated */ const float inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = inReal0[i]/inReal1[i]; +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_DX.c b/talib/ta_func/ta_DX.c new file mode 100644 index 0000000..aa65fe6 --- /dev/null +++ b/talib/ta_func/ta_DX.c @@ -0,0 +1,703 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * MIF Mirek Fontan (mira@fontan.cz) + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 082303 MF Fix #792298. Remove rounding. Bug reported by AM. + * 062704 MF Fix #965557. Div by zero bug reported by MIF. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::DxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int dxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_DX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + if( optInTimePeriod > 1 ) + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_DX,Dx); + else + return 2; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_DX - Directional Movement Index + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Dx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Dx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode dx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_DX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int today, lookbackTotal, outIdx; + double prevHigh, prevLow, prevClose; + double prevMinusDM, prevPlusDM, prevTR; + double tempReal, tempReal2, diffP, diffM; + double minusDI, plusDI; + + int i; + + #define TRUE_RANGE(TH,TL,YC,OUT) {\ + OUT = TH-TL; \ + tempReal2 = std_fabs(TH-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + tempReal2 = std_fabs(TL-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + } + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* + * The DM1 (one period) is base on the largest part of + * today's range that is outside of yesterdays range. + * + * The following 7 cases explain how the +DM and -DM are + * calculated on one period: + * + * Case 1: Case 2: + * C| A| + * | | C| + * | +DM1 = (C-A) B| | +DM1 = 0 + * | -DM1 = 0 | -DM1 = (B-D) + * A| | D| + * | D| + * B| + * + * Case 3: Case 4: + * C| C| + * | A| | + * | +DM1 = (C-A) | | +DM1 = 0 + * | -DM1 = 0 B| | -DM1 = (B-D) + * A| | | + * | | D| + * B| | + * D| + * + * Case 5: Case 6: + * A| A| C| + * | C| +DM1 = 0 | | +DM1 = 0 + * | | -DM1 = 0 | | -DM1 = 0 + * | D| | | + * B| B| D| + * + * + * Case 7: + * + * C| + * A| | + * | | +DM=0 + * B| | -DM=0 + * D| + * + * In case 3 and 4, the rule is that the smallest delta between + * (C-A) and (B-D) determine which of +DM or -DM is zero. + * + * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are + * zero. + * + * The rules remain the same when A=B and C=D (when the highs + * equal the lows). + * + * When calculating the DM over a period > 1, the one-period DM + * for the desired period are initialy sum. In other word, + * for a -DM14, sum the -DM1 for the first 14 days (that's + * 13 values because there is no DM for the first day!) + * Subsequent DM are calculated using the Wilder's + * smoothing approach: + * + * Previous -DM14 + * Today's -DM14 = Previous -DM14 - -------------- + Today's -DM1 + * 14 + * + * Calculation of a -DI14 is as follow: + * + * -DM14 + * -DI14 = -------- + * TR14 + * + * Calculation of the TR14 is: + * + * Previous TR14 + * Today's TR14 = Previous TR14 - -------------- + Today's TR1 + * 14 + * + * The first TR14 is the summation of the first 14 TR1. See the + * TA_TRANGE function on how to calculate the true range. + * + * Calculation of the DX14 is: + * + * diffDI = ABS( (-DI14) - (+DI14) ) + * sumDI = (-DI14) + (+DI14) + * + * DX14 = 100 * (diffDI / sumDI) + * + * Reference: + * New Concepts In Technical Trading Systems, J. Welles Wilder Jr + */ + + /* Original implementation from Wilder's book was doing some integer + * rounding in its calculations. + * + * This was understandable in the context that at the time the book + * was written, most user were doing the calculation by hand. + * + * For a computer, rounding is unnecessary (and even problematic when inputs + * are close to 1). + * + * TA-Lib does not do the rounding. Still, if you want to reproduce Wilder's examples, + * you can comment out the following #undef/#define and rebuild the library. + */ + #undef round_pos + #define round_pos(x) (x) + + if( optInTimePeriod > 1 ) + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_DX,Dx); + else + lookbackTotal = 2; + + /* Adjust startIdx to account for the lookback period. */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Indicate where the next output should be put + * in the outReal. + */ + outIdx = 0; + + /* Process the initial DM and TR */ + VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; + + prevMinusDM = 0.0; + prevPlusDM = 0.0; + prevTR = 0.0; + today = startIdx - lookbackTotal; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + prevClose = inClose[today]; + i = optInTimePeriod-1; + while( i-- > 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR += tempReal; + prevClose = inClose[today]; + } + + /* Skip the unstable period. Note that this loop must be executed + * at least ONCE to calculate the first DI. + */ + i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_DX,Dx) + 1; + while( i-- != 0 ) + { + /* Calculate the prevMinusDM and prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + prevMinusDM -= prevMinusDM/optInTimePeriod; + prevPlusDM -= prevPlusDM/optInTimePeriod; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + } + + /* Write the first DX output */ + if( !TA_IS_ZERO(prevTR) ) + { + minusDI = round_pos(100.0*(prevMinusDM/prevTR)); + plusDI = round_pos(100.0*(prevPlusDM/prevTR)); + tempReal = minusDI+plusDI; + if( !TA_IS_ZERO(tempReal) ) + outReal[0] = round_pos( 100.0 * (std_fabs(minusDI-plusDI)/tempReal) ); + else + outReal[0] = 0.0; + } + else + outReal[0] = 0.0; + outIdx = 1; + + while( today < endIdx ) + { + /* Calculate the prevMinusDM and prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + prevMinusDM -= prevMinusDM/optInTimePeriod; + prevPlusDM -= prevPlusDM/optInTimePeriod; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + else if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + + /* Calculate the DX. The value is rounded (see Wilder book). */ + if( !TA_IS_ZERO(prevTR)) + { + minusDI = round_pos(100.0*(prevMinusDM/prevTR)); + plusDI = round_pos(100.0*(prevPlusDM/prevTR)); + /* This loop is just to accumulate the initial DX */ + tempReal = minusDI+plusDI; + if( !TA_IS_ZERO(tempReal)) + outReal[outIdx] = round_pos( 100.0 * (std_fabs(minusDI-plusDI)/tempReal) ); + else + outReal[outIdx] = outReal[outIdx-1]; + } + else + outReal[outIdx] = outReal[outIdx-1]; + outIdx++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Dx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Dx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode dx( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_DX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, lookbackTotal, outIdx; +/* Generated */ double prevHigh, prevLow, prevClose; +/* Generated */ double prevMinusDM, prevPlusDM, prevTR; +/* Generated */ double tempReal, tempReal2, diffP, diffM; +/* Generated */ double minusDI, plusDI; +/* Generated */ int i; +/* Generated */ #define TRUE_RANGE(TH,TL,YC,OUT) {\ +/* Generated */ OUT = TH-TL; \ +/* Generated */ tempReal2 = std_fabs(TH-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ tempReal2 = std_fabs(TL-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ } +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #undef round_pos +/* Generated */ #define round_pos(x) (x) +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_DX,Dx); +/* Generated */ else +/* Generated */ lookbackTotal = 2; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; +/* Generated */ prevMinusDM = 0.0; +/* Generated */ prevPlusDM = 0.0; +/* Generated */ prevTR = 0.0; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ prevClose = inClose[today]; +/* Generated */ i = optInTimePeriod-1; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR += tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_DX,Dx) + 1; +/* Generated */ while( i-- != 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ prevMinusDM -= prevMinusDM/optInTimePeriod; +/* Generated */ prevPlusDM -= prevPlusDM/optInTimePeriod; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ { +/* Generated */ minusDI = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ plusDI = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ tempReal = minusDI+plusDI; +/* Generated */ if( !TA_IS_ZERO(tempReal) ) +/* Generated */ outReal[0] = round_pos( 100.0 * (std_fabs(minusDI-plusDI)/tempReal) ); +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ outIdx = 1; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ prevMinusDM -= prevMinusDM/optInTimePeriod; +/* Generated */ prevPlusDM -= prevPlusDM/optInTimePeriod; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ else if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(prevTR)) +/* Generated */ { +/* Generated */ minusDI = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ plusDI = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ tempReal = minusDI+plusDI; +/* Generated */ if( !TA_IS_ZERO(tempReal)) +/* Generated */ outReal[outIdx] = round_pos( 100.0 * (std_fabs(minusDI-plusDI)/tempReal) ); +/* Generated */ else +/* Generated */ outReal[outIdx] = outReal[outIdx-1]; +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[outIdx] = outReal[outIdx-1]; +/* Generated */ outIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_EMA.c b/talib/ta_func/ta_EMA.c new file mode 100644 index 0000000..3690b8b --- /dev/null +++ b/talib/ta_func/ta_EMA.c @@ -0,0 +1,510 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::EmaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int emaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_EMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod - 1 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_EMA,Ema); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_EMA - Exponential Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_EMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Simply call the internal implementation of the EMA. */ + return FUNCTION_CALL(INT_EMA)( startIdx, endIdx, inReal, + optInTimePeriod, + PER_TO_K( optInTimePeriod ), + outBegIdx, outNBElement, outReal ); +} + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + // No INT function +#else +/* Internal implementation can be called from any other TA function. + * + * Faster because there is no parameter check, but it is a double + * edge sword. + * + * The optInK_1 and optInTimePeriod are usually tightly coupled: + * + * optInK_1 = 2 / (optInTimePeriod + 1). + * + * These values are going to be related by this equation 99.9% of the + * time... but there is some exception, this is why both must be provided. + * + * The macro PER_TO_K is equivalent to the above formula. + */ +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) + enum class Core::RetCode Core::TA_INT_EMA( int startIdx, + int endIdx, + SubArray^ inReal, + int optInTimePeriod, + double optInK_1, + [Out]int% outBegIdx, + [Out]int% outNBElement, + SubArray^ outReal ) +#elif defined( _MANAGED ) + enum class Core::RetCode Core::TA_INT_EMA( int startIdx, + int endIdx, + cli::array^ inReal, + int optInTimePeriod, + double optInK_1, + [Out]int% outBegIdx, + [Out]int% outNBElement, + cli::array^ outReal ) +#elif defined( _JAVA ) +public RetCode TA_INT_EMA( int startIdx, + int endIdx, + INPUT_TYPE []inReal, + int optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + double optInK_1, /* Ratio for calculation of EMA. */ + MInteger outBegIdx, + MInteger outNBElement, + double []outReal ) + +#else +TA_RetCode TA_PREFIX(INT_EMA)( int startIdx, + int endIdx, + const INPUT_TYPE *inReal, + int optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + double optInK_1, /* Ratio for calculation of EMA. */ + int *outBegIdx, + int *outNBElement, + double *outReal ) +#endif +{ + double tempReal, prevMA; + int i, today, outIdx, lookbackTotal; + + /* Ususally, optInK_1 = 2 / (optInTimePeriod + 1), + * but sometime there is exception. This + * is why both value are parameters. + */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = LOOKBACK_CALL(EMA)( optInTimePeriod ); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Do the EMA calculation using tight loops. */ + + /* The first EMA is calculated differently. It + * then become the seed for subsequent EMA. + * + * The algorithm for this seed vary widely. + * Only 3 are implemented here: + * + * TA_MA_CLASSIC: + * Use a simple MA of the first 'period'. + * This is the approach most widely documented. + * + * TA_MA_METASTOCK: + * Use first price bar value as a seed + * from the begining of all the available + * data. + * + * TA_MA_TRADESTATION: + * Use 4th price bar as a seed, except when + * period is 1 who use 2th price bar or something + * like that... (not an obvious one...). + */ + if( TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_DEFAULT,Default) ) + { + today = startIdx-lookbackTotal; + i = optInTimePeriod; + tempReal = 0.0; + while( i-- > 0 ) + tempReal += inReal[today++]; + + prevMA = tempReal / optInTimePeriod; + } + else + { + prevMA = inReal[0]; + today = 1; + + /* !!! Tradestation not supported yet. + case TA_MA_TRADESTATION: + prevMA = inReal[startIdx-1]; + if( optInTimePeriod == 1 ) + VALUE_HANDLE_DEREF(outBegIdx)_0 = 1; + else + VALUE_HANDLE_DEREF(outBegIdx)_0 = 3; + */ + } + + /* At this point, prevMA is the first EMA (the seed for + * the rest). + * 'today' keep track of where the processing is within the + * input. + */ + + /* Skip the unstable period. Do the processing + * but do not write it in the output. + */ + while( today <= startIdx ) + prevMA = ((inReal[today++]-prevMA)*optInK_1) + prevMA; + + /* Write the first value. */ + outReal[0] = prevMA; + outIdx = 1; + + /* Calculate the remaining range. */ + while( today <= endIdx ) + { + prevMA = ((inReal[today++]-prevMA)*optInK_1) + prevMA; + outReal[outIdx++] = prevMA; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} +#endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_EMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ return FUNCTION_CALL(INT_EMA)( startIdx, endIdx, inReal, +/* Generated */ optInTimePeriod, +/* Generated */ PER_TO_K( optInTimePeriod ), +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ } +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ // No INT function +/* Generated */ #else +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TA_INT_EMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ double optInK_1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TA_INT_EMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ double optInK_1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode TA_INT_EMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ INPUT_TYPE []inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ double optInK_1, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double []outReal ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_PREFIX(INT_EMA)( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const INPUT_TYPE *inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ double optInK_1, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double *outReal ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double tempReal, prevMA; +/* Generated */ int i, today, outIdx, lookbackTotal; +/* Generated */ lookbackTotal = LOOKBACK_CALL(EMA)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ if( TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_DEFAULT,Default) ) +/* Generated */ { +/* Generated */ today = startIdx-lookbackTotal; +/* Generated */ i = optInTimePeriod; +/* Generated */ tempReal = 0.0; +/* Generated */ while( i-- > 0 ) +/* Generated */ tempReal += inReal[today++]; +/* Generated */ prevMA = tempReal / optInTimePeriod; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevMA = inReal[0]; +/* Generated */ today = 1; +/* Generated */ } +/* Generated */ while( today <= startIdx ) +/* Generated */ prevMA = ((inReal[today++]-prevMA)*optInK_1) + prevMA; +/* Generated */ outReal[0] = prevMA; +/* Generated */ outIdx = 1; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ prevMA = ((inReal[today++]-prevMA)*optInK_1) + prevMA; +/* Generated */ outReal[outIdx++] = prevMA; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ #endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_EXP.c b/talib/ta_func/ta_EXP.c new file mode 100644 index 0000000..10bf53d --- /dev/null +++ b/talib/ta_func/ta_EXP.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::ExpLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int expLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_EXP_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_EXP - Vector Arithmetic Exp + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Exp( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Exp( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode exp( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_EXP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_exp(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Exp( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Exp( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode exp( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_EXP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_exp(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_FLOOR.c b/talib/ta_func/ta_FLOOR.c new file mode 100644 index 0000000..a116efc --- /dev/null +++ b/talib/ta_func/ta_FLOOR.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::FloorLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int floorLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_FLOOR_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_FLOOR - Vector Floor + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Floor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Floor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode floor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_FLOOR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_floor(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Floor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Floor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode floor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_FLOOR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_floor(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_HT_DCPERIOD.c b/talib/ta_func/ta_HT_DCPERIOD.c new file mode 100644 index 0000000..2cb7a30 --- /dev/null +++ b/talib/ta_func/ta_HT_DCPERIOD.c @@ -0,0 +1,569 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::HtDcPeriodLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int htDcPeriodLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_HT_DCPERIOD_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* See TA_MAMA_Lookback for an explanation of these */ + return 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_DCPERIOD,HtDcPeriod); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_HT_DCPERIOD - Hilbert Transform - Dominant Cycle Period + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtDcPeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtDcPeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htDcPeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_HT_DCPERIOD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg; + + double todayValue, smoothPeriod; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Constant */ + rad2Deg = 180.0 / (4.0 * std_atan(1)); + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_DCPERIOD,HtDcPeriod); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 9; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + smoothPeriod = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "even" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + smoothPeriod = (0.33*period)+(0.67*smoothPeriod); + + if( today >= startIdx ) + { + outReal[outIdx++] = smoothPeriod; + } + + /* Ooof... let's do the next price bar now! */ + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtDcPeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtDcPeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htDcPeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_HT_DCPERIOD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg; +/* Generated */ double todayValue, smoothPeriod; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ rad2Deg = 180.0 / (4.0 * std_atan(1)); +/* Generated */ lookbackTotal = 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_DCPERIOD,HtDcPeriod); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 9; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ smoothPeriod = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ smoothPeriod = (0.33*period)+(0.67*smoothPeriod); +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = smoothPeriod; +/* Generated */ } +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_HT_DCPHASE.c b/talib/ta_func/ta_HT_DCPHASE.c new file mode 100644 index 0000000..0b1b015 --- /dev/null +++ b/talib/ta_func/ta_HT_DCPHASE.c @@ -0,0 +1,687 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::HtDcPhaseLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int htDcPhaseLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_HT_DCPHASE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* 31 input are skip + * +32 output are skip to account for misc lookback + * --- + * 63 Total Lookback + * + * 31 is for being compatible with Tradestation. + * See TA_MAMA_Lookback for an explanation of the "32". + */ + return 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_DCPHASE,HtDcPhase); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_HT_DCPHASE - Hilbert Transform - Dominant Cycle Phase + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtDcPhase( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtDcPhase( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htDcPhase( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_HT_DCPHASE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg, constDeg2RadBy360; + + double todayValue, smoothPeriod; + + /* Varaible used to keep track of the previous + * smooth price. In the case of this algorithm, + * we will never need more than 50 values. + */ + #define SMOOTH_PRICE_SIZE 50 + CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); + int idx; + + /* Variable used to calculate the dominant cycle phase */ + int DCPeriodInt; + double DCPhase, DCPeriod, imagPart, realPart; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); + + /* Constant */ + tempReal = std_atan(1); + rad2Deg = 45.0/tempReal; + constDeg2RadBy360 = tempReal*8.0; + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_DCPHASE,HtDcPhase); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 34; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + smoothPeriod = 0.0; + + for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) + smoothPrice[i] = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + DCPhase = 0.0; + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + /* Remember the smoothedValue into the smoothPrice + * circular buffer. + */ + smoothPrice[smoothPrice_Idx] = smoothedValue; + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "even" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + smoothPeriod = (0.33*period)+(0.67*smoothPeriod); + + /* Compute Dominant Cycle Phase */ + DCPeriod = smoothPeriod+0.5; + DCPeriodInt = (int)DCPeriod; + realPart = 0.0; + imagPart = 0.0; + + /* idx is used to iterate for up to 50 of the last + * value of smoothPrice. + */ + idx = smoothPrice_Idx; + for( i=0; i < DCPeriodInt; i++ ) + { + tempReal = ((double)i*constDeg2RadBy360)/(double)DCPeriodInt; + tempReal2 = smoothPrice[idx]; + realPart += std_sin(tempReal)*tempReal2; + imagPart += std_cos(tempReal)*tempReal2; + if( idx == 0 ) + idx = SMOOTH_PRICE_SIZE-1; + else + idx--; + } + + tempReal = std_fabs(imagPart); + if( tempReal > 0.0 ) + DCPhase = std_atan(realPart/imagPart)*rad2Deg; + else if( tempReal <= 0.01 ) + { + if( realPart < 0.0 ) + DCPhase -= 90.0; + else if( realPart > 0.0 ) + DCPhase += 90.0; + } + DCPhase += 90.0; + + /* Compensate for one bar lag of the weighted moving average */ + DCPhase += 360.0 / smoothPeriod; + if( imagPart < 0.0 ) + DCPhase += 180.0; + if( DCPhase > 315.0 ) + DCPhase -= 360.0; + + if( today >= startIdx ) + { + outReal[outIdx++] = DCPhase; + } + + /* Ooof... let's do the next price bar now! */ + CIRCBUF_NEXT(smoothPrice); + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtDcPhase( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtDcPhase( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htDcPhase( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_HT_DCPHASE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg, constDeg2RadBy360; +/* Generated */ double todayValue, smoothPeriod; +/* Generated */ #define SMOOTH_PRICE_SIZE 50 +/* Generated */ CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); +/* Generated */ int idx; +/* Generated */ int DCPeriodInt; +/* Generated */ double DCPhase, DCPeriod, imagPart, realPart; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); +/* Generated */ tempReal = std_atan(1); +/* Generated */ rad2Deg = 45.0/tempReal; +/* Generated */ constDeg2RadBy360 = tempReal*8.0; +/* Generated */ lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_DCPHASE,HtDcPhase); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 34; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ smoothPeriod = 0.0; +/* Generated */ for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) +/* Generated */ smoothPrice[i] = 0.0; +/* Generated */ DCPhase = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ smoothPrice[smoothPrice_Idx] = smoothedValue; +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ smoothPeriod = (0.33*period)+(0.67*smoothPeriod); +/* Generated */ DCPeriod = smoothPeriod+0.5; +/* Generated */ DCPeriodInt = (int)DCPeriod; +/* Generated */ realPart = 0.0; +/* Generated */ imagPart = 0.0; +/* Generated */ idx = smoothPrice_Idx; +/* Generated */ for( i=0; i < DCPeriodInt; i++ ) +/* Generated */ { +/* Generated */ tempReal = ((double)i*constDeg2RadBy360)/(double)DCPeriodInt; +/* Generated */ tempReal2 = smoothPrice[idx]; +/* Generated */ realPart += std_sin(tempReal)*tempReal2; +/* Generated */ imagPart += std_cos(tempReal)*tempReal2; +/* Generated */ if( idx == 0 ) +/* Generated */ idx = SMOOTH_PRICE_SIZE-1; +/* Generated */ else +/* Generated */ idx--; +/* Generated */ } +/* Generated */ tempReal = std_fabs(imagPart); +/* Generated */ if( tempReal > 0.0 ) +/* Generated */ DCPhase = std_atan(realPart/imagPart)*rad2Deg; +/* Generated */ else if( tempReal <= 0.01 ) +/* Generated */ { +/* Generated */ if( realPart < 0.0 ) +/* Generated */ DCPhase -= 90.0; +/* Generated */ else if( realPart > 0.0 ) +/* Generated */ DCPhase += 90.0; +/* Generated */ } +/* Generated */ DCPhase += 90.0; +/* Generated */ DCPhase += 360.0 / smoothPeriod; +/* Generated */ if( imagPart < 0.0 ) +/* Generated */ DCPhase += 180.0; +/* Generated */ if( DCPhase > 315.0 ) +/* Generated */ DCPhase -= 360.0; +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = DCPhase; +/* Generated */ } +/* Generated */ CIRCBUF_NEXT(smoothPrice); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_HT_PHASOR.c b/talib/ta_func/ta_HT_PHASOR.c new file mode 100644 index 0000000..e093426 --- /dev/null +++ b/talib/ta_func/ta_HT_PHASOR.c @@ -0,0 +1,590 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::HtPhasorLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int htPhasorLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_HT_PHASOR_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* See TA_MAMA_Lookback for an explanation of these */ + return 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_PHASOR,HtPhasor); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_HT_PHASOR - Hilbert Transform - Phasor Components + * + * Input = double + * Output = double, double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtPhasor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInPhase, +/* Generated */ SubArray^ outQuadrature ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtPhasor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInPhase, +/* Generated */ cli::array^ outQuadrature ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htPhasor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outInPhase[], +/* Generated */ double outQuadrature[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_HT_PHASOR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outInPhase[], +/* Generated */ double outQuadrature[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg; + + double todayValue; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInPhase ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outQuadrature ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Constant */ + rad2Deg = 180.0 / (4.0 * std_atan(1)); + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_PHASOR,HtPhasor); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 9; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + if( today >= startIdx ) + { + outQuadrature[outIdx] = Q1; + outInPhase[outIdx++] = I1ForEvenPrev3; + } + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + if( today >= startIdx ) + { + outQuadrature[outIdx] = Q1; + outInPhase[outIdx++] = I1ForOddPrev3; + } + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "even" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + /* Ooof... let's do the next price bar now! */ + today++; + } + + /* Default return values */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtPhasor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInPhase, +/* Generated */ SubArray^ outQuadrature ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtPhasor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInPhase, +/* Generated */ cli::array^ outQuadrature ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htPhasor( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outInPhase[], +/* Generated */ double outQuadrature[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_HT_PHASOR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outInPhase[], +/* Generated */ double outQuadrature[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg; +/* Generated */ double todayValue; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInPhase ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outQuadrature ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ rad2Deg = 180.0 / (4.0 * std_atan(1)); +/* Generated */ lookbackTotal = 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_PHASOR,HtPhasor); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 9; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outQuadrature[outIdx] = Q1; +/* Generated */ outInPhase[outIdx++] = I1ForEvenPrev3; +/* Generated */ } +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outQuadrature[outIdx] = Q1; +/* Generated */ outInPhase[outIdx++] = I1ForOddPrev3; +/* Generated */ } +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_HT_SINE.c b/talib/ta_func/ta_HT_SINE.c new file mode 100644 index 0000000..fbbe74f --- /dev/null +++ b/talib/ta_func/ta_HT_SINE.c @@ -0,0 +1,704 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::HtSineLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int htSineLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_HT_SINE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* 31 input are skip + * +32 output are skip to account for misc lookback + * --- + * 63 Total Lookback + * + * 31 is for being compatible with Tradestation. + * See TA_MAMA_Lookback for an explanation of the "32". + */ + return 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_SINE,HtSine); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_HT_SINE - Hilbert Transform - SineWave + * + * Input = double + * Output = double, double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtSine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outSine, +/* Generated */ SubArray^ outLeadSine ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtSine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outSine, +/* Generated */ cli::array^ outLeadSine ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htSine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outSine[], +/* Generated */ double outLeadSine[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_HT_SINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outSine[], +/* Generated */ double outLeadSine[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg, deg2Rad, constDeg2RadBy360; + + double todayValue, smoothPeriod; + + /* Varaible used to keep track of the previous + * smooth price. In the case of this algorithm, + * we will never need more than 50 values. + */ + #define SMOOTH_PRICE_SIZE 50 + CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); + int idx; + + /* Variable used to calculate the dominant cycle phase */ + int DCPeriodInt; + double DCPhase, DCPeriod, imagPart, realPart; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outSine ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outLeadSine ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); + + /* The following could be replaced by constant eventually. */ + tempReal = std_atan(1); + rad2Deg = 45.0/tempReal; + deg2Rad = 1.0/rad2Deg; + constDeg2RadBy360 = tempReal*8.0; + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_SINE,HtSine); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 34; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + smoothPeriod = 0.0; + + for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) + smoothPrice[i] = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + DCPhase = 0.0; + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + /* Remember the smoothedValue into the smoothPrice + * circular buffer. + */ + smoothPrice[smoothPrice_Idx] = smoothedValue; + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "even" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + smoothPeriod = (0.33*period)+(0.67*smoothPeriod); + + /* Compute Dominant Cycle Phase */ + DCPeriod = smoothPeriod+0.5; + DCPeriodInt = (int)DCPeriod; + realPart = 0.0; + imagPart = 0.0; + + /* idx is used to iterate for up to 50 of the last + * value of smoothPrice. + */ + idx = smoothPrice_Idx; + for( i=0; i < DCPeriodInt; i++ ) + { + tempReal = ((double)i*constDeg2RadBy360)/(double)DCPeriodInt; + tempReal2 = smoothPrice[idx]; + realPart += std_sin(tempReal)*tempReal2; + imagPart += std_cos(tempReal)*tempReal2; + if( idx == 0 ) + idx = SMOOTH_PRICE_SIZE-1; + else + idx--; + } + + tempReal = std_fabs(imagPart); + if( tempReal > 0.0 ) + DCPhase = std_atan(realPart/imagPart)*rad2Deg; + else if( tempReal <= 0.01 ) + { + if( realPart < 0.0 ) + DCPhase -= 90.0; + else if( realPart > 0.0 ) + DCPhase += 90.0; + } + DCPhase += 90.0; + + /* Compensate for one bar lag of the weighted moving average */ + DCPhase += 360.0 / smoothPeriod; + if( imagPart < 0.0 ) + DCPhase += 180.0; + if( DCPhase > 315.0 ) + DCPhase -= 360.0; + + if( today >= startIdx ) + { + outSine[outIdx] = std_sin(DCPhase*deg2Rad); + outLeadSine[outIdx++] = std_sin((DCPhase+45)*deg2Rad); + } + + /* Ooof... let's do the next price bar now! */ + CIRCBUF_NEXT(smoothPrice); + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtSine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outSine, +/* Generated */ SubArray^ outLeadSine ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtSine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outSine, +/* Generated */ cli::array^ outLeadSine ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htSine( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outSine[], +/* Generated */ double outLeadSine[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_HT_SINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outSine[], +/* Generated */ double outLeadSine[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg, deg2Rad, constDeg2RadBy360; +/* Generated */ double todayValue, smoothPeriod; +/* Generated */ #define SMOOTH_PRICE_SIZE 50 +/* Generated */ CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); +/* Generated */ int idx; +/* Generated */ int DCPeriodInt; +/* Generated */ double DCPhase, DCPeriod, imagPart, realPart; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outSine ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outLeadSine ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); +/* Generated */ tempReal = std_atan(1); +/* Generated */ rad2Deg = 45.0/tempReal; +/* Generated */ deg2Rad = 1.0/rad2Deg; +/* Generated */ constDeg2RadBy360 = tempReal*8.0; +/* Generated */ lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_SINE,HtSine); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 34; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ smoothPeriod = 0.0; +/* Generated */ for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) +/* Generated */ smoothPrice[i] = 0.0; +/* Generated */ DCPhase = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ smoothPrice[smoothPrice_Idx] = smoothedValue; +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ smoothPeriod = (0.33*period)+(0.67*smoothPeriod); +/* Generated */ DCPeriod = smoothPeriod+0.5; +/* Generated */ DCPeriodInt = (int)DCPeriod; +/* Generated */ realPart = 0.0; +/* Generated */ imagPart = 0.0; +/* Generated */ idx = smoothPrice_Idx; +/* Generated */ for( i=0; i < DCPeriodInt; i++ ) +/* Generated */ { +/* Generated */ tempReal = ((double)i*constDeg2RadBy360)/(double)DCPeriodInt; +/* Generated */ tempReal2 = smoothPrice[idx]; +/* Generated */ realPart += std_sin(tempReal)*tempReal2; +/* Generated */ imagPart += std_cos(tempReal)*tempReal2; +/* Generated */ if( idx == 0 ) +/* Generated */ idx = SMOOTH_PRICE_SIZE-1; +/* Generated */ else +/* Generated */ idx--; +/* Generated */ } +/* Generated */ tempReal = std_fabs(imagPart); +/* Generated */ if( tempReal > 0.0 ) +/* Generated */ DCPhase = std_atan(realPart/imagPart)*rad2Deg; +/* Generated */ else if( tempReal <= 0.01 ) +/* Generated */ { +/* Generated */ if( realPart < 0.0 ) +/* Generated */ DCPhase -= 90.0; +/* Generated */ else if( realPart > 0.0 ) +/* Generated */ DCPhase += 90.0; +/* Generated */ } +/* Generated */ DCPhase += 90.0; +/* Generated */ DCPhase += 360.0 / smoothPeriod; +/* Generated */ if( imagPart < 0.0 ) +/* Generated */ DCPhase += 180.0; +/* Generated */ if( DCPhase > 315.0 ) +/* Generated */ DCPhase -= 360.0; +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outSine[outIdx] = std_sin(DCPhase*deg2Rad); +/* Generated */ outLeadSine[outIdx++] = std_sin((DCPhase+45)*deg2Rad); +/* Generated */ } +/* Generated */ CIRCBUF_NEXT(smoothPrice); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_HT_TRENDLINE.c b/talib/ta_func/ta_HT_TRENDLINE.c new file mode 100644 index 0000000..e06f666 --- /dev/null +++ b/talib/ta_func/ta_HT_TRENDLINE.c @@ -0,0 +1,649 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::HtTrendlineLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int htTrendlineLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_HT_TRENDLINE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* 31 input are skip + * +32 output are skip to account for misc lookback + * --- + * 63 Total Lookback + * + * 31 is for being compatible with Tradestation. + * See TA_MAMA_Lookback for an explanation of the "32". + */ + return 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_TRENDLINE,HtTrendline); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_HT_TRENDLINE - Hilbert Transform - Instantaneous Trendline + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtTrendline( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtTrendline( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htTrendline( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_HT_TRENDLINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variable to keep track of the last 3 ITrend */ + double iTrend1, iTrend2, iTrend3; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg; + + double todayValue, smoothPeriod; + + /* Variable used to keep track of the previous + * smooth price. In the case of this algorithm, + * we will never need more than 50 values. + */ + #define SMOOTH_PRICE_SIZE 50 + CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); + int idx; + + /* Variable used to calculate the dominant cycle phase */ + int DCPeriodInt; + double DCPeriod; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); + + iTrend1 = iTrend2 = iTrend3 = 0.0; + + /* Constant */ + tempReal = std_atan(1); + rad2Deg = 45.0/tempReal; + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_TRENDLINE,HtTrendline); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 34; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + smoothPeriod = 0.0; + + for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) + smoothPrice[i] = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + /* Remember the smoothedValue into the smoothPrice + * circular buffer. + */ + smoothPrice[smoothPrice_Idx] = smoothedValue; + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "even" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + smoothPeriod = (0.33*period)+(0.67*smoothPeriod); + + /* Compute Trendline */ + DCPeriod = smoothPeriod+0.5; + DCPeriodInt = (int)DCPeriod; + + /* idx is used to iterate for up to 50 of the last + * value of smoothPrice. + */ + idx = today; + tempReal = 0.0; + for( i=0; i < DCPeriodInt; i++ ) + tempReal += inReal[idx--]; + + if( DCPeriodInt > 0 ) + tempReal = tempReal/(double)DCPeriodInt; + + tempReal2 = (4.0*tempReal + 3.0*iTrend1 + 2.0*iTrend2 + iTrend3) / 10.0; + iTrend3 = iTrend2; + iTrend2 = iTrend1; + iTrend1 = tempReal; + + if( today >= startIdx ) + { + outReal[outIdx++] = tempReal2; + } + + /* Ooof... let's do the next price bar now! */ + CIRCBUF_NEXT(smoothPrice); + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtTrendline( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtTrendline( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htTrendline( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_HT_TRENDLINE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ double iTrend1, iTrend2, iTrend3; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg; +/* Generated */ double todayValue, smoothPeriod; +/* Generated */ #define SMOOTH_PRICE_SIZE 50 +/* Generated */ CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); +/* Generated */ int idx; +/* Generated */ int DCPeriodInt; +/* Generated */ double DCPeriod; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); +/* Generated */ iTrend1 = iTrend2 = iTrend3 = 0.0; +/* Generated */ tempReal = std_atan(1); +/* Generated */ rad2Deg = 45.0/tempReal; +/* Generated */ lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_TRENDLINE,HtTrendline); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 34; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ smoothPeriod = 0.0; +/* Generated */ for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) +/* Generated */ smoothPrice[i] = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ smoothPrice[smoothPrice_Idx] = smoothedValue; +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ smoothPeriod = (0.33*period)+(0.67*smoothPeriod); +/* Generated */ DCPeriod = smoothPeriod+0.5; +/* Generated */ DCPeriodInt = (int)DCPeriod; +/* Generated */ idx = today; +/* Generated */ tempReal = 0.0; +/* Generated */ for( i=0; i < DCPeriodInt; i++ ) +/* Generated */ tempReal += inReal[idx--]; +/* Generated */ if( DCPeriodInt > 0 ) +/* Generated */ tempReal = tempReal/(double)DCPeriodInt; +/* Generated */ tempReal2 = (4.0*tempReal + 3.0*iTrend1 + 2.0*iTrend2 + iTrend3) / 10.0; +/* Generated */ iTrend3 = iTrend2; +/* Generated */ iTrend2 = iTrend1; +/* Generated */ iTrend1 = tempReal; +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = tempReal2; +/* Generated */ } +/* Generated */ CIRCBUF_NEXT(smoothPrice); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_HT_TRENDMODE.c b/talib/ta_func/ta_HT_TRENDMODE.c new file mode 100644 index 0000000..b1dd68c --- /dev/null +++ b/talib/ta_func/ta_HT_TRENDMODE.c @@ -0,0 +1,802 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::HtTrendModeLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int htTrendModeLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_HT_TRENDMODE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* 31 input are skip + * +32 output are skip to account for misc lookback + * --- + * 63 Total Lookback + * + * 31 is for being compatible with Tradestation. + * See TA_MAMA_Lookback for an explanation of the "32". + */ + return 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_TRENDMODE,HtTrendMode); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_HT_TRENDMODE - Hilbert Transform - Trend vs Cycle Mode + * + * Input = double + * Output = int + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtTrendMode( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtTrendMode( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htTrendMode( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_HT_TRENDMODE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variable to keep track of the last 3 ITrend */ + double iTrend1, iTrend2, iTrend3; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg, deg2Rad, constDeg2RadBy360; + + double todayValue, smoothPeriod; + + /* Variable used to keep track of the previous + * smooth price. In the case of this algorithm, + * we will never need more than 50 values. + */ + #define SMOOTH_PRICE_SIZE 50 + CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); + int idx; + + /* Variable used to calculate the dominant cycle phase */ + int DCPeriodInt; + double DCPhase, DCPeriod, imagPart, realPart; + + /* Variable used to calculate the trend mode */ + int daysInTrend, trend; + double prevDCPhase, trendline; + double prevSine, prevLeadSine, sine, leadSine; + + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); + + iTrend1 = iTrend2 = iTrend3 = 0.0; + daysInTrend = 0; + prevDCPhase = DCPhase = 0.0; + prevSine = sine = 0.0; + prevLeadSine = leadSine = 0.0; + + /* The following could be replaced by constant eventually. */ + tempReal = std_atan(1); + rad2Deg = 45.0/tempReal; + deg2Rad = 1.0/rad2Deg; + constDeg2RadBy360 = tempReal*8.0; + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_TRENDMODE,HtTrendMode); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 34; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + smoothPeriod = 0.0; + + for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) + smoothPrice[i] = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + DCPhase = 0.0; + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + /* Remember the smoothedValue into the smoothPrice + * circular buffer. + */ + smoothPrice[smoothPrice_Idx] = smoothedValue; + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "even" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + smoothPeriod = (0.33*period)+(0.67*smoothPeriod); + + /* Compute Dominant Cycle Phase */ + prevDCPhase = DCPhase; + DCPeriod = smoothPeriod+0.5; + DCPeriodInt = (int)DCPeriod; + realPart = 0.0; + imagPart = 0.0; + + /* idx is used to iterate for up to 50 of the last + * value of smoothPrice. + */ + idx = smoothPrice_Idx; + for( i=0; i < DCPeriodInt; i++ ) + { + tempReal = ((double)i*constDeg2RadBy360)/(double)DCPeriodInt; + tempReal2 = smoothPrice[idx]; + realPart += std_sin(tempReal)*tempReal2; + imagPart += std_cos(tempReal)*tempReal2; + if( idx == 0 ) + idx = SMOOTH_PRICE_SIZE-1; + else + idx--; + } + + tempReal = std_fabs(imagPart); + if( tempReal > 0.0 ) + DCPhase = std_atan(realPart/imagPart)*rad2Deg; + else if( tempReal <= 0.01 ) + { + if( realPart < 0.0 ) + DCPhase -= 90.0; + else if( realPart > 0.0 ) + DCPhase += 90.0; + } + DCPhase += 90.0; + + /* Compensate for one bar lag of the weighted moving average */ + DCPhase += 360.0 / smoothPeriod; + if( imagPart < 0.0 ) + DCPhase += 180.0; + if( DCPhase > 315.0 ) + DCPhase -= 360.0; + + prevSine = sine; + prevLeadSine = leadSine; + sine = std_sin(DCPhase*deg2Rad); + leadSine = std_sin((DCPhase+45)*deg2Rad); + + /* Compute Trendline */ + DCPeriod = smoothPeriod+0.5; + DCPeriodInt = (int)DCPeriod; + + /* idx is used to iterate for up to 50 of the last + * value of smoothPrice. + */ + idx = today; + tempReal = 0.0; + for( i=0; i < DCPeriodInt; i++ ) + tempReal += inReal[idx--]; + + if( DCPeriodInt > 0 ) + tempReal = tempReal/(double)DCPeriodInt; + + trendline = (4.0*tempReal + 3.0*iTrend1 + 2.0*iTrend2 + iTrend3) / 10.0; + iTrend3 = iTrend2; + iTrend2 = iTrend1; + iTrend1 = tempReal; + + /* Compute the trend Mode , and assume trend by default */ + trend = 1; + + /* Measure days in trend from last crossing of the SineWave Indicator lines */ + if( ((sine > leadSine) && (prevSine <= prevLeadSine)) || + ((sine < leadSine) && (prevSine >= prevLeadSine)) ) + { + daysInTrend = 0; + trend = 0; + } + + daysInTrend++; + + if( daysInTrend < (0.5*smoothPeriod) ) + trend = 0; + + tempReal = DCPhase - prevDCPhase; + if( (smoothPeriod != 0.0) && + ((tempReal > (0.67*360.0/smoothPeriod)) && (tempReal < (1.5*360.0/smoothPeriod))) ) + { + trend = 0; + } + + tempReal = smoothPrice[smoothPrice_Idx]; + if( (trendline != 0.0) && (std_fabs( (tempReal - trendline)/trendline ) >= 0.015) ) + trend = 1; + + if( today >= startIdx ) + { + outInteger[outIdx++] = trend; + } + + /* Ooof... let's do the next price bar now! */ + CIRCBUF_NEXT(smoothPrice); + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::HtTrendMode( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::HtTrendMode( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode htTrendMode( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_HT_TRENDMODE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ double iTrend1, iTrend2, iTrend3; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg, deg2Rad, constDeg2RadBy360; +/* Generated */ double todayValue, smoothPeriod; +/* Generated */ #define SMOOTH_PRICE_SIZE 50 +/* Generated */ CIRCBUF_PROLOG(smoothPrice,double,SMOOTH_PRICE_SIZE); +/* Generated */ int idx; +/* Generated */ int DCPeriodInt; +/* Generated */ double DCPhase, DCPeriod, imagPart, realPart; +/* Generated */ int daysInTrend, trend; +/* Generated */ double prevDCPhase, trendline; +/* Generated */ double prevSine, prevLeadSine, sine, leadSine; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ CIRCBUF_INIT_LOCAL_ONLY(smoothPrice,double); +/* Generated */ iTrend1 = iTrend2 = iTrend3 = 0.0; +/* Generated */ daysInTrend = 0; +/* Generated */ prevDCPhase = DCPhase = 0.0; +/* Generated */ prevSine = sine = 0.0; +/* Generated */ prevLeadSine = leadSine = 0.0; +/* Generated */ tempReal = std_atan(1); +/* Generated */ rad2Deg = 45.0/tempReal; +/* Generated */ deg2Rad = 1.0/rad2Deg; +/* Generated */ constDeg2RadBy360 = tempReal*8.0; +/* Generated */ lookbackTotal = 63 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_HT_TRENDMODE,HtTrendMode); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 34; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ smoothPeriod = 0.0; +/* Generated */ for( i=0; i < SMOOTH_PRICE_SIZE; i++ ) +/* Generated */ smoothPrice[i] = 0.0; +/* Generated */ DCPhase = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ smoothPrice[smoothPrice_Idx] = smoothedValue; +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ smoothPeriod = (0.33*period)+(0.67*smoothPeriod); +/* Generated */ prevDCPhase = DCPhase; +/* Generated */ DCPeriod = smoothPeriod+0.5; +/* Generated */ DCPeriodInt = (int)DCPeriod; +/* Generated */ realPart = 0.0; +/* Generated */ imagPart = 0.0; +/* Generated */ idx = smoothPrice_Idx; +/* Generated */ for( i=0; i < DCPeriodInt; i++ ) +/* Generated */ { +/* Generated */ tempReal = ((double)i*constDeg2RadBy360)/(double)DCPeriodInt; +/* Generated */ tempReal2 = smoothPrice[idx]; +/* Generated */ realPart += std_sin(tempReal)*tempReal2; +/* Generated */ imagPart += std_cos(tempReal)*tempReal2; +/* Generated */ if( idx == 0 ) +/* Generated */ idx = SMOOTH_PRICE_SIZE-1; +/* Generated */ else +/* Generated */ idx--; +/* Generated */ } +/* Generated */ tempReal = std_fabs(imagPart); +/* Generated */ if( tempReal > 0.0 ) +/* Generated */ DCPhase = std_atan(realPart/imagPart)*rad2Deg; +/* Generated */ else if( tempReal <= 0.01 ) +/* Generated */ { +/* Generated */ if( realPart < 0.0 ) +/* Generated */ DCPhase -= 90.0; +/* Generated */ else if( realPart > 0.0 ) +/* Generated */ DCPhase += 90.0; +/* Generated */ } +/* Generated */ DCPhase += 90.0; +/* Generated */ DCPhase += 360.0 / smoothPeriod; +/* Generated */ if( imagPart < 0.0 ) +/* Generated */ DCPhase += 180.0; +/* Generated */ if( DCPhase > 315.0 ) +/* Generated */ DCPhase -= 360.0; +/* Generated */ prevSine = sine; +/* Generated */ prevLeadSine = leadSine; +/* Generated */ sine = std_sin(DCPhase*deg2Rad); +/* Generated */ leadSine = std_sin((DCPhase+45)*deg2Rad); +/* Generated */ DCPeriod = smoothPeriod+0.5; +/* Generated */ DCPeriodInt = (int)DCPeriod; +/* Generated */ idx = today; +/* Generated */ tempReal = 0.0; +/* Generated */ for( i=0; i < DCPeriodInt; i++ ) +/* Generated */ tempReal += inReal[idx--]; +/* Generated */ if( DCPeriodInt > 0 ) +/* Generated */ tempReal = tempReal/(double)DCPeriodInt; +/* Generated */ trendline = (4.0*tempReal + 3.0*iTrend1 + 2.0*iTrend2 + iTrend3) / 10.0; +/* Generated */ iTrend3 = iTrend2; +/* Generated */ iTrend2 = iTrend1; +/* Generated */ iTrend1 = tempReal; +/* Generated */ trend = 1; +/* Generated */ if( ((sine > leadSine) && (prevSine <= prevLeadSine)) || +/* Generated */ ((sine < leadSine) && (prevSine >= prevLeadSine)) ) +/* Generated */ { +/* Generated */ daysInTrend = 0; +/* Generated */ trend = 0; +/* Generated */ } +/* Generated */ daysInTrend++; +/* Generated */ if( daysInTrend < (0.5*smoothPeriod) ) +/* Generated */ trend = 0; +/* Generated */ tempReal = DCPhase - prevDCPhase; +/* Generated */ if( (smoothPeriod != 0.0) && +/* Generated */ ((tempReal > (0.67*360.0/smoothPeriod)) && (tempReal < (1.5*360.0/smoothPeriod))) ) +/* Generated */ { +/* Generated */ trend = 0; +/* Generated */ } +/* Generated */ tempReal = smoothPrice[smoothPrice_Idx]; +/* Generated */ if( (trendline != 0.0) && (std_fabs( (tempReal - trendline)/trendline ) >= 0.015) ) +/* Generated */ trend = 1; +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outInteger[outIdx++] = trend; +/* Generated */ } +/* Generated */ CIRCBUF_NEXT(smoothPrice); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_IMI.c b/talib/ta_func/ta_IMI.c new file mode 100644 index 0000000..0736cae --- /dev/null +++ b/talib/ta_func/ta_IMI.c @@ -0,0 +1,338 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AB Anatoliy Belsky + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 181012 AB Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::ImiLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int imiLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_IMI_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_IMI, Imi) - 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_IMI - Intraday Momentum Index + * + * Input = Open, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Imi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Imi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode imi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inOpen[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_IMI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inOpen[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int lookback, outIdx = 0; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inOpen||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + lookback = LOOKBACK_CALL(IMI)( optInTimePeriod ); + + if(startIdx < lookback) + startIdx = lookback; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + while (startIdx <= endIdx) { + double upsum = .0, downsum = .0; + int i; + + for (i = startIdx - lookback; i <= startIdx; i++) { + double close = inClose[i]; + double open = inOpen[i]; + + if (close > open) { + upsum += (close - open); + } else { + downsum += (open - close); + } + + outReal[outIdx] = 100.0*(upsum/(upsum + downsum)); + } + + startIdx++; + outIdx++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Imi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inOpen, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Imi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inOpen, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode imi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inOpen[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_IMI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inOpen[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int lookback, outIdx = 0; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inOpen||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookback = LOOKBACK_CALL(IMI)( optInTimePeriod ); +/* Generated */ if(startIdx < lookback) +/* Generated */ startIdx = lookback; +/* Generated */ if( startIdx > endIdx ) { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ while (startIdx <= endIdx) { +/* Generated */ double upsum = .0, downsum = .0; +/* Generated */ int i; +/* Generated */ for (i = startIdx - lookback; i <= startIdx; i++) { +/* Generated */ double close = inClose[i]; +/* Generated */ double open = inOpen[i]; +/* Generated */ if (close > open) { +/* Generated */ upsum += (close - open); +/* Generated */ } else { +/* Generated */ downsum += (open - close); +/* Generated */ } +/* Generated */ outReal[outIdx] = 100.0*(upsum/(upsum + downsum)); +/* Generated */ } +/* Generated */ startIdx++; +/* Generated */ outIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_KAMA.c b/talib/ta_func/ta_KAMA.c new file mode 100644 index 0000000..9f15136 --- /dev/null +++ b/talib/ta_func/ta_KAMA.c @@ -0,0 +1,506 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 062704 MF Fix limit case to avoid divid by zero (or by + * a value close to zero induce by the imprecision + * of floating points). + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::KamaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int kamaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_KAMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_KAMA,Kama); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_KAMA - Kaufman Adaptive Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Kama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Kama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode kama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_KAMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + CONSTANT_DOUBLE(constMax) = 2.0/(30.0+1.0); + CONSTANT_DOUBLE(constDiff) = 2.0/(2.0+1.0) - constMax; + + double tempReal, tempReal2; + double sumROC1, periodROC, prevKAMA; + int i, today, outIdx, lookbackTotal; + int trailingIdx; + double trailingValue; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Default return values */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_KAMA,Kama); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Initialize the variables by going through + * the lookback period. + */ + sumROC1 = 0.0; + today = startIdx-lookbackTotal; + trailingIdx = today; + i = optInTimePeriod; + while( i-- > 0 ) + { + tempReal = inReal[today++]; + tempReal -= inReal[today]; + sumROC1 += std_fabs(tempReal); + } + + /* At this point sumROC1 represent the + * summation of the 1-day price difference + * over the (optInTimePeriod-1) + */ + + /* Calculate the first KAMA */ + + /* The yesterday price is used here as the previous KAMA. */ + prevKAMA = inReal[today-1]; + + tempReal = inReal[today]; + tempReal2 = inReal[trailingIdx++]; + periodROC = tempReal-tempReal2; + + /* Save the trailing value. Do this because inReal + * and outReal can be pointers to the same buffer. + */ + trailingValue = tempReal2; + + /* Calculate the efficiency ratio */ + if( (sumROC1 <= periodROC) || TA_IS_ZERO(sumROC1)) + tempReal = 1.0; + else + tempReal = std_fabs(periodROC/sumROC1); + + /* Calculate the smoothing constant */ + tempReal = (tempReal*constDiff)+constMax; + tempReal *= tempReal; + + /* Calculate the KAMA like an EMA, using the + * smoothing constant as the adaptive factor. + */ + prevKAMA = ((inReal[today++]-prevKAMA)*tempReal) + prevKAMA; + + /* 'today' keep track of where the processing is within the + * input. + */ + + /* Skip the unstable period. Do the whole processing + * needed for KAMA, but do not write it in the output. + */ + while( today <= startIdx ) + { + tempReal = inReal[today]; + tempReal2 = inReal[trailingIdx++]; + periodROC = tempReal-tempReal2; + + /* Adjust sumROC1: + * - Remove trailing ROC1 + * - Add new ROC1 + */ + sumROC1 -= std_fabs(trailingValue-tempReal2); + sumROC1 += std_fabs(tempReal-inReal[today-1]); + + /* Save the trailing value. Do this because inReal + * and outReal can be pointers to the same buffer. + */ + trailingValue = tempReal2; + + /* Calculate the efficiency ratio */ + if( (sumROC1 <= periodROC) || TA_IS_ZERO(sumROC1) ) + tempReal = 1.0; + else + tempReal = std_fabs(periodROC/sumROC1); + + /* Calculate the smoothing constant */ + tempReal = (tempReal*constDiff)+constMax; + tempReal *= tempReal; + + /* Calculate the KAMA like an EMA, using the + * smoothing constant as the adaptive factor. + */ + prevKAMA = ((inReal[today++]-prevKAMA)*tempReal) + prevKAMA; + } + + /* Write the first value. */ + outReal[0] = prevKAMA; + outIdx = 1; + VALUE_HANDLE_DEREF(outBegIdx) = today-1; + + /* Do the KAMA calculation for the requested range. */ + while( today <= endIdx ) + { + tempReal = inReal[today]; + tempReal2 = inReal[trailingIdx++]; + periodROC = tempReal-tempReal2; + + /* Adjust sumROC1: + * - Remove trailing ROC1 + * - Add new ROC1 + */ + sumROC1 -= std_fabs(trailingValue-tempReal2); + sumROC1 += std_fabs(tempReal-inReal[today-1]); + + /* Save the trailing value. Do this because inReal + * and outReal can be pointers to the same buffer. + */ + trailingValue = tempReal2; + + /* Calculate the efficiency ratio */ + if( (sumROC1 <= periodROC) || TA_IS_ZERO(sumROC1) ) + tempReal = 1.0; + else + tempReal = std_fabs(periodROC / sumROC1); + + /* Calculate the smoothing constant */ + tempReal = (tempReal*constDiff)+constMax; + tempReal *= tempReal; + + /* Calculate the KAMA like an EMA, using the + * smoothing constant as the adaptive factor. + */ + prevKAMA = ((inReal[today++]-prevKAMA)*tempReal) + prevKAMA; + outReal[outIdx++] = prevKAMA; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Kama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Kama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode kama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_KAMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ CONSTANT_DOUBLE(constMax) = 2.0/(30.0+1.0); +/* Generated */ CONSTANT_DOUBLE(constDiff) = 2.0/(2.0+1.0) - constMax; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double sumROC1, periodROC, prevKAMA; +/* Generated */ int i, today, outIdx, lookbackTotal; +/* Generated */ int trailingIdx; +/* Generated */ double trailingValue; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_KAMA,Kama); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ sumROC1 = 0.0; +/* Generated */ today = startIdx-lookbackTotal; +/* Generated */ trailingIdx = today; +/* Generated */ i = optInTimePeriod; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ tempReal -= inReal[today]; +/* Generated */ sumROC1 += std_fabs(tempReal); +/* Generated */ } +/* Generated */ prevKAMA = inReal[today-1]; +/* Generated */ tempReal = inReal[today]; +/* Generated */ tempReal2 = inReal[trailingIdx++]; +/* Generated */ periodROC = tempReal-tempReal2; +/* Generated */ trailingValue = tempReal2; +/* Generated */ if( (sumROC1 <= periodROC) || TA_IS_ZERO(sumROC1)) +/* Generated */ tempReal = 1.0; +/* Generated */ else +/* Generated */ tempReal = std_fabs(periodROC/sumROC1); +/* Generated */ tempReal = (tempReal*constDiff)+constMax; +/* Generated */ tempReal *= tempReal; +/* Generated */ prevKAMA = ((inReal[today++]-prevKAMA)*tempReal) + prevKAMA; +/* Generated */ while( today <= startIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[today]; +/* Generated */ tempReal2 = inReal[trailingIdx++]; +/* Generated */ periodROC = tempReal-tempReal2; +/* Generated */ sumROC1 -= std_fabs(trailingValue-tempReal2); +/* Generated */ sumROC1 += std_fabs(tempReal-inReal[today-1]); +/* Generated */ trailingValue = tempReal2; +/* Generated */ if( (sumROC1 <= periodROC) || TA_IS_ZERO(sumROC1) ) +/* Generated */ tempReal = 1.0; +/* Generated */ else +/* Generated */ tempReal = std_fabs(periodROC/sumROC1); +/* Generated */ tempReal = (tempReal*constDiff)+constMax; +/* Generated */ tempReal *= tempReal; +/* Generated */ prevKAMA = ((inReal[today++]-prevKAMA)*tempReal) + prevKAMA; +/* Generated */ } +/* Generated */ outReal[0] = prevKAMA; +/* Generated */ outIdx = 1; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = today-1; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[today]; +/* Generated */ tempReal2 = inReal[trailingIdx++]; +/* Generated */ periodROC = tempReal-tempReal2; +/* Generated */ sumROC1 -= std_fabs(trailingValue-tempReal2); +/* Generated */ sumROC1 += std_fabs(tempReal-inReal[today-1]); +/* Generated */ trailingValue = tempReal2; +/* Generated */ if( (sumROC1 <= periodROC) || TA_IS_ZERO(sumROC1) ) +/* Generated */ tempReal = 1.0; +/* Generated */ else +/* Generated */ tempReal = std_fabs(periodROC / sumROC1); +/* Generated */ tempReal = (tempReal*constDiff)+constMax; +/* Generated */ tempReal *= tempReal; +/* Generated */ prevKAMA = ((inReal[today++]-prevKAMA)*tempReal) + prevKAMA; +/* Generated */ outReal[outIdx++] = prevKAMA; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_LINEARREG.c b/talib/ta_func/ta_LINEARREG.c new file mode 100644 index 0000000..814a906 --- /dev/null +++ b/talib/ta_func/ta_LINEARREG.c @@ -0,0 +1,363 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * JP John Price + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 070203 JP Initial. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::LinearRegLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int linearRegLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_LINEARREG_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_LINEARREG - Linear Regression + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearReg( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearReg( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearReg( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_LINEARREG( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + int today, lookbackTotal; + double SumX, SumXY, SumY, SumXSqr, Divisor; + + double m, b; + int i; + + double tempValue1; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Linear Regression is a concept also known as the + * "least squares method" or "best fit." Linear + * Regression attempts to fit a straight line between + * several data points in such a way that distance + * between each data point and the line is minimized. + * + * For each point, a straight line over the specified + * previous bar period is determined in terms + * of y = b + m*x: + * + * TA_LINEARREG : Returns b+m*(period-1) + * TA_LINEARREG_SLOPE : Returns 'm' + * TA_LINEARREG_ANGLE : Returns 'm' in degree. + * TA_LINEARREG_INTERCEPT: Returns 'b' + * TA_TSF : Returns b+m*(period) + */ + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(LINEARREG)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; /* Index into the output. */ + today = startIdx; + + SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; + SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; + Divisor = SumX * SumX - optInTimePeriod * SumXSqr; + + while( today <= endIdx ) + { + SumXY = 0; + SumY = 0; + for( i = optInTimePeriod; i-- != 0; ) + { + SumY += tempValue1 = inReal[today - i]; + SumXY += (double)i * tempValue1; + } + m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; + b = ( SumY - m * SumX ) / (double)optInTimePeriod; + outReal[outIdx++] = b + m * (double)(optInTimePeriod-1); + today++; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearReg( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearReg( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearReg( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_LINEARREG( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal; +/* Generated */ double SumX, SumXY, SumY, SumXSqr, Divisor; +/* Generated */ double m, b; +/* Generated */ int i; +/* Generated */ double tempValue1; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(LINEARREG)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; +/* Generated */ SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; +/* Generated */ Divisor = SumX * SumX - optInTimePeriod * SumXSqr; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ SumXY = 0; +/* Generated */ SumY = 0; +/* Generated */ for( i = optInTimePeriod; i-- != 0; ) +/* Generated */ { +/* Generated */ SumY += tempValue1 = inReal[today - i]; +/* Generated */ SumXY += (double)i * tempValue1; +/* Generated */ } +/* Generated */ m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; +/* Generated */ b = ( SumY - m * SumX ) / (double)optInTimePeriod; +/* Generated */ outReal[outIdx++] = b + m * (double)(optInTimePeriod-1); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_LINEARREG_ANGLE.c b/talib/ta_func/ta_LINEARREG_ANGLE.c new file mode 100644 index 0000000..793653c --- /dev/null +++ b/talib/ta_func/ta_LINEARREG_ANGLE.c @@ -0,0 +1,363 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * JP John Price + * MF Mario Fortier + * AM Adrian Michel + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 070203 JP Initial. + * 072106 MF,AM Fix #1526632. Add missing atan(). + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::LinearRegAngleLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int linearRegAngleLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_LINEARREG_ANGLE_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_LINEARREG_ANGLE - Linear Regression Angle + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearRegAngle( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearRegAngle( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearRegAngle( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_LINEARREG_ANGLE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + int today, lookbackTotal; + double SumX, SumXY, SumY, SumXSqr, Divisor; + + double m; + + int i; + + double tempValue1; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Linear Regression is a concept also known as the + * "least squares method" or "best fit." Linear + * Regression attempts to fit a straight line between + * several data points in such a way that distance + * between each data point and the line is minimized. + * + * For each point, a straight line over the specified + * previous bar period is determined in terms + * of y = b + m*x: + * + * TA_LINEARREG : Returns b+m*(period-1) + * TA_LINEARREG_SLOPE : Returns 'm' + * TA_LINEARREG_ANGLE : Returns 'm' in degree. + * TA_LINEARREG_INTERCEPT: Returns 'b' + * TA_TSF : Returns b+m*(period) + */ + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(LINEARREG_ANGLE)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; /* Index into the output. */ + today = startIdx; + + SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; + SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; + Divisor = SumX * SumX - optInTimePeriod * SumXSqr; + + while( today <= endIdx ) + { + SumXY = 0; + SumY = 0; + for( i = optInTimePeriod; i-- != 0; ) + { + SumY += tempValue1 = inReal[today - i]; + SumXY += (double)i * tempValue1; + } + m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; + outReal[outIdx++] = std_atan(m) * ( 180.0 / PI ); + today++; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearRegAngle( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearRegAngle( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearRegAngle( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_LINEARREG_ANGLE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal; +/* Generated */ double SumX, SumXY, SumY, SumXSqr, Divisor; +/* Generated */ double m; +/* Generated */ int i; +/* Generated */ double tempValue1; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(LINEARREG_ANGLE)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; +/* Generated */ SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; +/* Generated */ Divisor = SumX * SumX - optInTimePeriod * SumXSqr; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ SumXY = 0; +/* Generated */ SumY = 0; +/* Generated */ for( i = optInTimePeriod; i-- != 0; ) +/* Generated */ { +/* Generated */ SumY += tempValue1 = inReal[today - i]; +/* Generated */ SumXY += (double)i * tempValue1; +/* Generated */ } +/* Generated */ m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; +/* Generated */ outReal[outIdx++] = std_atan(m) * ( 180.0 / PI ); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_LINEARREG_INTERCEPT.c b/talib/ta_func/ta_LINEARREG_INTERCEPT.c new file mode 100644 index 0000000..640bac4 --- /dev/null +++ b/talib/ta_func/ta_LINEARREG_INTERCEPT.c @@ -0,0 +1,361 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * JP John Price + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 070203 JP Initial. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::LinearRegInterceptLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int linearRegInterceptLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_LINEARREG_INTERCEPT_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_LINEARREG_INTERCEPT - Linear Regression Intercept + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearRegIntercept( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearRegIntercept( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearRegIntercept( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_LINEARREG_INTERCEPT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + int today, lookbackTotal; + double SumX, SumXY, SumY, SumXSqr, Divisor; + + double m; + int i; + + double tempValue1; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Linear Regression is a concept also known as the + * "least squares method" or "best fit." Linear + * Regression attempts to fit a straight line between + * several data points in such a way that distance + * between each data point and the line is minimized. + * + * For each point, a straight line over the specified + * previous bar period is determined in terms + * of y = b + m*x: + * + * TA_LINEARREG : Returns b+m*(period-1) + * TA_LINEARREG_SLOPE : Returns 'm' + * TA_LINEARREG_ANGLE : Returns 'm' in degree. + * TA_LINEARREG_INTERCEPT: Returns 'b' + * TA_TSF : Returns b+m*(period) + */ + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(LINEARREG_INTERCEPT)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; /* Index into the output. */ + today = startIdx; + + SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; + SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; + Divisor = SumX * SumX - optInTimePeriod * SumXSqr; + + while( today <= endIdx ) + { + SumXY = 0; + SumY = 0; + for( i = optInTimePeriod; i-- != 0; ) + { + SumY += tempValue1 = inReal[today - i]; + SumXY += (double)i * tempValue1; + } + m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; + outReal[outIdx++] = ( SumY - m * SumX ) / (double)optInTimePeriod; + today++; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearRegIntercept( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearRegIntercept( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearRegIntercept( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_LINEARREG_INTERCEPT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal; +/* Generated */ double SumX, SumXY, SumY, SumXSqr, Divisor; +/* Generated */ double m; +/* Generated */ int i; +/* Generated */ double tempValue1; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(LINEARREG_INTERCEPT)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; +/* Generated */ SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; +/* Generated */ Divisor = SumX * SumX - optInTimePeriod * SumXSqr; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ SumXY = 0; +/* Generated */ SumY = 0; +/* Generated */ for( i = optInTimePeriod; i-- != 0; ) +/* Generated */ { +/* Generated */ SumY += tempValue1 = inReal[today - i]; +/* Generated */ SumXY += (double)i * tempValue1; +/* Generated */ } +/* Generated */ m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; +/* Generated */ outReal[outIdx++] = ( SumY - m * SumX ) / (double)optInTimePeriod; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_LINEARREG_SLOPE.c b/talib/ta_func/ta_LINEARREG_SLOPE.c new file mode 100644 index 0000000..328f135 --- /dev/null +++ b/talib/ta_func/ta_LINEARREG_SLOPE.c @@ -0,0 +1,357 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * JP John Price + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 070203 JP Initial. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::LinearRegSlopeLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int linearRegSlopeLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_LINEARREG_SLOPE_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_LINEARREG_SLOPE - Linear Regression Slope + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearRegSlope( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearRegSlope( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearRegSlope( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_LINEARREG_SLOPE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + int today, lookbackTotal; + double SumX, SumXY, SumY, SumXSqr, Divisor; + + int i; + + double tempValue1; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Linear Regression is a concept also known as the + * "least squares method" or "best fit." Linear + * Regression attempts to fit a straight line between + * several data points in such a way that distance + * between each data point and the line is minimized. + * + * For each point, a straight line over the specified + * previous bar period is determined in terms + * of y = b + m*x: + * + * TA_LINEARREG : Returns b+m*(period-1) + * TA_LINEARREG_SLOPE : Returns 'm' + * TA_LINEARREG_ANGLE : Returns 'm' in degree. + * TA_LINEARREG_INTERCEPT: Returns 'b' + * TA_TSF : Returns b+m*(period) + */ + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(LINEARREG_SLOPE)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; /* Index into the output. */ + today = startIdx; + + SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; + SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; + Divisor = SumX * SumX - optInTimePeriod * SumXSqr; + + while( today <= endIdx ) + { + SumXY = 0; + SumY = 0; + for( i = optInTimePeriod; i-- != 0; ) + { + SumY += tempValue1 = inReal[today - i]; + SumXY += (double)i * tempValue1; + } + outReal[outIdx++] = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; + today++; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::LinearRegSlope( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::LinearRegSlope( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode linearRegSlope( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_LINEARREG_SLOPE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal; +/* Generated */ double SumX, SumXY, SumY, SumXSqr, Divisor; +/* Generated */ int i; +/* Generated */ double tempValue1; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(LINEARREG_SLOPE)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; +/* Generated */ SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; +/* Generated */ Divisor = SumX * SumX - optInTimePeriod * SumXSqr; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ SumXY = 0; +/* Generated */ SumY = 0; +/* Generated */ for( i = optInTimePeriod; i-- != 0; ) +/* Generated */ { +/* Generated */ SumY += tempValue1 = inReal[today - i]; +/* Generated */ SumXY += (double)i * tempValue1; +/* Generated */ } +/* Generated */ outReal[outIdx++] = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_LN.c b/talib/ta_func/ta_LN.c new file mode 100644 index 0000000..f0d87bd --- /dev/null +++ b/talib/ta_func/ta_LN.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::LnLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int lnLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_LN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_LN - Vector Log Natural + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ln( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ln( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ln( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_LN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_log(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ln( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ln( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ln( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_LN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_log(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_LOG10.c b/talib/ta_func/ta_LOG10.c new file mode 100644 index 0000000..cc8e25f --- /dev/null +++ b/talib/ta_func/ta_LOG10.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::Log10Lookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int log10Lookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_LOG10_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_LOG10 - Vector Log10 + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Log10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Log10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode log10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_LOG10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_log10(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Log10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Log10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode log10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_LOG10( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_log10(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MA.c b/talib/ta_func/ta_MA.c new file mode 100644 index 0000000..f85e904 --- /dev/null +++ b/talib/ta_func/ta_MA.c @@ -0,0 +1,486 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 022203 MF Add MAMA + * 040503 MF Add T3 + * 052603 MF Adapt code to compile with .NET Managed C++ + * 111603 MF Allow period of 1. Just copy input into output. + * 060907 MF Use TA_SMA/TA_EMA instead of internal implementation. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MovingAverageLookback( int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int movingAverageLookback( int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MA_Lookback( int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInMAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + if( optInTimePeriod <= 1 ) + return 0; + + switch( optInMAType ) + { + case ENUM_CASE(MAType, TA_MAType_SMA, Sma ): + retValue = LOOKBACK_CALL(SMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_EMA, Ema): + retValue = LOOKBACK_CALL(EMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_WMA, Wma): + retValue = LOOKBACK_CALL(WMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_DEMA, Dema): + retValue = LOOKBACK_CALL(DEMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_TEMA, Tema ): + retValue = LOOKBACK_CALL(TEMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_TRIMA, Trima ): + retValue = LOOKBACK_CALL(TRIMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_KAMA, Kama ): + retValue = LOOKBACK_CALL(KAMA)( optInTimePeriod ); + break; + + case ENUM_CASE(MAType, TA_MAType_MAMA, Mama ): + retValue = LOOKBACK_CALL(MAMA)( 0.5, 0.05 ); + break; + + case ENUM_CASE(MAType, TA_MAType_T3, T3): + retValue = LOOKBACK_CALL(T3)( optInTimePeriod, 0.7 ); + break; + + default: + retValue = 0; + } + + return retValue; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MA - Moving average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * optInMAType: + * Type of Moving Average + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MovingAverage( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MovingAverage( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode movingAverage( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_REF(dummyBuffer); + ENUM_DECLARATION(RetCode) retCode; + + int nbElement; + int outIdx, todayIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + if( optInTimePeriod == 1 ) + { + nbElement = endIdx-startIdx+1; + VALUE_HANDLE_DEREF(outNBElement) = nbElement; + for( todayIdx=startIdx, outIdx=0; outIdx < nbElement; outIdx++, todayIdx++ ) + outReal[outIdx] = inReal[todayIdx]; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + /* Simply forward the job to the corresponding TA function. */ + switch( optInMAType ) + { + case ENUM_CASE(MAType, TA_MAType_SMA, Sma): + retCode = FUNCTION_CALL(SMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_EMA, Ema): + retCode = FUNCTION_CALL(EMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_WMA, Wma): + retCode = FUNCTION_CALL(WMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_DEMA, Dema): + retCode = FUNCTION_CALL(DEMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_TEMA, Tema): + retCode = FUNCTION_CALL(TEMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_TRIMA, Trima): + retCode = FUNCTION_CALL(TRIMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_KAMA, Kama): + retCode = FUNCTION_CALL(KAMA)( startIdx, endIdx, inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + break; + + case ENUM_CASE(MAType, TA_MAType_MAMA, Mama): + /* The optInTimePeriod is ignored and the FAMA output of the MAMA + * is ignored. + */ + ARRAY_ALLOC(dummyBuffer, (endIdx-startIdx+1) ); + + #if !defined( _JAVA ) + if( !dummyBuffer ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + + retCode = FUNCTION_CALL(MAMA)( startIdx, endIdx, inReal, 0.5, 0.05, + outBegIdx, outNBElement, + outReal, dummyBuffer ); + + ARRAY_FREE( dummyBuffer ); + break; + + case ENUM_CASE(MAType, TA_MAType_T3, T3 ): + retCode = FUNCTION_CALL(T3)( startIdx, endIdx, inReal, + optInTimePeriod, 0.7, + outBegIdx, outNBElement, outReal ); + break; + + default: + retCode = ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); + break; + } + + return retCode; +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MovingAverage( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MovingAverage( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode movingAverage( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(dummyBuffer); +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int nbElement; +/* Generated */ int outIdx, todayIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( optInTimePeriod == 1 ) +/* Generated */ { +/* Generated */ nbElement = endIdx-startIdx+1; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = nbElement; +/* Generated */ for( todayIdx=startIdx, outIdx=0; outIdx < nbElement; outIdx++, todayIdx++ ) +/* Generated */ outReal[outIdx] = inReal[todayIdx]; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ switch( optInMAType ) +/* Generated */ { +/* Generated */ case ENUM_CASE(MAType, TA_MAType_SMA, Sma): +/* Generated */ retCode = FUNCTION_CALL(SMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_EMA, Ema): +/* Generated */ retCode = FUNCTION_CALL(EMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_WMA, Wma): +/* Generated */ retCode = FUNCTION_CALL(WMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_DEMA, Dema): +/* Generated */ retCode = FUNCTION_CALL(DEMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_TEMA, Tema): +/* Generated */ retCode = FUNCTION_CALL(TEMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_TRIMA, Trima): +/* Generated */ retCode = FUNCTION_CALL(TRIMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_KAMA, Kama): +/* Generated */ retCode = FUNCTION_CALL(KAMA)( startIdx, endIdx, inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_MAMA, Mama): +/* Generated */ ARRAY_ALLOC(dummyBuffer, (endIdx-startIdx+1) ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !dummyBuffer ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL(MAMA)( startIdx, endIdx, inReal, 0.5, 0.05, +/* Generated */ outBegIdx, outNBElement, +/* Generated */ outReal, dummyBuffer ); +/* Generated */ ARRAY_FREE( dummyBuffer ); +/* Generated */ break; +/* Generated */ case ENUM_CASE(MAType, TA_MAType_T3, T3 ): +/* Generated */ retCode = FUNCTION_CALL(T3)( startIdx, endIdx, inReal, +/* Generated */ optInTimePeriod, 0.7, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ break; +/* Generated */ default: +/* Generated */ retCode = ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ break; +/* Generated */ } +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MACD.c b/talib/ta_func/ta_MACD.c new file mode 100644 index 0000000..f540cab --- /dev/null +++ b/talib/ta_func/ta_MACD.c @@ -0,0 +1,804 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JPP JP Pienaar (j.pienaar@mci.co.za) + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 080403 JPP Fix #767653 for logic when swapping periods. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MacdLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int macdLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MACD_Lookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int tempInteger; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInSignalPeriod. */ +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* The lookback is driven by the signal line output. + * + * (must also account for the initial data consume + * by the slow period). + */ + + /* Make sure slow is really slower than + * the fast period! if not, swap... + */ + if( optInSlowPeriod < optInFastPeriod ) + { + /* swap */ + tempInteger = optInSlowPeriod; + optInSlowPeriod = optInFastPeriod; + optInFastPeriod = tempInteger; + } + + return LOOKBACK_CALL(EMA)( optInSlowPeriod ) + + LOOKBACK_CALL(EMA)( optInSignalPeriod ); +} + + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MACD - Moving Average Convergence/Divergence + * + * Input = double + * Output = double, double, double + * + * Optional Parameters + * ------------------- + * optInFastPeriod:(From 2 to 100000) + * Number of period for the fast MA + * + * optInSlowPeriod:(From 2 to 100000) + * Number of period for the slow MA + * + * optInSignalPeriod:(From 1 to 100000) + * Smoothing for the signal line (nb of period) + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Macd( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Macd( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode macd( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MACD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInSignalPeriod. */ +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMACD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMACDSignal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMACDHist ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + return FUNCTION_CALL(INT_MACD)( startIdx, endIdx, inReal, + optInFastPeriod, + optInSlowPeriod, + optInSignalPeriod, + outBegIdx, + outNBElement, + outMACD, + outMACDSignal, + outMACDHist ); +} + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + // No INT function +#else + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) + enum class Core::RetCode Core::TA_INT_MACD( int startIdx, + int endIdx, + SubArray^ inReal, + int optInFastPeriod, /* 0 is fix 12 */ + int optInSlowPeriod, /* 0 is fix 26 */ + int optInSignalPeriod_2, + [Out]int% outBegIdx, + [Out]int% outNBElement, + SubArray^ outMACD, + SubArray^ outMACDSignal, + SubArray^ outMACDHist ) +#elif defined( _MANAGED ) + enum class Core::RetCode Core::TA_INT_MACD( int startIdx, + int endIdx, + cli::array^ inReal, + int optInFastPeriod, /* 0 is fix 12 */ + int optInSlowPeriod, /* 0 is fix 26 */ + int optInSignalPeriod_2, + [Out]int% outBegIdx, + [Out]int% outNBElement, + cli::array^ outMACD, + cli::array^ outMACDSignal, + cli::array^ outMACDHist ) +#elif defined( _JAVA ) +RetCode TA_INT_MACD( int startIdx, + int endIdx, + INPUT_TYPE inReal[], + int optInFastPeriod, /* 0 is fix 12 */ + int optInSlowPeriod, /* 0 is fix 26 */ + int optInSignalPeriod_2, + MInteger outBegIdx, + MInteger outNBElement, + double outMACD[], + double outMACDSignal[], + double outMACDHist[] ) + +#else +TA_RetCode TA_PREFIX(INT_MACD)( int startIdx, + int endIdx, + const INPUT_TYPE inReal[], + int optInFastPeriod, /* 0 is fix 12 */ + int optInSlowPeriod, /* 0 is fix 26 */ + int optInSignalPeriod_2, + int *outBegIdx, + int *outNBElement, + double outMACD[], + double outMACDSignal[], + double outMACDHist[] ) +#endif +{ + ARRAY_REF(slowEMABuffer); + ARRAY_REF(fastEMABuffer); + double k1, k2; + ENUM_DECLARATION(RetCode) retCode; + int tempInteger; + VALUE_HANDLE_INT(outBegIdx1); + VALUE_HANDLE_INT(outNbElement1); + VALUE_HANDLE_INT(outBegIdx2); + VALUE_HANDLE_INT(outNbElement2); + int lookbackTotal, lookbackSignal; + int i; + + /* !!! A lot of speed optimization could be done + * !!! with this function. + * !!! + * !!! A better approach would be to use TA_INT_EMA + * !!! just to get the seeding values for the + * !!! fast and slow EMA. Then process the difference + * !!! in an allocated buffer until enough data is + * !!! available for the first signal value. + * !!! From that point all the processing can + * !!! be done in a tight loop. + * !!! + * !!! That approach will have the following + * !!! advantage: + * !!! 1) One mem allocation needed instead of two. + * !!! 2) The mem allocation size will be only the + * !!! signal lookback period instead of the + * !!! whole range of data. + * !!! 3) Processing will be done in a tight loop. + * !!! allowing to avoid a lot of memory store-load + * !!! operation. + * !!! 4) The memcpy at the end will be eliminated! + * !!! + * !!! If only I had time.... + */ + + /* Make sure slow is really slower than + * the fast period! if not, swap... + */ + if( optInSlowPeriod < optInFastPeriod ) + { + /* swap */ + tempInteger = optInSlowPeriod; + optInSlowPeriod = optInFastPeriod; + optInFastPeriod = tempInteger; + } + + /* Catch special case for fix 26/12 MACD. */ + if( optInSlowPeriod != 0 ) + k1 = PER_TO_K(optInSlowPeriod); + else + { + optInSlowPeriod = 26; + k1 = (double)0.075; /* Fix 26 */ + } + + if( optInFastPeriod != 0 ) + k2 = PER_TO_K(optInFastPeriod); + else + { + optInFastPeriod = 12; + k2 = (double)0.15; /* Fix 12 */ + } + + lookbackSignal = LOOKBACK_CALL(EMA)( optInSignalPeriod_2 ); + + /* Move up the start index if there is not + * enough initial data. + */ + lookbackTotal = lookbackSignal; + lookbackTotal += LOOKBACK_CALL(EMA)( optInSlowPeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Allocate intermediate buffer for fast/slow EMA. */ + tempInteger = (endIdx-startIdx)+1+lookbackSignal; + ARRAY_ALLOC( fastEMABuffer, tempInteger ); + #if !defined( _JAVA ) + if( !fastEMABuffer ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + ARRAY_ALLOC( slowEMABuffer, tempInteger ); + #if !defined( _JAVA ) + if( !slowEMABuffer ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastEMABuffer ); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + /* Calculate the slow EMA. + * + * Move back the startIdx to get enough data + * for the signal period. That way, once the + * signal calculation is done, all the output + * will start at the requested 'startIdx'. + */ + tempInteger = startIdx-lookbackSignal; + retCode = FUNCTION_CALL(INT_EMA)( tempInteger, endIdx, + inReal, optInSlowPeriod, k1, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), slowEMABuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastEMABuffer ); + ARRAY_FREE( slowEMABuffer ); + return retCode; + } + + /* Calculate the fast EMA. */ + retCode = FUNCTION_CALL(INT_EMA)( tempInteger, endIdx, + inReal, optInFastPeriod, k2, + VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), fastEMABuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastEMABuffer ); + ARRAY_FREE( slowEMABuffer ); + return retCode; + } + + /* Parano tests. Will be removed eventually. */ + if( (VALUE_HANDLE_GET(outBegIdx1) != tempInteger) || + (VALUE_HANDLE_GET(outBegIdx2) != tempInteger) || + (VALUE_HANDLE_GET(outNbElement1) != VALUE_HANDLE_GET(outNbElement2)) || + (VALUE_HANDLE_GET(outNbElement1) != (endIdx-startIdx)+1+lookbackSignal) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastEMABuffer ); + ARRAY_FREE( slowEMABuffer ); + return TA_INTERNAL_ERROR(119); + } + + /* Calculate (fast EMA) - (slow EMA). */ + for( i=0; i < VALUE_HANDLE_GET(outNbElement1); i++ ) + fastEMABuffer[i] = fastEMABuffer[i] - slowEMABuffer[i]; + + + /* Copy the result into the output for the caller. */ + ARRAY_MEMMOVE( outMACD, 0, fastEMABuffer, lookbackSignal, (endIdx-startIdx)+1 ); + + /* Calculate the signal/trigger line. */ + retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(outNbElement1)-1, + fastEMABuffer, optInSignalPeriod_2, PER_TO_K(optInSignalPeriod_2), + VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), outMACDSignal ); + + + ARRAY_FREE( fastEMABuffer ); + ARRAY_FREE( slowEMABuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Calculate the histogram. */ + for( i=0; i < VALUE_HANDLE_GET(outNbElement2); i++ ) + outMACDHist[i] = outMACD[i]-outMACDSignal[i]; + + + /* All done! Indicate the output limits and return success. */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = VALUE_HANDLE_GET(outNbElement2); + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} +#endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Macd( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Macd( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode macd( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MACD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMACD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMACDSignal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMACDHist ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ return FUNCTION_CALL(INT_MACD)( startIdx, endIdx, inReal, +/* Generated */ optInFastPeriod, +/* Generated */ optInSlowPeriod, +/* Generated */ optInSignalPeriod, +/* Generated */ outBegIdx, +/* Generated */ outNBElement, +/* Generated */ outMACD, +/* Generated */ outMACDSignal, +/* Generated */ outMACDHist ); +/* Generated */ } +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ // No INT function +/* Generated */ #else +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TA_INT_MACD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ int optInSignalPeriod_2, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TA_INT_MACD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ int optInSignalPeriod_2, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ RetCode TA_INT_MACD( int startIdx, +/* Generated */ int endIdx, +/* Generated */ INPUT_TYPE inReal[], +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ int optInSignalPeriod_2, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_PREFIX(INT_MACD)( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const INPUT_TYPE inReal[], +/* Generated */ int optInFastPeriod, +/* Generated */ int optInSlowPeriod, +/* Generated */ int optInSignalPeriod_2, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(slowEMABuffer); +/* Generated */ ARRAY_REF(fastEMABuffer); +/* Generated */ double k1, k2; +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int tempInteger; +/* Generated */ VALUE_HANDLE_INT(outBegIdx1); +/* Generated */ VALUE_HANDLE_INT(outNbElement1); +/* Generated */ VALUE_HANDLE_INT(outBegIdx2); +/* Generated */ VALUE_HANDLE_INT(outNbElement2); +/* Generated */ int lookbackTotal, lookbackSignal; +/* Generated */ int i; +/* Generated */ if( optInSlowPeriod < optInFastPeriod ) +/* Generated */ { +/* Generated */ tempInteger = optInSlowPeriod; +/* Generated */ optInSlowPeriod = optInFastPeriod; +/* Generated */ optInFastPeriod = tempInteger; +/* Generated */ } +/* Generated */ if( optInSlowPeriod != 0 ) +/* Generated */ k1 = PER_TO_K(optInSlowPeriod); +/* Generated */ else +/* Generated */ { +/* Generated */ optInSlowPeriod = 26; +/* Generated */ k1 = (double)0.075; +/* Generated */ } +/* Generated */ if( optInFastPeriod != 0 ) +/* Generated */ k2 = PER_TO_K(optInFastPeriod); +/* Generated */ else +/* Generated */ { +/* Generated */ optInFastPeriod = 12; +/* Generated */ k2 = (double)0.15; +/* Generated */ } +/* Generated */ lookbackSignal = LOOKBACK_CALL(EMA)( optInSignalPeriod_2 ); +/* Generated */ lookbackTotal = lookbackSignal; +/* Generated */ lookbackTotal += LOOKBACK_CALL(EMA)( optInSlowPeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ tempInteger = (endIdx-startIdx)+1+lookbackSignal; +/* Generated */ ARRAY_ALLOC( fastEMABuffer, tempInteger ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !fastEMABuffer ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC( slowEMABuffer, tempInteger ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !slowEMABuffer ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastEMABuffer ); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ tempInteger = startIdx-lookbackSignal; +/* Generated */ retCode = FUNCTION_CALL(INT_EMA)( tempInteger, endIdx, +/* Generated */ inReal, optInSlowPeriod, k1, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), slowEMABuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastEMABuffer ); +/* Generated */ ARRAY_FREE( slowEMABuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL(INT_EMA)( tempInteger, endIdx, +/* Generated */ inReal, optInFastPeriod, k2, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), fastEMABuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastEMABuffer ); +/* Generated */ ARRAY_FREE( slowEMABuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ if( (VALUE_HANDLE_GET(outBegIdx1) != tempInteger) || +/* Generated */ (VALUE_HANDLE_GET(outBegIdx2) != tempInteger) || +/* Generated */ (VALUE_HANDLE_GET(outNbElement1) != VALUE_HANDLE_GET(outNbElement2)) || +/* Generated */ (VALUE_HANDLE_GET(outNbElement1) != (endIdx-startIdx)+1+lookbackSignal) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastEMABuffer ); +/* Generated */ ARRAY_FREE( slowEMABuffer ); +/* Generated */ return TA_INTERNAL_ERROR(119); +/* Generated */ } +/* Generated */ for( i=0; i < VALUE_HANDLE_GET(outNbElement1); i++ ) +/* Generated */ fastEMABuffer[i] = fastEMABuffer[i] - slowEMABuffer[i]; +/* Generated */ ARRAY_MEMMOVE( outMACD, 0, fastEMABuffer, lookbackSignal, (endIdx-startIdx)+1 ); +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(outNbElement1)-1, +/* Generated */ fastEMABuffer, optInSignalPeriod_2, PER_TO_K(optInSignalPeriod_2), +/* Generated */ VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), outMACDSignal ); +/* Generated */ ARRAY_FREE( fastEMABuffer ); +/* Generated */ ARRAY_FREE( slowEMABuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ for( i=0; i < VALUE_HANDLE_GET(outNbElement2); i++ ) +/* Generated */ outMACDHist[i] = outMACD[i]-outMACDSignal[i]; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = VALUE_HANDLE_GET(outNbElement2); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ #endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MACDEXT.c b/talib/ta_func/ta_MACDEXT.c new file mode 100644 index 0000000..9f188a8 --- /dev/null +++ b/talib/ta_func/ta_MACDEXT.c @@ -0,0 +1,719 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MacdExtLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int macdExtLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MACDEXT_Lookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSignalMAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int tempInteger, lookbackLargest; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastMAType < 0) || ((int)optInFastMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowMAType < 0) || ((int)optInSlowMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSignalPeriod. */ +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSignalMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSignalMAType < 0) || ((int)optInSignalMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Find the MA with the largest lookback */ + lookbackLargest = LOOKBACK_CALL(MA)( optInFastPeriod, optInFastMAType ); + tempInteger = LOOKBACK_CALL(MA)( optInSlowPeriod, optInSlowMAType ); + if( tempInteger > lookbackLargest ) + lookbackLargest = tempInteger; + + /* Add to the largest MA lookback the signal line lookback */ + return lookbackLargest + LOOKBACK_CALL(MA)( optInSignalPeriod, optInSignalMAType ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MACDEXT - MACD with controllable MA type + * + * Input = double + * Output = double, double, double + * + * Optional Parameters + * ------------------- + * optInFastPeriod:(From 2 to 100000) + * Number of period for the fast MA + * + * optInFastMAType: + * Type of Moving Average for fast MA + * + * optInSlowPeriod:(From 2 to 100000) + * Number of period for the slow MA + * + * optInSlowMAType: + * Type of Moving Average for slow MA + * + * optInSignalPeriod:(From 1 to 100000) + * Smoothing for the signal line (nb of period) + * + * optInSignalMAType: + * Type of Moving Average for signal line + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MacdExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MacdExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode macdExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MACDEXT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSignalMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ARRAY_REF( slowMABuffer ); + ARRAY_REF( fastMABuffer ); + ENUM_DECLARATION(RetCode) retCode; + int tempInteger; + VALUE_HANDLE_INT(outBegIdx1); + VALUE_HANDLE_INT(outNbElement1); + VALUE_HANDLE_INT(outBegIdx2); + VALUE_HANDLE_INT(outNbElement2); + int lookbackTotal, lookbackSignal, lookbackLargest; + int i; + ENUM_DECLARATION(MAType) tempMAType; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastMAType < 0) || ((int)optInFastMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowMAType < 0) || ((int)optInSlowMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSignalPeriod. */ +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSignalMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSignalMAType < 0) || ((int)optInSignalMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMACD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMACDSignal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMACDHist ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Make sure slow is really slower than + * the fast period! if not, swap... + */ + if( optInSlowPeriod < optInFastPeriod ) + { + /* swap period */ + tempInteger = optInSlowPeriod; + optInSlowPeriod = optInFastPeriod; + optInFastPeriod = tempInteger; + /* swap type */ + tempMAType = optInSlowMAType; + optInSlowMAType = optInFastMAType; + optInFastMAType = tempMAType; + } + + /* Find the MA with the largest lookback */ + lookbackLargest = LOOKBACK_CALL(MA)( optInFastPeriod, optInFastMAType ); + tempInteger = LOOKBACK_CALL(MA)( optInSlowPeriod, optInSlowMAType ); + if( tempInteger > lookbackLargest ) + lookbackLargest = tempInteger; + + /* Add the lookback needed for the signal line */ + lookbackSignal = LOOKBACK_CALL(MA)( optInSignalPeriod, optInSignalMAType ); + lookbackTotal = lookbackSignal+lookbackLargest; + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Allocate intermediate buffer for fast/slow MA. */ + tempInteger = (endIdx-startIdx)+1+lookbackSignal; + ARRAY_ALLOC( fastMABuffer, tempInteger ); + #if !defined( _JAVA ) + if( !fastMABuffer ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + ARRAY_ALLOC( slowMABuffer, tempInteger ); + #if !defined( _JAVA ) + if( !slowMABuffer ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastMABuffer ); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + /* Calculate the slow MA. + * + * Move back the startIdx to get enough data + * for the signal period. That way, once the + * signal calculation is done, all the output + * will start at the requested 'startIdx'. + */ + tempInteger = startIdx-lookbackSignal; + retCode = FUNCTION_CALL(MA)( tempInteger, endIdx, + inReal, optInSlowPeriod, optInSlowMAType, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), + slowMABuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastMABuffer ); + ARRAY_FREE( slowMABuffer ); + return retCode; + } + + /* Calculate the fast MA. */ + retCode = FUNCTION_CALL(MA)( tempInteger, endIdx, + inReal, optInFastPeriod, optInFastMAType, + VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), + fastMABuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastMABuffer ); + ARRAY_FREE( slowMABuffer ); + return retCode; + } + + /* Parano tests. Will be removed eventually. */ + if( (VALUE_HANDLE_GET(outBegIdx1) != tempInteger) || + (VALUE_HANDLE_GET(outBegIdx2) != tempInteger) || + (VALUE_HANDLE_GET(outNbElement1) != VALUE_HANDLE_GET(outNbElement2)) || + (VALUE_HANDLE_GET(outNbElement1) != (endIdx-startIdx)+1+lookbackSignal) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + ARRAY_FREE( fastMABuffer ); + ARRAY_FREE( slowMABuffer ); + return TA_INTERNAL_ERROR(119); + } + + /* Calculate (fast MA) - (slow MA). */ + for( i=0; i < VALUE_HANDLE_GET(outNbElement1); i++ ) + fastMABuffer[i] = fastMABuffer[i] - slowMABuffer[i]; + + /* Copy the result into the output for the caller. */ + ARRAY_MEMMOVE( outMACD, 0, fastMABuffer, lookbackSignal, (endIdx-startIdx)+1 ); + + /* Calculate the signal/trigger line. */ + retCode = FUNCTION_CALL_DOUBLE(MA)( 0, VALUE_HANDLE_GET(outNbElement1)-1, + fastMABuffer, optInSignalPeriod, optInSignalMAType, + VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), outMACDSignal ); + + ARRAY_FREE( fastMABuffer ); + ARRAY_FREE( slowMABuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Calculate the histogram. */ + for( i=0; i < VALUE_HANDLE_GET(outNbElement2); i++ ) + outMACDHist[i] = outMACD[i]-outMACDSignal[i]; + + /* All done! Indicate the output limits and return success. */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = VALUE_HANDLE_GET(outNbElement2); + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MacdExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MacdExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode macdExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MAType optInSignalMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MACDEXT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInFastMAType, +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInSlowMAType, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSignalMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF( slowMABuffer ); +/* Generated */ ARRAY_REF( fastMABuffer ); +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int tempInteger; +/* Generated */ VALUE_HANDLE_INT(outBegIdx1); +/* Generated */ VALUE_HANDLE_INT(outNbElement1); +/* Generated */ VALUE_HANDLE_INT(outBegIdx2); +/* Generated */ VALUE_HANDLE_INT(outNbElement2); +/* Generated */ int lookbackTotal, lookbackSignal, lookbackLargest; +/* Generated */ int i; +/* Generated */ ENUM_DECLARATION(MAType) tempMAType; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastMAType < 0) || ((int)optInFastMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowMAType < 0) || ((int)optInSlowMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSignalMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSignalMAType < 0) || ((int)optInSignalMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMACD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMACDSignal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMACDHist ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( optInSlowPeriod < optInFastPeriod ) +/* Generated */ { +/* Generated */ tempInteger = optInSlowPeriod; +/* Generated */ optInSlowPeriod = optInFastPeriod; +/* Generated */ optInFastPeriod = tempInteger; +/* Generated */ tempMAType = optInSlowMAType; +/* Generated */ optInSlowMAType = optInFastMAType; +/* Generated */ optInFastMAType = tempMAType; +/* Generated */ } +/* Generated */ lookbackLargest = LOOKBACK_CALL(MA)( optInFastPeriod, optInFastMAType ); +/* Generated */ tempInteger = LOOKBACK_CALL(MA)( optInSlowPeriod, optInSlowMAType ); +/* Generated */ if( tempInteger > lookbackLargest ) +/* Generated */ lookbackLargest = tempInteger; +/* Generated */ lookbackSignal = LOOKBACK_CALL(MA)( optInSignalPeriod, optInSignalMAType ); +/* Generated */ lookbackTotal = lookbackSignal+lookbackLargest; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ tempInteger = (endIdx-startIdx)+1+lookbackSignal; +/* Generated */ ARRAY_ALLOC( fastMABuffer, tempInteger ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !fastMABuffer ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC( slowMABuffer, tempInteger ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !slowMABuffer ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastMABuffer ); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ tempInteger = startIdx-lookbackSignal; +/* Generated */ retCode = FUNCTION_CALL(MA)( tempInteger, endIdx, +/* Generated */ inReal, optInSlowPeriod, optInSlowMAType, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ slowMABuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastMABuffer ); +/* Generated */ ARRAY_FREE( slowMABuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL(MA)( tempInteger, endIdx, +/* Generated */ inReal, optInFastPeriod, optInFastMAType, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), +/* Generated */ fastMABuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastMABuffer ); +/* Generated */ ARRAY_FREE( slowMABuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ if( (VALUE_HANDLE_GET(outBegIdx1) != tempInteger) || +/* Generated */ (VALUE_HANDLE_GET(outBegIdx2) != tempInteger) || +/* Generated */ (VALUE_HANDLE_GET(outNbElement1) != VALUE_HANDLE_GET(outNbElement2)) || +/* Generated */ (VALUE_HANDLE_GET(outNbElement1) != (endIdx-startIdx)+1+lookbackSignal) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ ARRAY_FREE( fastMABuffer ); +/* Generated */ ARRAY_FREE( slowMABuffer ); +/* Generated */ return TA_INTERNAL_ERROR(119); +/* Generated */ } +/* Generated */ for( i=0; i < VALUE_HANDLE_GET(outNbElement1); i++ ) +/* Generated */ fastMABuffer[i] = fastMABuffer[i] - slowMABuffer[i]; +/* Generated */ ARRAY_MEMMOVE( outMACD, 0, fastMABuffer, lookbackSignal, (endIdx-startIdx)+1 ); +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(MA)( 0, VALUE_HANDLE_GET(outNbElement1)-1, +/* Generated */ fastMABuffer, optInSignalPeriod, optInSignalMAType, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx2), VALUE_HANDLE_OUT(outNbElement2), outMACDSignal ); +/* Generated */ ARRAY_FREE( fastMABuffer ); +/* Generated */ ARRAY_FREE( slowMABuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ for( i=0; i < VALUE_HANDLE_GET(outNbElement2); i++ ) +/* Generated */ outMACDHist[i] = outMACD[i]-outMACDSignal[i]; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = VALUE_HANDLE_GET(outNbElement2); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MACDFIX.c b/talib/ta_func/ta_MACDFIX.c new file mode 100644 index 0000000..9c11f22 --- /dev/null +++ b/talib/ta_func/ta_MACDFIX.c @@ -0,0 +1,312 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MacdFixLookback( int optInSignalPeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int macdFixLookback( int optInSignalPeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MACDFIX_Lookback( int optInSignalPeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInSignalPeriod. */ +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* The lookback is driven by the signal line output. + * + * (must also account for the initial data consume + * by the fix 26 period EMA). + */ + return LOOKBACK_CALL(EMA)( 26 ) + + LOOKBACK_CALL(EMA)( optInSignalPeriod ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MACDFIX - Moving Average Convergence/Divergence Fix 12/26 + * + * Input = double + * Output = double, double, double + * + * Optional Parameters + * ------------------- + * optInSignalPeriod:(From 1 to 100000) + * Smoothing for the signal line (nb of period) + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MacdFix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MacdFix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode macdFix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MACDFIX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSignalPeriod. */ +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMACD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMACDSignal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMACDHist ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + return FUNCTION_CALL(INT_MACD)( startIdx, endIdx, inReal, + 0, /* 0 indicate fix 12 == 0.15 for optInFastPeriod */ + 0, /* 0 indicate fix 26 == 0.075 for optInSlowPeriod */ + optInSignalPeriod, + outBegIdx, + outNBElement, + outMACD, + outMACDSignal, + outMACDHist ); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MacdFix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMACD, +/* Generated */ SubArray^ outMACDSignal, +/* Generated */ SubArray^ outMACDHist ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MacdFix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMACD, +/* Generated */ cli::array^ outMACDSignal, +/* Generated */ cli::array^ outMACDHist ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode macdFix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MACDFIX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInSignalPeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMACD[], +/* Generated */ double outMACDSignal[], +/* Generated */ double outMACDHist[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInSignalPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSignalPeriod = 9; +/* Generated */ else if( ((int)optInSignalPeriod < 1) || ((int)optInSignalPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMACD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMACDSignal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMACDHist ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ return FUNCTION_CALL(INT_MACD)( startIdx, endIdx, inReal, +/* Generated */ 0, +/* Generated */ 0, +/* Generated */ optInSignalPeriod, +/* Generated */ outBegIdx, +/* Generated */ outNBElement, +/* Generated */ outMACD, +/* Generated */ outMACDSignal, +/* Generated */ outMACDHist ); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MAMA.c b/talib/ta_func/ta_MAMA.c new file mode 100644 index 0000000..b42065d --- /dev/null +++ b/talib/ta_func/ta_MAMA.c @@ -0,0 +1,725 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 023003 MF Initial Coding of MAMA. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MamaLookback( double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit ) /* From 0.01 to 0.99 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int mamaLookback( double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit ) /* From 0.01 to 0.99 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MAMA_Lookback( double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit ) /* From 0.01 to 0.99 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInFastLimit == TA_REAL_DEFAULT ) +/* Generated */ optInFastLimit = 5.000000e-1; +/* Generated */ else if( (optInFastLimit < 1.000000e-2) ||/* Generated */ (optInFastLimit > 9.900000e-1) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInSlowLimit == TA_REAL_DEFAULT ) +/* Generated */ optInSlowLimit = 5.000000e-2; +/* Generated */ else if( (optInSlowLimit < 1.000000e-2) ||/* Generated */ (optInSlowLimit > 9.900000e-1) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* The two parameters are not a factor to determine + * the lookback, but are still requested for + * consistency with all other Lookback functions. + */ + UNUSED_VARIABLE(optInFastLimit); + UNUSED_VARIABLE(optInSlowLimit); + + /* Lookback is a fix amount + the unstable period. + * + * + * The fix lookback is 32 and is establish as follow: + * + * 12 price bar to be compatible with the implementation + * of TradeStation found in John Ehlers book. + * 6 price bars for the Detrender + * 6 price bars for Q1 + * 3 price bars for jI + * 3 price bars for jQ + * 1 price bar for Re/Im + * 1 price bar for the Delta Phase + * ------- + * 32 Total + */ + + return 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MAMA,Mama); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MAMA - MESA Adaptive Moving Average + * + * Input = double + * Output = double, double + * + * Optional Parameters + * ------------------- + * optInFastLimit:(From 0.01 to 0.99) + * Upper limit use in the adaptive algorithm + * + * optInSlowLimit:(From 0.01 to 0.99) + * Lower limit use in the adaptive algorithm + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMAMA, +/* Generated */ SubArray^ outFAMA ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMAMA, +/* Generated */ cli::array^ outFAMA ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMAMA[], +/* Generated */ double outFAMA[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MAMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMAMA[], +/* Generated */ double outFAMA[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int outIdx, i; + int lookbackTotal, today; + double tempReal, tempReal2; + + double adjustedPrevPeriod, period; + + /* Variable used for the price smoother (a weighted moving average). */ + int trailingWMAIdx; + double periodWMASum, periodWMASub, trailingWMAValue; + double smoothedValue; + + /* Variables used for the Hilbert Transormation */ + CONSTANT_DOUBLE(a) = 0.0962; + CONSTANT_DOUBLE(b) = 0.5769; + double hilbertTempReal; + int hilbertIdx; + + HILBERT_VARIABLES( detrender ); + HILBERT_VARIABLES( Q1 ); + HILBERT_VARIABLES( jI ); + HILBERT_VARIABLES( jQ ); + + double Q2, I2, prevQ2, prevI2, Re, Im; + + double I1ForOddPrev2, I1ForOddPrev3; + double I1ForEvenPrev2, I1ForEvenPrev3; + + double rad2Deg; + + double mama,fama,todayValue,prevPhase; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInFastLimit == TA_REAL_DEFAULT ) +/* Generated */ optInFastLimit = 5.000000e-1; +/* Generated */ else if( (optInFastLimit < 1.000000e-2) ||/* Generated */ (optInFastLimit > 9.900000e-1) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInSlowLimit == TA_REAL_DEFAULT ) +/* Generated */ optInSlowLimit = 5.000000e-2; +/* Generated */ else if( (optInSlowLimit < 1.000000e-2) ||/* Generated */ (optInSlowLimit > 9.900000e-1) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMAMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outFAMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Constant */ + rad2Deg = 180.0 / (4.0 * std_atan(1)); + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MAMA,Mama); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + /* Initialize the price smoother, which is simply a weighted + * moving average of the price. + * To understand this algorithm, I strongly suggest to understand + * first how TA_WMA is done. + */ + trailingWMAIdx = startIdx - lookbackTotal; + today = trailingWMAIdx; + + /* Initialization is same as WMA, except loop is unrolled + * for speed optimization. + */ + tempReal = inReal[today++]; + periodWMASub = tempReal; + periodWMASum = tempReal; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*2.0; + tempReal = inReal[today++]; + periodWMASub += tempReal; + periodWMASum += tempReal*3.0; + + trailingWMAValue = 0.0; + + /* Subsequent WMA value are evaluated by using + * the DO_PRICE_WMA macro. + */ + #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ + periodWMASub += varNewPrice; \ + periodWMASub -= trailingWMAValue; \ + periodWMASum += varNewPrice*4.0; \ + trailingWMAValue = inReal[trailingWMAIdx++]; \ + varToStoreSmoothedValue = periodWMASum*0.1; \ + periodWMASum -= periodWMASub; \ + } + + i = 9; + do + { + tempReal = inReal[today++]; + DO_PRICE_WMA(tempReal,smoothedValue); + } while( --i != 0); + + /* Initialize the circular buffers used by the hilbert + * transform logic. + * A buffer is used for odd day and another for even days. + * This minimize the number of memory access and floating point + * operations needed (note also that by using static circular buffer, + * no large dynamic memory allocation is needed for storing + * intermediate calculation!). + */ + hilbertIdx = 0; + + INIT_HILBERT_VARIABLES(detrender); + INIT_HILBERT_VARIABLES(Q1); + INIT_HILBERT_VARIABLES(jI); + INIT_HILBERT_VARIABLES(jQ); + + period = 0.0; + outIdx = 0; + + prevI2 = prevQ2 = 0.0; + Re = Im = 0.0; + mama = fama = 0.0; + I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; + I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; + + prevPhase = 0.0; + + /* The code is speed optimized and is most likely very + * hard to follow if you do not already know well the + * original algorithm. + * To understadn better, it is strongly suggested to look + * first at the Excel implementation in "test_MAMA.xls" included + * in this package. + */ + while( today <= endIdx ) + { + adjustedPrevPeriod = (0.075*period)+0.54; + + todayValue = inReal[today]; + DO_PRICE_WMA(todayValue,smoothedValue); + + if( (today%2) == 0 ) + { + /* Do the Hilbert Transforms for even price bar */ + DO_HILBERT_EVEN(detrender,smoothedValue); + DO_HILBERT_EVEN(Q1,detrender); + DO_HILBERT_EVEN(jI,I1ForEvenPrev3); + DO_HILBERT_EVEN(jQ,Q1); + if( ++hilbertIdx == 3 ) + hilbertIdx = 0; + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); + + /* The variable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForOddPrev3 = I1ForOddPrev2; + I1ForOddPrev2 = detrender; + + /* Put Alpha in tempReal2 */ + if( I1ForEvenPrev3 != 0.0 ) + tempReal2 = (std_atan(Q1/I1ForEvenPrev3)*rad2Deg); + else + tempReal2 = 0.0; + } + else + { + /* Do the Hilbert Transforms for odd price bar */ + DO_HILBERT_ODD(detrender,smoothedValue); + DO_HILBERT_ODD(Q1,detrender); + DO_HILBERT_ODD(jI,I1ForOddPrev3); + DO_HILBERT_ODD(jQ,Q1); + + Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); + I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); + + /* The varaiable I1 is the detrender delayed for + * 3 price bars. + * + * Save the current detrender value for being + * used by the "odd" logic later. + */ + I1ForEvenPrev3 = I1ForEvenPrev2; + I1ForEvenPrev2 = detrender; + + /* Put Alpha in tempReal2 */ + if( I1ForOddPrev3 != 0.0 ) + tempReal2 = (std_atan(Q1/I1ForOddPrev3)*rad2Deg); + else + tempReal2 = 0.0; + } + + /* Put Delta Phase into tempReal */ + tempReal = prevPhase - tempReal2; + prevPhase = tempReal2; + if( tempReal < 1.0 ) + tempReal = 1.0; + + /* Put Alpha into tempReal */ + if( tempReal > 1.0 ) + { + tempReal = optInFastLimit/tempReal; + if( tempReal < optInSlowLimit ) + tempReal = optInSlowLimit; + } + else + { + tempReal = optInFastLimit; + } + + /* Calculate MAMA, FAMA */ + mama = (tempReal*todayValue)+((1-tempReal)*mama); + tempReal *= 0.5; + fama = (tempReal*mama)+((1-tempReal)*fama); + if( today >= startIdx ) + { + outMAMA[outIdx] = mama; + outFAMA[outIdx++] = fama; + } + + /* Adjust the period for next price bar */ + Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); + Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); + prevQ2 = Q2; + prevI2 = I2; + tempReal = period; + if( (Im != 0.0) && (Re != 0.0) ) + period = 360.0 / (std_atan(Im/Re)*rad2Deg); + tempReal2 = 1.5*tempReal; + if( period > tempReal2) + period = tempReal2; + tempReal2 = 0.67*tempReal; + if( period < tempReal2 ) + period = tempReal2; + if( period < 6 ) + period = 6; + else if( period > 50 ) + period = 50; + period = (0.2*period) + (0.8 * tempReal); + + /* Ooof... let's do the next price bar now! */ + today++; + } + + /* Default return values */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMAMA, +/* Generated */ SubArray^ outFAMA ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMAMA, +/* Generated */ cli::array^ outFAMA ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mama( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMAMA[], +/* Generated */ double outFAMA[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MAMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ double optInFastLimit, /* From 0.01 to 0.99 */ +/* Generated */ double optInSlowLimit, /* From 0.01 to 0.99 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMAMA[], +/* Generated */ double outFAMA[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ int lookbackTotal, today; +/* Generated */ double tempReal, tempReal2; +/* Generated */ double adjustedPrevPeriod, period; +/* Generated */ int trailingWMAIdx; +/* Generated */ double periodWMASum, periodWMASub, trailingWMAValue; +/* Generated */ double smoothedValue; +/* Generated */ CONSTANT_DOUBLE(a) = 0.0962; +/* Generated */ CONSTANT_DOUBLE(b) = 0.5769; +/* Generated */ double hilbertTempReal; +/* Generated */ int hilbertIdx; +/* Generated */ HILBERT_VARIABLES( detrender ); +/* Generated */ HILBERT_VARIABLES( Q1 ); +/* Generated */ HILBERT_VARIABLES( jI ); +/* Generated */ HILBERT_VARIABLES( jQ ); +/* Generated */ double Q2, I2, prevQ2, prevI2, Re, Im; +/* Generated */ double I1ForOddPrev2, I1ForOddPrev3; +/* Generated */ double I1ForEvenPrev2, I1ForEvenPrev3; +/* Generated */ double rad2Deg; +/* Generated */ double mama,fama,todayValue,prevPhase; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInFastLimit == TA_REAL_DEFAULT ) +/* Generated */ optInFastLimit = 5.000000e-1; +/* Generated */ else if( (optInFastLimit < 1.000000e-2) || (optInFastLimit > 9.900000e-1) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInSlowLimit == TA_REAL_DEFAULT ) +/* Generated */ optInSlowLimit = 5.000000e-2; +/* Generated */ else if( (optInSlowLimit < 1.000000e-2) || (optInSlowLimit > 9.900000e-1) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMAMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outFAMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ rad2Deg = 180.0 / (4.0 * std_atan(1)); +/* Generated */ lookbackTotal = 32 + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MAMA,Mama); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ trailingWMAIdx = startIdx - lookbackTotal; +/* Generated */ today = trailingWMAIdx; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub = tempReal; +/* Generated */ periodWMASum = tempReal; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*2.0; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ periodWMASub += tempReal; +/* Generated */ periodWMASum += tempReal*3.0; +/* Generated */ trailingWMAValue = 0.0; +/* Generated */ #define DO_PRICE_WMA(varNewPrice,varToStoreSmoothedValue) { \ +/* Generated */ periodWMASub += varNewPrice; \ +/* Generated */ periodWMASub -= trailingWMAValue; \ +/* Generated */ periodWMASum += varNewPrice*4.0; \ +/* Generated */ trailingWMAValue = inReal[trailingWMAIdx++]; \ +/* Generated */ varToStoreSmoothedValue = periodWMASum*0.1; \ +/* Generated */ periodWMASum -= periodWMASub; \ +/* Generated */ } +/* Generated */ i = 9; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[today++]; +/* Generated */ DO_PRICE_WMA(tempReal,smoothedValue); +/* Generated */ } while( --i != 0); +/* Generated */ hilbertIdx = 0; +/* Generated */ INIT_HILBERT_VARIABLES(detrender); +/* Generated */ INIT_HILBERT_VARIABLES(Q1); +/* Generated */ INIT_HILBERT_VARIABLES(jI); +/* Generated */ INIT_HILBERT_VARIABLES(jQ); +/* Generated */ period = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ prevI2 = prevQ2 = 0.0; +/* Generated */ Re = Im = 0.0; +/* Generated */ mama = fama = 0.0; +/* Generated */ I1ForOddPrev3 = I1ForEvenPrev3 = 0.0; +/* Generated */ I1ForOddPrev2 = I1ForEvenPrev2 = 0.0; +/* Generated */ prevPhase = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ adjustedPrevPeriod = (0.075*period)+0.54; +/* Generated */ todayValue = inReal[today]; +/* Generated */ DO_PRICE_WMA(todayValue,smoothedValue); +/* Generated */ if( (today%2) == 0 ) +/* Generated */ { +/* Generated */ DO_HILBERT_EVEN(detrender,smoothedValue); +/* Generated */ DO_HILBERT_EVEN(Q1,detrender); +/* Generated */ DO_HILBERT_EVEN(jI,I1ForEvenPrev3); +/* Generated */ DO_HILBERT_EVEN(jQ,Q1); +/* Generated */ if( ++hilbertIdx == 3 ) +/* Generated */ hilbertIdx = 0; +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForEvenPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForOddPrev3 = I1ForOddPrev2; +/* Generated */ I1ForOddPrev2 = detrender; +/* Generated */ if( I1ForEvenPrev3 != 0.0 ) +/* Generated */ tempReal2 = (std_atan(Q1/I1ForEvenPrev3)*rad2Deg); +/* Generated */ else +/* Generated */ tempReal2 = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ DO_HILBERT_ODD(detrender,smoothedValue); +/* Generated */ DO_HILBERT_ODD(Q1,detrender); +/* Generated */ DO_HILBERT_ODD(jI,I1ForOddPrev3); +/* Generated */ DO_HILBERT_ODD(jQ,Q1); +/* Generated */ Q2 = (0.2*(Q1 + jI)) + (0.8*prevQ2); +/* Generated */ I2 = (0.2*(I1ForOddPrev3 - jQ)) + (0.8*prevI2); +/* Generated */ I1ForEvenPrev3 = I1ForEvenPrev2; +/* Generated */ I1ForEvenPrev2 = detrender; +/* Generated */ if( I1ForOddPrev3 != 0.0 ) +/* Generated */ tempReal2 = (std_atan(Q1/I1ForOddPrev3)*rad2Deg); +/* Generated */ else +/* Generated */ tempReal2 = 0.0; +/* Generated */ } +/* Generated */ tempReal = prevPhase - tempReal2; +/* Generated */ prevPhase = tempReal2; +/* Generated */ if( tempReal < 1.0 ) +/* Generated */ tempReal = 1.0; +/* Generated */ if( tempReal > 1.0 ) +/* Generated */ { +/* Generated */ tempReal = optInFastLimit/tempReal; +/* Generated */ if( tempReal < optInSlowLimit ) +/* Generated */ tempReal = optInSlowLimit; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ tempReal = optInFastLimit; +/* Generated */ } +/* Generated */ mama = (tempReal*todayValue)+((1-tempReal)*mama); +/* Generated */ tempReal *= 0.5; +/* Generated */ fama = (tempReal*mama)+((1-tempReal)*fama); +/* Generated */ if( today >= startIdx ) +/* Generated */ { +/* Generated */ outMAMA[outIdx] = mama; +/* Generated */ outFAMA[outIdx++] = fama; +/* Generated */ } +/* Generated */ Re = (0.2*((I2*prevI2)+(Q2*prevQ2)))+(0.8*Re); +/* Generated */ Im = (0.2*((I2*prevQ2)-(Q2*prevI2)))+(0.8*Im); +/* Generated */ prevQ2 = Q2; +/* Generated */ prevI2 = I2; +/* Generated */ tempReal = period; +/* Generated */ if( (Im != 0.0) && (Re != 0.0) ) +/* Generated */ period = 360.0 / (std_atan(Im/Re)*rad2Deg); +/* Generated */ tempReal2 = 1.5*tempReal; +/* Generated */ if( period > tempReal2) +/* Generated */ period = tempReal2; +/* Generated */ tempReal2 = 0.67*tempReal; +/* Generated */ if( period < tempReal2 ) +/* Generated */ period = tempReal2; +/* Generated */ if( period < 6 ) +/* Generated */ period = 6; +/* Generated */ else if( period > 50 ) +/* Generated */ period = 50; +/* Generated */ period = (0.2*period) + (0.8 * tempReal); +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MAVP.c b/talib/ta_func/ta_MAVP.c new file mode 100644 index 0000000..1f85e5d --- /dev/null +++ b/talib/ta_func/ta_MAVP.c @@ -0,0 +1,504 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 021807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MovingAverageVariablePeriodLookback( int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int movingAverageVariablePeriodLookback( int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MAVP_Lookback( int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInMinPeriod. */ +/* Generated */ if( (int)optInMinPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInMinPeriod = 2; +/* Generated */ else if( ((int)optInMinPeriod < 2) || ((int)optInMinPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInMaxPeriod. */ +/* Generated */ if( (int)optInMaxPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInMaxPeriod = 30; +/* Generated */ else if( ((int)optInMaxPeriod < 2) || ((int)optInMaxPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + return LOOKBACK_CALL(MA)(optInMaxPeriod, optInMAType); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MAVP - Moving average with variable period + * + * Input = double, double + * Output = double + * + * Optional Parameters + * ------------------- + * optInMinPeriod:(From 2 to 100000) + * Value less than minimum will be changed to Minimum period + * + * optInMaxPeriod:(From 2 to 100000) + * Value higher than maximum will be changed to Maximum period + * + * optInMAType: + * Type of Moving Average + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ SubArray^ inPeriods, +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ cli::array^ inPeriods, +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode movingAverageVariablePeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ double inPeriods[], +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MAVP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ const double inPeriods[], +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int i, j, lookbackTotal, outputSize, tempInt, curPeriod; + ARRAY_INT_REF(localPeriodArray); + ARRAY_REF(localOutputArray); + VALUE_HANDLE_INT(localBegIdx); + VALUE_HANDLE_INT(localNbElement); + ENUM_DECLARATION(RetCode) retCode; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inPeriods ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInMinPeriod. */ +/* Generated */ if( (int)optInMinPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInMinPeriod = 2; +/* Generated */ else if( ((int)optInMinPeriod < 2) || ((int)optInMinPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInMaxPeriod. */ +/* Generated */ if( (int)optInMaxPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInMaxPeriod = 30; +/* Generated */ else if( ((int)optInMaxPeriod < 2) || ((int)optInMaxPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = LOOKBACK_CALL(MA)(optInMaxPeriod,optInMAType); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate exact output size */ + if( lookbackTotal > startIdx ) + tempInt = lookbackTotal; + else + tempInt = startIdx; + if( tempInt > endIdx ) + { + /* No output */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + outputSize = endIdx - tempInt + 1; + + /* Allocate intermediate local buffer. */ + ARRAY_ALLOC(localOutputArray,outputSize); + ARRAY_INT_ALLOC(localPeriodArray,outputSize); + + /* Copy caller array of period into local buffer. + * At the same time, truncate to min/max. + */ + for( i=0; i < outputSize; i++ ) + { + tempInt = (int)(inPeriods[startIdx+i]); + if( tempInt < optInMinPeriod ) + tempInt = optInMinPeriod; + else if( tempInt > optInMaxPeriod ) + tempInt = optInMaxPeriod; + localPeriodArray[i] = tempInt; + } + + /* Process each element of the input. + * For each possible period value, the MA is calculated + * only once. + * The outReal is then fill up for all element with + * the same period. + * A local flag (value 0) is set in localPeriodArray + * to avoid doing a second time the same calculation. + */ + for( i=0; i < outputSize; i++ ) + { + curPeriod = localPeriodArray[i]; + if( curPeriod != 0 ) + { + /* TODO: This portion of the function can be slightly speed + * optimized by making the function without unstable period + * start their calculation at 'startIdx+i' instead of startIdx. + */ + + /* Calculation of the MA required. */ + retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal, + curPeriod, optInMAType, + VALUE_HANDLE_OUT(localBegIdx),VALUE_HANDLE_OUT(localNbElement),localOutputArray ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + ARRAY_FREE(localOutputArray); + ARRAY_INT_FREE(localPeriodArray); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + outReal[i] = localOutputArray[i]; + for( j=i+1; j < outputSize; j++ ) + { + if( localPeriodArray[j] == curPeriod ) + { + localPeriodArray[j] = 0; /* Flag to avoid recalculation */ + outReal[j] = localOutputArray[j]; + } + } + } + } + + ARRAY_FREE(localOutputArray); + ARRAY_INT_FREE(localPeriodArray); + + /* Done. Inform the caller of the success. */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outputSize; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ SubArray^ inPeriods, +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MovingAverageVariablePeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ cli::array^ inPeriods, +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode movingAverageVariablePeriod( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ float inPeriods[], +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MAVP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ const float inPeriods[], +/* Generated */ int optInMinPeriod, /* From 2 to 100000 */ +/* Generated */ int optInMaxPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i, j, lookbackTotal, outputSize, tempInt, curPeriod; +/* Generated */ ARRAY_INT_REF(localPeriodArray); +/* Generated */ ARRAY_REF(localOutputArray); +/* Generated */ VALUE_HANDLE_INT(localBegIdx); +/* Generated */ VALUE_HANDLE_INT(localNbElement); +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inPeriods ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInMinPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInMinPeriod = 2; +/* Generated */ else if( ((int)optInMinPeriod < 2) || ((int)optInMinPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInMaxPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInMaxPeriod = 30; +/* Generated */ else if( ((int)optInMaxPeriod < 2) || ((int)optInMaxPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(MA)(optInMaxPeriod,optInMAType); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ if( lookbackTotal > startIdx ) +/* Generated */ tempInt = lookbackTotal; +/* Generated */ else +/* Generated */ tempInt = startIdx; +/* Generated */ if( tempInt > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outputSize = endIdx - tempInt + 1; +/* Generated */ ARRAY_ALLOC(localOutputArray,outputSize); +/* Generated */ ARRAY_INT_ALLOC(localPeriodArray,outputSize); +/* Generated */ for( i=0; i < outputSize; i++ ) +/* Generated */ { +/* Generated */ tempInt = (int)(inPeriods[startIdx+i]); +/* Generated */ if( tempInt < optInMinPeriod ) +/* Generated */ tempInt = optInMinPeriod; +/* Generated */ else if( tempInt > optInMaxPeriod ) +/* Generated */ tempInt = optInMaxPeriod; +/* Generated */ localPeriodArray[i] = tempInt; +/* Generated */ } +/* Generated */ for( i=0; i < outputSize; i++ ) +/* Generated */ { +/* Generated */ curPeriod = localPeriodArray[i]; +/* Generated */ if( curPeriod != 0 ) +/* Generated */ { +/* Generated */ retCode = FUNCTION_CALL(MA)( startIdx, endIdx, inReal, +/* Generated */ curPeriod, optInMAType, +/* Generated */ VALUE_HANDLE_OUT(localBegIdx),VALUE_HANDLE_OUT(localNbElement),localOutputArray ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ ARRAY_FREE(localOutputArray); +/* Generated */ ARRAY_INT_FREE(localPeriodArray); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ outReal[i] = localOutputArray[i]; +/* Generated */ for( j=i+1; j < outputSize; j++ ) +/* Generated */ { +/* Generated */ if( localPeriodArray[j] == curPeriod ) +/* Generated */ { +/* Generated */ localPeriodArray[j] = 0; +/* Generated */ outReal[j] = localOutputArray[j]; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ ARRAY_FREE(localOutputArray); +/* Generated */ ARRAY_INT_FREE(localPeriodArray); +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outputSize; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MAX.c b/talib/ta_func/ta_MAX.c new file mode 100644 index 0000000..c576d8c --- /dev/null +++ b/talib/ta_func/ta_MAX.c @@ -0,0 +1,382 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JV Jesus Viver <324122@cienz.unizar.es> + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 101902 JV Speed optimization of the algorithm + * 102202 MF Speed optimize a bit further + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MaxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int maxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MAX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MAX - Highest value over a specified period + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Max( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Max( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #undef max +/* Generated */ public RetCode max( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MAX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double highest, tmp; + int outIdx, nbInitialElementNeeded; + int trailingIdx, today, i, highestIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + highestIdx = -1; + highest = 0.0; + + while( today <= endIdx ) + { + tmp = inReal[today]; + + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inReal[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inReal[i]; + if( tmp > highest ) + { + highestIdx = i; + highest = tmp; + } + } + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + } + + outReal[outIdx++] = highest; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Max( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Max( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode max( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MAX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double highest, tmp; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, today, i, highestIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ highestIdx = -1; +/* Generated */ highest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inReal[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inReal[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inReal[i]; +/* Generated */ if( tmp > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ outReal[outIdx++] = highest; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MAXINDEX.c b/talib/ta_func/ta_MAXINDEX.c new file mode 100644 index 0000000..930cd77 --- /dev/null +++ b/talib/ta_func/ta_MAXINDEX.c @@ -0,0 +1,377 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120806 AC Creation (equal to MAX but outputs index) + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MaxIndexLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int maxIndexLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MAXINDEX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MAXINDEX - Index of highest value over a specified period + * + * Input = double + * Output = int + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode maxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MAXINDEX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double highest, tmp; + int outIdx, nbInitialElementNeeded; + int trailingIdx, today, i, highestIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + highestIdx = -1; + highest = 0.0; + + while( today <= endIdx ) + { + tmp = inReal[today]; + + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inReal[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inReal[i]; + if( tmp > highest ) + { + highestIdx = i; + highest = tmp; + } + } + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + } + + outInteger[outIdx++] = highestIdx; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode maxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MAXINDEX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double highest, tmp; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, today, i, highestIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ highestIdx = -1; +/* Generated */ highest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inReal[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inReal[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inReal[i]; +/* Generated */ if( tmp > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ outInteger[outIdx++] = highestIdx; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MEDPRICE.c b/talib/ta_func/ta_MEDPRICE.c new file mode 100644 index 0000000..a87214a --- /dev/null +++ b/talib/ta_func/ta_MEDPRICE.c @@ -0,0 +1,273 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 112605 MF Fix outBegIdx when startIdx != 0 + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MedPriceLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int medPriceLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MEDPRICE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* This function have no lookback needed. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MEDPRICE - Median Price + * + * Input = High, Low + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MedPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MedPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode medPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MEDPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int outIdx, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* MEDPRICE = (High + Low ) / 2 + * This is the high and low of the same price bar. + * + * See MIDPRICE to use instead the highest high and lowest + * low over multiple price bar. + */ + + outIdx = 0; + + for( i=startIdx; i <= endIdx; i++ ) + { + outReal[outIdx++] = (inHigh[i]+inLow[i])/2.0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MedPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MedPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode medPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MEDPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ for( i=startIdx; i <= endIdx; i++ ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = (inHigh[i]+inLow[i])/2.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MFI.c b/talib/ta_func/ta_MFI.c new file mode 100644 index 0000000..1658249 --- /dev/null +++ b/talib/ta_func/ta_MFI.c @@ -0,0 +1,584 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * BT BobTrader (TADoc.org forum user). + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 062704 MF Prevent divide by zero. + * 121705 MF Java port related changes. + * 060907 MF,BT Fix #1727704. MFI logic bug when no price movement + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MfiLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int mfiLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MFI_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MFI,Mfi); +} + +#if defined( _MANAGED ) + ref class MoneyFlow + { + public: + double positive; + double negative; + }; +#elif defined( _JAVA ) + // See MoneyFlow.java for the definition. +#else + typedef struct + { + double positive; + double negative; + } MoneyFlow; +#endif + + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MFI - Money Flow Index + * + * Input = High, Low, Close, Volume + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mfi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ SubArray^ inVolume, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mfi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ cli::array^ inVolume, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mfi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ double inVolume[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MFI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ const double inVolume[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double posSumMF, negSumMF, prevValue; + double tempValue1, tempValue2; + int lookbackTotal, outIdx, i, today; + + CIRCBUF_PROLOG_CLASS( mflow, MoneyFlow, 50 ); /* Id, Type, Static Size */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose||!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + CIRCBUF_INIT_CLASS( mflow, MoneyFlow, optInTimePeriod ); + + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MFI,Mfi); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + CIRCBUF_DESTROY(mflow); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; /* Index into the output. */ + + /* Accumulate the positive and negative money flow + * among the initial period. + */ + today = startIdx-lookbackTotal; + prevValue = (inHigh[today]+inLow[today]+inClose[today])/3.0; + + posSumMF = 0.0; + negSumMF = 0.0; + today++; + for( i=optInTimePeriod; i > 0; i-- ) + { + tempValue1 = (inHigh[today]+inLow[today]+inClose[today])/3.0; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + tempValue1 *= inVolume[today++]; + if( tempValue2 < 0 ) + { + CIRCBUF_REF(mflow[mflow_Idx])negative = tempValue1; + negSumMF += tempValue1; + CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; + } + else if( tempValue2 > 0 ) + { + CIRCBUF_REF(mflow[mflow_Idx])positive = tempValue1; + posSumMF += tempValue1; + CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; + } + else + { + CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; + CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; + } + + CIRCBUF_NEXT(mflow); + } + + /* The following two equations are equivalent: + * MFI = 100 - (100 / 1 + (posSumMF/negSumMF)) + * MFI = 100 * (posSumMF/(posSumMF+negSumMF)) + * The second equation is used here for speed optimization. + */ + if( today > startIdx ) + { + tempValue1 = posSumMF+negSumMF; + if( tempValue1 < 1.0 ) + outReal[outIdx++] = 0.0; + else + outReal[outIdx++] = 100.0*(posSumMF/tempValue1); + } + else + { + /* Skip the unstable period. Do the processing + * but do not write it in the output. + */ + while( today < startIdx ) + { + posSumMF -= CIRCBUF_REF(mflow[mflow_Idx])positive; + negSumMF -= CIRCBUF_REF(mflow[mflow_Idx])negative; + + tempValue1 = (inHigh[today]+inLow[today]+inClose[today])/3.0; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + tempValue1 *= inVolume[today++]; + if( tempValue2 < 0 ) + { + CIRCBUF_REF(mflow[mflow_Idx])negative = tempValue1; + negSumMF += tempValue1; + CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; + } + else if( tempValue2 > 0 ) + { + CIRCBUF_REF(mflow[mflow_Idx])positive = tempValue1; + posSumMF += tempValue1; + CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; + } + else + { + CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; + CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; + } + + CIRCBUF_NEXT(mflow); + } + } + + /* Unstable period skipped... now continue + * processing if needed. + */ + while( today <= endIdx ) + { + posSumMF -= CIRCBUF_REF(mflow[mflow_Idx])positive; + negSumMF -= CIRCBUF_REF(mflow[mflow_Idx])negative; + + tempValue1 = (inHigh[today]+inLow[today]+inClose[today])/3.0; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + tempValue1 *= inVolume[today++]; + if( tempValue2 < 0 ) + { + CIRCBUF_REF(mflow[mflow_Idx])negative = tempValue1; + negSumMF += tempValue1; + CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; + } + else if( tempValue2 > 0 ) + { + CIRCBUF_REF(mflow[mflow_Idx])positive = tempValue1; + posSumMF += tempValue1; + CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; + } + else + { + CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; + CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; + } + + tempValue1 = posSumMF+negSumMF; + if( tempValue1 < 1.0 ) + outReal[outIdx++] = 0.0; + else + outReal[outIdx++] = 100.0*(posSumMF/tempValue1); + + CIRCBUF_NEXT(mflow); + } + + CIRCBUF_DESTROY(mflow); + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mfi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ SubArray^ inVolume, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mfi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ cli::array^ inVolume, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mfi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ float inVolume[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MFI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ const float inVolume[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double posSumMF, negSumMF, prevValue; +/* Generated */ double tempValue1, tempValue2; +/* Generated */ int lookbackTotal, outIdx, i, today; +/* Generated */ CIRCBUF_PROLOG_CLASS( mflow, MoneyFlow, 50 ); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose||!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ CIRCBUF_INIT_CLASS( mflow, MoneyFlow, optInTimePeriod ); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MFI,Mfi); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ CIRCBUF_DESTROY(mflow); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx-lookbackTotal; +/* Generated */ prevValue = (inHigh[today]+inLow[today]+inClose[today])/3.0; +/* Generated */ posSumMF = 0.0; +/* Generated */ negSumMF = 0.0; +/* Generated */ today++; +/* Generated */ for( i=optInTimePeriod; i > 0; i-- ) +/* Generated */ { +/* Generated */ tempValue1 = (inHigh[today]+inLow[today]+inClose[today])/3.0; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ tempValue1 *= inVolume[today++]; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = tempValue1; +/* Generated */ negSumMF += tempValue1; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; +/* Generated */ } +/* Generated */ else if( tempValue2 > 0 ) +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = tempValue1; +/* Generated */ posSumMF += tempValue1; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; +/* Generated */ } +/* Generated */ CIRCBUF_NEXT(mflow); +/* Generated */ } +/* Generated */ if( today > startIdx ) +/* Generated */ { +/* Generated */ tempValue1 = posSumMF+negSumMF; +/* Generated */ if( tempValue1 < 1.0 ) +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 100.0*(posSumMF/tempValue1); +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ while( today < startIdx ) +/* Generated */ { +/* Generated */ posSumMF -= CIRCBUF_REF(mflow[mflow_Idx])positive; +/* Generated */ negSumMF -= CIRCBUF_REF(mflow[mflow_Idx])negative; +/* Generated */ tempValue1 = (inHigh[today]+inLow[today]+inClose[today])/3.0; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ tempValue1 *= inVolume[today++]; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = tempValue1; +/* Generated */ negSumMF += tempValue1; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; +/* Generated */ } +/* Generated */ else if( tempValue2 > 0 ) +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = tempValue1; +/* Generated */ posSumMF += tempValue1; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; +/* Generated */ } +/* Generated */ CIRCBUF_NEXT(mflow); +/* Generated */ } +/* Generated */ } +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ posSumMF -= CIRCBUF_REF(mflow[mflow_Idx])positive; +/* Generated */ negSumMF -= CIRCBUF_REF(mflow[mflow_Idx])negative; +/* Generated */ tempValue1 = (inHigh[today]+inLow[today]+inClose[today])/3.0; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ tempValue1 *= inVolume[today++]; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = tempValue1; +/* Generated */ negSumMF += tempValue1; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; +/* Generated */ } +/* Generated */ else if( tempValue2 > 0 ) +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = tempValue1; +/* Generated */ posSumMF += tempValue1; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])positive = 0.0; +/* Generated */ CIRCBUF_REF(mflow[mflow_Idx])negative = 0.0; +/* Generated */ } +/* Generated */ tempValue1 = posSumMF+negSumMF; +/* Generated */ if( tempValue1 < 1.0 ) +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 100.0*(posSumMF/tempValue1); +/* Generated */ CIRCBUF_NEXT(mflow); +/* Generated */ } +/* Generated */ CIRCBUF_DESTROY(mflow); +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MIDPOINT.c b/talib/ta_func/ta_MIDPOINT.c new file mode 100644 index 0000000..bcd51b8 --- /dev/null +++ b/talib/ta_func/ta_MIDPOINT.c @@ -0,0 +1,354 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MidPointLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int midPointLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MIDPOINT_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MIDPOINT - MidPoint over period + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MidPoint( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MidPoint( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode midPoint( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MIDPOINT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + double lowest, highest, tmp; + int outIdx, nbInitialElementNeeded; + int trailingIdx, today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Find the highest and lowest value of a timeserie + * over the period. + * MIDPOINT = (Highest Value + Lowest Value)/2 + * + * See MIDPRICE if the input is a price bar with a + * high and low timeserie. + */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + + while( today <= endIdx ) + { + lowest = inReal[trailingIdx++]; + highest = lowest; + for( i=trailingIdx; i <= today; i++ ) + { + tmp = inReal[i]; + if( tmp < lowest ) lowest= tmp; + else if( tmp > highest) highest = tmp; + } + + outReal[outIdx++] = (highest+lowest)/2.0; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MidPoint( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MidPoint( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode midPoint( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MIDPOINT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, highest, tmp; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ lowest = inReal[trailingIdx++]; +/* Generated */ highest = lowest; +/* Generated */ for( i=trailingIdx; i <= today; i++ ) +/* Generated */ { +/* Generated */ tmp = inReal[i]; +/* Generated */ if( tmp < lowest ) lowest= tmp; +/* Generated */ else if( tmp > highest) highest = tmp; +/* Generated */ } +/* Generated */ outReal[outIdx++] = (highest+lowest)/2.0; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MIDPRICE.c b/talib/ta_func/ta_MIDPRICE.c new file mode 100644 index 0000000..20124b2 --- /dev/null +++ b/talib/ta_func/ta_MIDPRICE.c @@ -0,0 +1,367 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MidPriceLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int midPriceLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MIDPRICE_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MIDPRICE - Midpoint Price over period + * + * Input = High, Low + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MidPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MidPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode midPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MIDPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double lowest, highest, tmp; + int outIdx, nbInitialElementNeeded; + int trailingIdx, today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* MIDPRICE = (Highest High + Lowest Low)/2 + * + * This function is equivalent to MEDPRICE when the + * period is 1. + */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + + while( today <= endIdx ) + { + lowest = inLow[trailingIdx]; + highest = inHigh[trailingIdx]; + trailingIdx++; + for( i=trailingIdx; i <= today; i++ ) + { + tmp = inLow[i]; + if( tmp < lowest ) lowest= tmp; + tmp = inHigh[i]; + if( tmp > highest) highest = tmp; + } + + outReal[outIdx++] = (highest+lowest)/2.0; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MidPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MidPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode midPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MIDPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, highest, tmp; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ lowest = inLow[trailingIdx]; +/* Generated */ highest = inHigh[trailingIdx]; +/* Generated */ trailingIdx++; +/* Generated */ for( i=trailingIdx; i <= today; i++ ) +/* Generated */ { +/* Generated */ tmp = inLow[i]; +/* Generated */ if( tmp < lowest ) lowest= tmp; +/* Generated */ tmp = inHigh[i]; +/* Generated */ if( tmp > highest) highest = tmp; +/* Generated */ } +/* Generated */ outReal[outIdx++] = (highest+lowest)/2.0; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MIN.c b/talib/ta_func/ta_MIN.c new file mode 100644 index 0000000..ec11a9d --- /dev/null +++ b/talib/ta_func/ta_MIN.c @@ -0,0 +1,382 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JV Jesus Viver <324122@cienz.unizar.es> + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 101902 JV Speed optimization of the algorithm + * 102202 MF Speed optimize a bit further + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MinLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int minLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MIN_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MIN - Lowest value over a specified period + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Min( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Min( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #undef min +/* Generated */ public RetCode min( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MIN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double lowest, tmp; + int outIdx, nbInitialElementNeeded; + int trailingIdx, lowestIdx, today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + lowestIdx = -1; + lowest = 0.0; + + while( today <= endIdx ) + { + tmp = inReal[today]; + + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inReal[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inReal[i]; + if( tmp < lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + } + + outReal[outIdx++] = lowest; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Min( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Min( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode min( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MIN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, tmp; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, lowestIdx, today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ lowestIdx = -1; +/* Generated */ lowest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inReal[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inReal[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inReal[i]; +/* Generated */ if( tmp < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ outReal[outIdx++] = lowest; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MININDEX.c b/talib/ta_func/ta_MININDEX.c new file mode 100644 index 0000000..e71924d --- /dev/null +++ b/talib/ta_func/ta_MININDEX.c @@ -0,0 +1,377 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120806 AC Creation (equal to MIN but outputs index) + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MinIndexLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int minIndexLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MININDEX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MININDEX - Index of lowest value over a specified period + * + * Input = double + * Output = int + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MININDEX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double lowest, tmp; + int outIdx, nbInitialElementNeeded; + int trailingIdx, lowestIdx, today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + lowestIdx = -1; + lowest = 0.0; + + while( today <= endIdx ) + { + tmp = inReal[today]; + + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inReal[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inReal[i]; + if( tmp < lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + } + + outInteger[outIdx++] = lowestIdx; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outInteger ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outInteger ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MININDEX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outInteger[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, tmp; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, lowestIdx, today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outInteger ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ lowestIdx = -1; +/* Generated */ lowest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inReal[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inReal[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inReal[i]; +/* Generated */ if( tmp < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ outInteger[outIdx++] = lowestIdx; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MINMAX.c b/talib/ta_func/ta_MINMAX.c new file mode 100644 index 0000000..6ae5eae --- /dev/null +++ b/talib/ta_func/ta_MINMAX.c @@ -0,0 +1,439 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120906 AC Creation + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MinMaxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int minMaxLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MINMAX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MINMAX - Lowest and highest values over a specified period + * + * Input = double + * Output = double, double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinMax( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMin, +/* Generated */ SubArray^ outMax ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinMax( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMin, +/* Generated */ cli::array^ outMax ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minMax( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMin[], +/* Generated */ double outMax[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MINMAX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMin[], +/* Generated */ double outMax[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double highest, lowest, tmpHigh, tmpLow; + int outIdx, nbInitialElementNeeded; + int trailingIdx, today, i, highestIdx, lowestIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMin ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMax ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + highestIdx = -1; + highest = 0.0; + lowestIdx = -1; + lowest = 0.0; + + while( today <= endIdx ) + { + tmpLow = tmpHigh = inReal[today]; + + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inReal[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmpHigh = inReal[i]; + if( tmpHigh > highest ) + { + highestIdx = i; + highest = tmpHigh; + } + } + } + else if( tmpHigh >= highest ) + { + highestIdx = today; + highest = tmpHigh; + } + + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inReal[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmpLow = inReal[i]; + if( tmpLow < lowest ) + { + lowestIdx = i; + lowest = tmpLow; + } + } + } + else if( tmpLow <= lowest ) + { + lowestIdx = today; + lowest = tmpLow; + } + + outMax[outIdx] = highest; + outMin[outIdx] = lowest; + outIdx++; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinMax( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMin, +/* Generated */ SubArray^ outMax ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinMax( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMin, +/* Generated */ cli::array^ outMax ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minMax( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outMin[], +/* Generated */ double outMax[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MINMAX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outMin[], +/* Generated */ double outMax[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double highest, lowest, tmpHigh, tmpLow; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, today, i, highestIdx, lowestIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMin ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMax ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ highestIdx = -1; +/* Generated */ highest = 0.0; +/* Generated */ lowestIdx = -1; +/* Generated */ lowest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmpLow = tmpHigh = inReal[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inReal[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmpHigh = inReal[i]; +/* Generated */ if( tmpHigh > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmpHigh; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmpHigh >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmpHigh; +/* Generated */ } +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inReal[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmpLow = inReal[i]; +/* Generated */ if( tmpLow < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmpLow; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmpLow <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmpLow; +/* Generated */ } +/* Generated */ outMax[outIdx] = highest; +/* Generated */ outMin[outIdx] = lowest; +/* Generated */ outIdx++; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MINMAXINDEX.c b/talib/ta_func/ta_MINMAXINDEX.c new file mode 100644 index 0000000..f550a01 --- /dev/null +++ b/talib/ta_func/ta_MINMAXINDEX.c @@ -0,0 +1,439 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * AC Angelo Ciceri + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120906 AC Creation (equal to MINMAX but outputs index) + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MinMaxIndexLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int minMaxIndexLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MINMAXINDEX_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MINMAXINDEX - Indexes of lowest and highest values over a specified period + * + * Input = double + * Output = int, int + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinMaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMinIdx, +/* Generated */ SubArray^ outMaxIdx ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinMaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMinIdx, +/* Generated */ cli::array^ outMaxIdx ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minMaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outMinIdx[], +/* Generated */ int outMaxIdx[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MINMAXINDEX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outMinIdx[], +/* Generated */ int outMaxIdx[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double highest, lowest, tmpHigh, tmpLow; + int outIdx, nbInitialElementNeeded; + int trailingIdx, today, i, highestIdx, lowestIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMinIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outMaxIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + highestIdx = -1; + highest = 0.0; + lowestIdx = -1; + lowest = 0.0; + + while( today <= endIdx ) + { + tmpLow = tmpHigh = inReal[today]; + + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inReal[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmpHigh = inReal[i]; + if( tmpHigh > highest ) + { + highestIdx = i; + highest = tmpHigh; + } + } + } + else if( tmpHigh >= highest ) + { + highestIdx = today; + highest = tmpHigh; + } + + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inReal[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmpLow = inReal[i]; + if( tmpLow < lowest ) + { + lowestIdx = i; + lowest = tmpLow; + } + } + } + else if( tmpLow <= lowest ) + { + lowestIdx = today; + lowest = tmpLow; + } + + outMaxIdx[outIdx] = highestIdx; + outMinIdx[outIdx] = lowestIdx; + outIdx++; + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinMaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outMinIdx, +/* Generated */ SubArray^ outMaxIdx ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinMaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outMinIdx, +/* Generated */ cli::array^ outMaxIdx ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minMaxIndex( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ int outMinIdx[], +/* Generated */ int outMaxIdx[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MINMAXINDEX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ int outMinIdx[], +/* Generated */ int outMaxIdx[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double highest, lowest, tmpHigh, tmpLow; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, today, i, highestIdx, lowestIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outMinIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outMaxIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ highestIdx = -1; +/* Generated */ highest = 0.0; +/* Generated */ lowestIdx = -1; +/* Generated */ lowest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmpLow = tmpHigh = inReal[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inReal[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmpHigh = inReal[i]; +/* Generated */ if( tmpHigh > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmpHigh; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmpHigh >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmpHigh; +/* Generated */ } +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inReal[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmpLow = inReal[i]; +/* Generated */ if( tmpLow < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmpLow; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ else if( tmpLow <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmpLow; +/* Generated */ } +/* Generated */ outMaxIdx[outIdx] = highestIdx; +/* Generated */ outMinIdx[outIdx] = lowestIdx; +/* Generated */ outIdx++; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MINUS_DI.c b/talib/ta_func/ta_MINUS_DI.c new file mode 100644 index 0000000..c7a85af --- /dev/null +++ b/talib/ta_func/ta_MINUS_DI.c @@ -0,0 +1,714 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * MIF Mirek Fontan (mira@fontan.cz) + * CF Christo Fogelberg + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 082303 MF Fix #792298. Remove rounding. Bug reported by AM. + * 062704 MF Fix #965557. Div by zero bug reported by MIF. + * 122204 MF,CF Fix #1090231. Issues when period is 1. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MinusDILookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int minusDILookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MINUS_DI_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + if( optInTimePeriod > 1 ) + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DI,MinusDI); + else + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MINUS_DI - Minus Directional Indicator + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MINUS_DI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int today, lookbackTotal, outIdx; + double prevHigh, prevLow, prevClose; + double prevMinusDM, prevTR; + double tempReal, tempReal2, diffP, diffM; + + int i; + + #define TRUE_RANGE(TH,TL,YC,OUT) {\ + OUT = TH-TL; \ + tempReal2 = std_fabs(TH-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + tempReal2 = std_fabs(TL-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + } + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* + * The DM1 (one period) is base on the largest part of + * today's range that is outside of yesterdays range. + * + * The following 7 cases explain how the +DM and -DM are + * calculated on one period: + * + * Case 1: Case 2: + * C| A| + * | | C| + * | +DM1 = (C-A) B| | +DM1 = 0 + * | -DM1 = 0 | -DM1 = (B-D) + * A| | D| + * | D| + * B| + * + * Case 3: Case 4: + * C| C| + * | A| | + * | +DM1 = (C-A) | | +DM1 = 0 + * | -DM1 = 0 B| | -DM1 = (B-D) + * A| | | + * | | D| + * B| | + * D| + * + * Case 5: Case 6: + * A| A| C| + * | C| +DM1 = 0 | | +DM1 = 0 + * | | -DM1 = 0 | | -DM1 = 0 + * | D| | | + * B| B| D| + * + * + * Case 7: + * + * C| + * A| | + * | | +DM1=0 + * B| | -DM1=0 + * D| + * + * In case 3 and 4, the rule is that the smallest delta between + * (C-A) and (B-D) determine which of +DM or -DM is zero. + * + * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are + * zero. + * + * The rules remain the same when A=B and C=D (when the highs + * equal the lows). + * + * When calculating the DM over a period > 1, the one-period DM + * for the desired period are initialy sum. In other word, + * for a -DM14, sum the -DM1 for the first 14 days (that's + * 13 values because there is no DM for the first day!) + * Subsequent DM are calculated using the Wilder's + * smoothing approach: + * + * Previous -DM14 + * Today's -DM14 = Previous -DM14 - -------------- + Today's -DM1 + * 14 + * + * Calculation of a -DI14 is as follow: + * + * -DM14 + * -DI14 = -------- + * TR14 + * + * Calculation of the TR14 is: + * + * Previous TR14 + * Today's TR14 = Previous TR14 - -------------- + Today's TR1 + * 14 + * + * The first TR14 is the summation of the first 14 TR1. See the + * TA_TRANGE function on how to calculate the true range. + * + * Reference: + * New Concepts In Technical Trading Systems, J. Welles Wilder Jr + */ + + /* Original implementation from Wilder's book was doing some integer + * rounding in its calculations. + * + * This was understandable in the context that at the time the book + * was written, most user were doing the calculation by hand. + * + * For a computer, rounding is unnecessary (and even problematic when inputs + * are close to 1). + * + * TA-Lib does not do the rounding. Still, if you want to reproduce Wilder's examples, + * you can comment out the following #undef/#define and rebuild the library. + */ + #undef round_pos + #define round_pos(x) (x) + + if( optInTimePeriod > 1 ) + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DI,MinusDI); + else + lookbackTotal = 1; + + /* Adjust startIdx to account for the lookback period. */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Indicate where the next output should be put + * in the outReal. + */ + outIdx = 0; + + /* Trap the case where no smoothing is needed. */ + if( optInTimePeriod <= 1 ) + { + /* No smoothing needed. Just do the following: + * for each price bar. + * -DM1 + * -DI1 = ---- + * TR1 + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + today = startIdx-1; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + prevClose = inClose[today]; + while( today < endIdx ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + if( TA_IS_ZERO(tempReal) ) + outReal[outIdx++] = (double)0.0; + else + outReal[outIdx++] = diffM/tempReal; + } + else + outReal[outIdx++] = (double)0.0; + prevClose = inClose[today]; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Process the initial DM and TR */ + VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; + + prevMinusDM = 0.0; + prevTR = 0.0; + today = startIdx - lookbackTotal; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + prevClose = inClose[today]; + i = optInTimePeriod-1; + while( i-- > 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR += tempReal; + prevClose = inClose[today]; + } + + /* Process subsequent DI */ + + /* Skip the unstable period. Note that this loop must be executed + * at least ONCE to calculate the first DI. + */ + i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DI,MinusDI) + 1; + while( i-- != 0 ) + { + /* Calculate the prevMinusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; + } + else + { + /* Case 1,3,5 and 7 */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + } + + + /* Now start to write the output in + * the caller provided outReal. + */ + if( !TA_IS_ZERO(prevTR) ) + outReal[0] = round_pos(100.0*(prevMinusDM/prevTR)); + else + outReal[0] = 0.0; + outIdx = 1; + + while( today < endIdx ) + { + /* Calculate the prevMinusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; + } + else + { + /* Case 1,3,5 and 7 */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + + /* Calculate the DI. The value is rounded (see Wilder book). */ + if( !TA_IS_ZERO(prevTR) ) + outReal[outIdx++] = round_pos(100.0*(prevMinusDM/prevTR)); + else + outReal[outIdx++] = 0.0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MINUS_DI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, lookbackTotal, outIdx; +/* Generated */ double prevHigh, prevLow, prevClose; +/* Generated */ double prevMinusDM, prevTR; +/* Generated */ double tempReal, tempReal2, diffP, diffM; +/* Generated */ int i; +/* Generated */ #define TRUE_RANGE(TH,TL,YC,OUT) {\ +/* Generated */ OUT = TH-TL; \ +/* Generated */ tempReal2 = std_fabs(TH-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ tempReal2 = std_fabs(TL-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ } +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #undef round_pos +/* Generated */ #define round_pos(x) (x) +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DI,MinusDI); +/* Generated */ else +/* Generated */ lookbackTotal = 1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ if( optInTimePeriod <= 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ today = startIdx-1; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ prevClose = inClose[today]; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ if( TA_IS_ZERO(tempReal) ) +/* Generated */ outReal[outIdx++] = (double)0.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = diffM/tempReal; +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[outIdx++] = (double)0.0; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; +/* Generated */ prevMinusDM = 0.0; +/* Generated */ prevTR = 0.0; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ prevClose = inClose[today]; +/* Generated */ i = optInTimePeriod-1; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR += tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DI,MinusDI) + 1; +/* Generated */ while( i-- != 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ outReal[0] = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ outIdx = 1; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ outReal[outIdx++] = round_pos(100.0*(prevMinusDM/prevTR)); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MINUS_DM.c b/talib/ta_func/ta_MINUS_DM.c new file mode 100644 index 0000000..2e090c8 --- /dev/null +++ b/talib/ta_func/ta_MINUS_DM.c @@ -0,0 +1,589 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MinusDMLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int minusDMLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MINUS_DM_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + if( optInTimePeriod > 1 ) + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DM,MinusDM) - 1; + else + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MINUS_DM - Minus Directional Movement + * + * Input = High, Low + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MINUS_DM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int today, lookbackTotal, outIdx; + double prevHigh, prevLow, tempReal; + double prevMinusDM; + double diffP, diffM; + int i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* + * The DM1 (one period) is base on the largest part of + * today's range that is outside of yesterdays range. + * + * The following 7 cases explain how the +DM and -DM are + * calculated on one period: + * + * Case 1: Case 2: + * C| A| + * | | C| + * | +DM1 = (C-A) B| | +DM1 = 0 + * | -DM1 = 0 | -DM1 = (B-D) + * A| | D| + * | D| + * B| + * + * Case 3: Case 4: + * C| C| + * | A| | + * | +DM1 = (C-A) | | +DM1 = 0 + * | -DM1 = 0 B| | -DM1 = (B-D) + * A| | | + * | | D| + * B| | + * D| + * + * Case 5: Case 6: + * A| A| C| + * | C| +DM1 = 0 | | +DM1 = 0 + * | | -DM1 = 0 | | -DM1 = 0 + * | D| | | + * B| B| D| + * + * + * Case 7: + * + * C| + * A| | + * | | +DM=0 + * B| | -DM=0 + * D| + * + * In case 3 and 4, the rule is that the smallest delta between + * (C-A) and (B-D) determine which of +DM or -DM is zero. + * + * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are + * zero. + * + * The rules remain the same when A=B and C=D (when the highs + * equal the lows). + * + * When calculating the DM over a period > 1, the one-period DM + * for the desired period are initialy sum. In other word, + * for a -DM14, sum the -DM1 for the first 14 days (that's + * 13 values because there is no DM for the first day!) + * Subsequent DM are calculated using the Wilder's + * smoothing approach: + * + * Previous -DM14 + * Today's -DM14 = Previous -DM14 - -------------- + Today's -DM1 + * 14 + * + * Reference: + * New Concepts In Technical Trading Systems, J. Welles Wilder Jr + */ + + if( optInTimePeriod > 1 ) + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DM,MinusDM) - 1; + else + lookbackTotal = 1; + + /* Adjust startIdx to account for the lookback period. */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Indicate where the next output should be put + * in the outReal. + */ + outIdx = 0; + + /* Trap the case where no smoothing is needed. */ + if( optInTimePeriod <= 1 ) + { + /* No smoothing needed. Just do a simple DM1 + * for each price bar. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + today = startIdx-1; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + while( today < endIdx ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + outReal[outIdx++] = diffM; + } + else + outReal[outIdx++] = 0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Process the initial DM */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + prevMinusDM = 0.0; + today = startIdx - lookbackTotal; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + i = optInTimePeriod-1; + while( i-- > 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM += diffM; + } + } + + /* Process subsequent DM */ + + /* Skip the unstable period. */ + i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DM,MinusDM); + while( i-- != 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; + } + else + { + /* Case 1,3,5 and 7 */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); + } + } + + /* Now start to write the output in + * the caller provided outReal. + */ + outReal[0] = prevMinusDM; + outIdx = 1; + + while( today < endIdx ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + if( (diffM > 0) && (diffP < diffM) ) + { + /* Case 2 and 4: +DM=0,-DM=diffM */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; + } + else + { + /* Case 1,3,5 and 7 */ + prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); + } + + outReal[outIdx++] = prevMinusDM; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::MinusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::MinusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode minusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MINUS_DM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, lookbackTotal, outIdx; +/* Generated */ double prevHigh, prevLow, tempReal; +/* Generated */ double prevMinusDM; +/* Generated */ double diffP, diffM; +/* Generated */ int i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DM,MinusDM) - 1; +/* Generated */ else +/* Generated */ lookbackTotal = 1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ if( optInTimePeriod <= 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ today = startIdx-1; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = diffM; +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ prevMinusDM = 0.0; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ i = optInTimePeriod-1; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM += diffM; +/* Generated */ } +/* Generated */ } +/* Generated */ i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_MINUS_DM,MinusDM); +/* Generated */ while( i-- != 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ } +/* Generated */ outReal[0] = prevMinusDM; +/* Generated */ outIdx = 1; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffM > 0) && (diffP < diffM) ) +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod) + diffM; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevMinusDM = prevMinusDM - (prevMinusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ outReal[outIdx++] = prevMinusDM; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MOM.c b/talib/ta_func/ta_MOM.c new file mode 100644 index 0000000..b2ac4cb --- /dev/null +++ b/talib/ta_func/ta_MOM.c @@ -0,0 +1,344 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MomLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int momLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MOM_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return optInTimePeriod; + +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MOM - Momentum + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MOM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + + int inIdx, outIdx, trailingIdx; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* The interpretation of the rate of change varies widely depending + * which software and/or books you are refering to. + * + * The following is the table of Rate-Of-Change implemented in TA-LIB: + * MOM = (price - prevPrice) [Momentum] + * ROC = ((price/prevPrice)-1)*100 [Rate of change] + * ROCP = (price-prevPrice)/prevPrice [Rate of change Percentage] + * ROCR = (price/prevPrice) [Rate of change ratio] + * ROCR100 = (price/prevPrice)*100 [Rate of change ratio 100 Scale] + * + * Here are the equivalent function in other software: + * TA-Lib | Tradestation | Metastock + * ================================================= + * MOM | Momentum | ROC (Point) + * ROC | ROC | ROC (Percent) + * ROCP | PercentChange | - + * ROCR | - | - + * ROCR100 | - | MO + * + * The MOM function is the only one who is not normalized, and thus + * should be avoided for comparing different time serie of prices. + * + * ROC and ROCP are centered at zero and can have positive and negative + * value. Here are some equivalence: + * ROC = ROCP/100 + * = ((price-prevPrice)/prevPrice)/100 + * = ((price/prevPrice)-1)*100 + * + * ROCR and ROCR100 are ratio respectively centered at 1 and 100 and are + * always positive values. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate Momentum: + * Just substract the value from 'period' ago from + * current value. + */ + outIdx = 0; + inIdx = startIdx; + trailingIdx = startIdx - optInTimePeriod; + + while( inIdx <= endIdx ) + outReal[outIdx++] = inReal[inIdx++] - inReal[trailingIdx++]; + + /* Set output limits. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mom( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MOM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int inIdx, outIdx, trailingIdx; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ inIdx = startIdx; +/* Generated */ trailingIdx = startIdx - optInTimePeriod; +/* Generated */ while( inIdx <= endIdx ) +/* Generated */ outReal[outIdx++] = inReal[inIdx++] - inReal[trailingIdx++]; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_MULT.c b/talib/ta_func/ta_MULT.c new file mode 100644 index 0000000..0c0e4b6 --- /dev/null +++ b/talib/ta_func/ta_MULT.c @@ -0,0 +1,270 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::MultLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int multLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_MULT_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_MULT - Vector Arithmetic Mult + * + * Input = double, double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mult( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mult( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mult( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal0[], +/* Generated */ double inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_MULT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal0[], +/* Generated */ const double inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = inReal0[i]*inReal1[i]; + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Mult( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Mult( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode mult( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal0[], +/* Generated */ float inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_MULT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal0[], +/* Generated */ const float inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = inReal0[i]*inReal1[i]; +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_NATR.c b/talib/ta_func/ta_NATR.c new file mode 100644 index 0000000..12c6cec --- /dev/null +++ b/talib/ta_func/ta_NATR.c @@ -0,0 +1,497 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 060306 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::NatrLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int natrLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_NATR_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* The ATR lookback is the sum of: + * 1 + (optInTimePeriod - 1) + * + * Where 1 is for the True Range, and + * (optInTimePeriod-1) is for the simple + * moving average. + */ + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_NATR,Natr); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_NATR - Normalized Average True Range + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Natr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Natr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode natr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_NATR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ENUM_DECLARATION(RetCode) retCode; + int outIdx, today, lookbackTotal; + int nbATR; + VALUE_HANDLE_INT(outBegIdx1); + VALUE_HANDLE_INT(outNbElement1); + + double prevATR, tempValue; + ARRAY_REF( tempBuffer ); + ARRAY_LOCAL(prevATRTemp,1); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* This function is very similar as ATR, except + * it is being normalized as follow: + * + * NATR = (ATR(period) / Close) * 100 + * + * + * Normalization make the ATR function more relevant + * in the folllowing scenario: + * - Long term analysis where the price changes drastically. + * - Cross-market or cross-security ATR comparison. + * + * More Info: + * Technical Analysis of Stock & Commodities (TASC) + * May 2006 by John Forman + */ + + /* Average True Range is the greatest of the following: + * + * val1 = distance from today's high to today's low. + * val2 = distance from yesterday's close to today's high. + * val3 = distance from yesterday's close to today's low. + * + * These value are averaged for the specified period using + * Wilder method. This method have an unstable period comparable + * to an Exponential Moving Average (EMA). + */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(NATR)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + /* Trap the case where no smoothing is needed. */ + if( optInTimePeriod <= 1 ) + { + /* No smoothing needed. Just do a TRANGE. */ + return FUNCTION_CALL(TRANGE)( startIdx, endIdx, + inHigh, inLow, inClose, + outBegIdx, outNBElement, outReal ); + } + + /* Allocate an intermediate buffer for TRANGE. */ + ARRAY_ALLOC(tempBuffer, lookbackTotal+(endIdx-startIdx)+1 ); + + /* Do TRANGE in the intermediate buffer. */ + retCode = FUNCTION_CALL(TRANGE)( (startIdx-lookbackTotal+1), endIdx, + inHigh, inLow, inClose, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), + tempBuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + ARRAY_FREE( tempBuffer ); + return retCode; + } + + /* First value of the ATR is a simple Average of + * the TRANGE output for the specified period. + */ + retCode = FUNCTION_CALL_DOUBLE(INT_SMA)( optInTimePeriod-1, + optInTimePeriod-1, + tempBuffer, optInTimePeriod, + VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), + prevATRTemp ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + ARRAY_FREE( tempBuffer ); + return retCode; + } + prevATR = prevATRTemp[0]; + + /* Subsequent value are smoothed using the + * previous ATR value (Wilder's approach). + * 1) Multiply the previous ATR by 'period-1'. + * 2) Add today TR value. + * 3) Divide by 'period'. + */ + today = optInTimePeriod; + outIdx = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_NATR,Natr); + /* Skip the unstable period. */ + while( outIdx != 0 ) + { + prevATR *= optInTimePeriod - 1; + prevATR += tempBuffer[today++]; + prevATR /= optInTimePeriod; + outIdx--; + } + + /* Now start to write the final ATR in the caller + * provided outReal. + */ + outIdx = 1; + tempValue = inClose[today]; + if( !TA_IS_ZERO(tempValue) ) + outReal[0] = (prevATR/tempValue)*100.0; + else + outReal[0] = 0.0; + + /* Now do the number of requested ATR. */ + nbATR = (endIdx - startIdx)+1; + + while( --nbATR != 0 ) + { + prevATR *= optInTimePeriod - 1; + prevATR += tempBuffer[today++]; + prevATR /= optInTimePeriod; + tempValue = inClose[today]; + if( !TA_IS_ZERO(tempValue) ) + outReal[outIdx] = (prevATR/tempValue)*100.0; + else + outReal[0] = 0.0; + outIdx++; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + ARRAY_FREE( tempBuffer ); + + return retCode; +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Natr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Natr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode natr( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_NATR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int outIdx, today, lookbackTotal; +/* Generated */ int nbATR; +/* Generated */ VALUE_HANDLE_INT(outBegIdx1); +/* Generated */ VALUE_HANDLE_INT(outNbElement1); +/* Generated */ double prevATR, tempValue; +/* Generated */ ARRAY_REF( tempBuffer ); +/* Generated */ ARRAY_LOCAL(prevATRTemp,1); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackTotal = LOOKBACK_CALL(NATR)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ if( optInTimePeriod <= 1 ) +/* Generated */ { +/* Generated */ return FUNCTION_CALL(TRANGE)( startIdx, endIdx, +/* Generated */ inHigh, inLow, inClose, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ } +/* Generated */ ARRAY_ALLOC(tempBuffer, lookbackTotal+(endIdx-startIdx)+1 ); +/* Generated */ retCode = FUNCTION_CALL(TRANGE)( (startIdx-lookbackTotal+1), endIdx, +/* Generated */ inHigh, inLow, inClose, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ tempBuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_SMA)( optInTimePeriod-1, +/* Generated */ optInTimePeriod-1, +/* Generated */ tempBuffer, optInTimePeriod, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ prevATRTemp ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ prevATR = prevATRTemp[0]; +/* Generated */ today = optInTimePeriod; +/* Generated */ outIdx = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_NATR,Natr); +/* Generated */ while( outIdx != 0 ) +/* Generated */ { +/* Generated */ prevATR *= optInTimePeriod - 1; +/* Generated */ prevATR += tempBuffer[today++]; +/* Generated */ prevATR /= optInTimePeriod; +/* Generated */ outIdx--; +/* Generated */ } +/* Generated */ outIdx = 1; +/* Generated */ tempValue = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(tempValue) ) +/* Generated */ outReal[0] = (prevATR/tempValue)*100.0; +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ nbATR = (endIdx - startIdx)+1; +/* Generated */ while( --nbATR != 0 ) +/* Generated */ { +/* Generated */ prevATR *= optInTimePeriod - 1; +/* Generated */ prevATR += tempBuffer[today++]; +/* Generated */ prevATR /= optInTimePeriod; +/* Generated */ tempValue = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(tempValue) ) +/* Generated */ outReal[outIdx] = (prevATR/tempValue)*100.0; +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ outIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_NVI.c b/talib/ta_func/ta_NVI.c new file mode 100644 index 0000000..2cdbbdf --- /dev/null +++ b/talib/ta_func/ta_NVI.c @@ -0,0 +1,197 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #using +/* Generated */ #include "Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (TA_INTERNAL_ERROR) +/* Generated */ namespace TA { namespace Library { +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::NVI_Lookback( /* Generated */ void ) +/* Generated */ +/* Generated */ #else +/* Generated */ int TA_NVI_Lookback( /* Generated */ void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert lookback code here. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_NVI - Negative Volume Index + * + * Input = Close, Volume + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ enum Core::TA_RetCode Core::NVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inClose __gc [], +/* Generated */ int inVolume __gc [], +/* Generated */ [OutAttribute]Int32 REF(outBegIdx), +/* Generated */ [OutAttribute]Int32 REF(outNBElement), +/* Generated */ double outReal __gc [] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_NVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inClose[], +/* Generated */ const int inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return TA_OUT_OF_RANGE_START_INDEX; +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return TA_OUT_OF_RANGE_END_INDEX; +/* Generated */ +/* Generated */ /* Validate the parameters. */ +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inClose||!inVolume) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ +/* Generated */ if( outReal == NULL ) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Default return values */ + *outBegIdx = 0; + *outNBElement = 0; + + return TA_SUCCESS; +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #if !defined( _MANAGED ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) +/* Generated */ enum Core::TA_RetCode Core::NVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inClose __gc [], +/* Generated */ int inVolume __gc [], +/* Generated */ [OutAttribute]Int32 REF(outBegIdx), +/* Generated */ [OutAttribute]Int32 REF(outNBElement), +/* Generated */ double outReal __gc [] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_NVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inClose[], +/* Generated */ const int inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return TA_OUT_OF_RANGE_START_INDEX; +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return TA_OUT_OF_RANGE_END_INDEX; +/* Generated */ if(!inClose||!inVolume) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ if( outReal == NULL ) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ #endif +/* Generated */ *outBegIdx = 0; +/* Generated */ *outNBElement = 0; +/* Generated */ return TA_SUCCESS; +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }} // Close namespace TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_OBV.c b/talib/ta_func/ta_OBV.c new file mode 100644 index 0000000..a7ebf1f --- /dev/null +++ b/talib/ta_func/ta_OBV.c @@ -0,0 +1,289 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AC Angelo Ciceri + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 110206 AC Change volume and open interest to double + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::ObvLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int obvLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_OBV_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* This function have no lookback needed. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_OBV - On Balance Volume + * + * Input = double, Volume + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Obv( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ SubArray^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Obv( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ cli::array^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode obv( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ double inVolume[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_OBV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ const double inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int i; + int outIdx; + double prevReal, tempReal, prevOBV; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + prevOBV = inVolume[startIdx]; + prevReal = inReal[startIdx]; + outIdx = 0; + + for(i=startIdx; i <= endIdx; i++ ) + { + tempReal = inReal[i]; + if( tempReal > prevReal ) + prevOBV += inVolume[i]; + else if( tempReal < prevReal ) + prevOBV -= inVolume[i]; + + outReal[outIdx++] = prevOBV; + prevReal = tempReal; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Obv( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ SubArray^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Obv( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ cli::array^ inVolume, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode obv( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ float inVolume[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_OBV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ const float inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i; +/* Generated */ int outIdx; +/* Generated */ double prevReal, tempReal, prevOBV; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if(!inVolume) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ prevOBV = inVolume[startIdx]; +/* Generated */ prevReal = inReal[startIdx]; +/* Generated */ outIdx = 0; +/* Generated */ for(i=startIdx; i <= endIdx; i++ ) +/* Generated */ { +/* Generated */ tempReal = inReal[i]; +/* Generated */ if( tempReal > prevReal ) +/* Generated */ prevOBV += inVolume[i]; +/* Generated */ else if( tempReal < prevReal ) +/* Generated */ prevOBV -= inVolume[i]; +/* Generated */ outReal[outIdx++] = prevOBV; +/* Generated */ prevReal = tempReal; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_PLUS_DI.c b/talib/ta_func/ta_PLUS_DI.c new file mode 100644 index 0000000..5aa4ea1 --- /dev/null +++ b/talib/ta_func/ta_PLUS_DI.c @@ -0,0 +1,714 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AM Adrian Michel + * MIF Mirek Fontan (mira@fontan.cz) + * CF Christo Fogelberg + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 082303 MF Fix #792298. Remove rounding. Bug reported by AM. + * 062704 MF Fix #965557. Div by zero bug reported by MIF. + * 122204 MF,CF Fix #1090231. Issues when period is 1. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::PlusDILookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int plusDILookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_PLUS_DI_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + if( optInTimePeriod > 1 ) + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DI,PlusDI); + else + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_PLUS_DI - Plus Directional Indicator + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::PlusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::PlusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode plusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_PLUS_DI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int today, lookbackTotal, outIdx; + double prevHigh, prevLow, prevClose; + double prevPlusDM, prevTR; + double tempReal, tempReal2, diffP, diffM; + + int i; + + #define TRUE_RANGE(TH,TL,YC,OUT) {\ + OUT = TH-TL; \ + tempReal2 = std_fabs(TH-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + tempReal2 = std_fabs(TL-YC); \ + if( tempReal2 > OUT ) \ + OUT = tempReal2; \ + } + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + /* + * The DM1 (one period) is base on the largest part of + * today's range that is outside of yesterdays range. + * + * The following 7 cases explain how the +DM and -DM are + * calculated on one period: + * + * Case 1: Case 2: + * C| A| + * | | C| + * | +DM1 = (C-A) B| | +DM1 = 0 + * | -DM1 = 0 | -DM1 = (B-D) + * A| | D| + * | D| + * B| + * + * Case 3: Case 4: + * C| C| + * | A| | + * | +DM1 = (C-A) | | +DM1 = 0 + * | -DM1 = 0 B| | -DM1 = (B-D) + * A| | | + * | | D| + * B| | + * D| + * + * Case 5: Case 6: + * A| A| C| + * | C| +DM1 = 0 | | +DM1 = 0 + * | | -DM1 = 0 | | -DM1 = 0 + * | D| | | + * B| B| D| + * + * + * Case 7: + * + * C| + * A| | + * | | +DM1=0 + * B| | -DM1=0 + * D| + * + * In case 3 and 4, the rule is that the smallest delta between + * (C-A) and (B-D) determine which of +DM or -DM is zero. + * + * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are + * zero. + * + * The rules remain the same when A=B and C=D (when the highs + * equal the lows). + * + * When calculating the DM over a period > 1, the one-period DM + * for the desired period are initialy sum. In other word, + * for a -DM14, sum the -DM1 for the first 14 days (that's + * 13 values because there is no DM for the first day!) + * Subsequent DM are calculated using the Wilder's + * smoothing approach: + * + * Previous +DM14 + * Today's +DM14 = Previous +DM14 - -------------- + Today's +DM1 + * 14 + * + * Calculation of a +DI14 is as follow: + * + * +DM14 + * +DI14 = -------- + * TR14 + * + * Calculation of the TR14 is: + * + * Previous TR14 + * Today's TR14 = Previous TR14 - -------------- + Today's TR1 + * 14 + * + * The first TR14 is the summation of the first 14 TR1. See the + * TA_TRANGE function on how to calculate the true range. + * + * Reference: + * New Concepts In Technical Trading Systems, J. Welles Wilder Jr + */ + + /* Original implementation from Wilder's book was doing some integer + * rounding in its calculations. + * + * This was understandable in the context that at the time the book + * was written, most user were doing the calculation by hand. + * + * For a computer, rounding is unnecessary (and even problematic when inputs + * are close to 1). + * + * TA-Lib does not do the rounding. Still, if you want to reproduce Wilder's examples, + * you can comment out the following #undef/#define and rebuild the library. + */ + #undef round_pos + #define round_pos(x) (x) + + if( optInTimePeriod > 1 ) + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DI,PlusDI); + else + lookbackTotal = 1; + + /* Adjust startIdx to account for the lookback period. */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Indicate where the next output should be put + * in the outReal. + */ + outIdx = 0; + + /* Trap the case where no smoothing is needed. */ + if( optInTimePeriod <= 1 ) + { + /* No smoothing needed. Just do the following: + * for each price bar. + * +DM1 + * +DI1 = ---- + * TR1 + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + today = startIdx-1; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + prevClose = inClose[today]; + while( today < endIdx ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + if( TA_IS_ZERO(tempReal) ) + outReal[outIdx++] = (double)0.0; + else + outReal[outIdx++] = diffP/tempReal; + } + else + outReal[outIdx++] = (double)0.0; + prevClose = inClose[today]; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Process the initial DM and TR */ + VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; + + prevPlusDM = 0.0; + prevTR = 0.0; + today = startIdx - lookbackTotal; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + prevClose = inClose[today]; + i = optInTimePeriod-1; + while( i-- > 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR += tempReal; + prevClose = inClose[today]; + } + + /* Process subsequent DI */ + + /* Skip the unstable period. Note that this loop must be executed + * at least ONCE to calculate the first DI. + */ + i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DI,PlusDI) + 1; + while( i-- != 0 ) + { + /* Calculate the prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; + } + else + { + /* Case 2,4,5 and 7 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + } + + /* Now start to write the output in + * the caller provided outReal. + */ + + if( !TA_IS_ZERO(prevTR) ) + outReal[0] = round_pos(100.0*(prevPlusDM/prevTR)); + else + outReal[0] = 0.0; + outIdx = 1; + + while( today < endIdx ) + { + /* Calculate the prevPlusDM */ + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; + } + else + { + /* Case 2,4,5 and 7 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); + } + + /* Calculate the prevTR */ + TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); + prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; + prevClose = inClose[today]; + + /* Calculate the DI. The value is rounded (see Wilder book). */ + if( !TA_IS_ZERO(prevTR) ) + outReal[outIdx++] = round_pos(100.0*(prevPlusDM/prevTR)); + else + outReal[outIdx++] = 0.0; + + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::PlusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::PlusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode plusDI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_PLUS_DI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, lookbackTotal, outIdx; +/* Generated */ double prevHigh, prevLow, prevClose; +/* Generated */ double prevPlusDM, prevTR; +/* Generated */ double tempReal, tempReal2, diffP, diffM; +/* Generated */ int i; +/* Generated */ #define TRUE_RANGE(TH,TL,YC,OUT) {\ +/* Generated */ OUT = TH-TL; \ +/* Generated */ tempReal2 = std_fabs(TH-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ tempReal2 = std_fabs(TL-YC); \ +/* Generated */ if( tempReal2 > OUT ) \ +/* Generated */ OUT = tempReal2; \ +/* Generated */ } +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #undef round_pos +/* Generated */ #define round_pos(x) (x) +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DI,PlusDI); +/* Generated */ else +/* Generated */ lookbackTotal = 1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ if( optInTimePeriod <= 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ today = startIdx-1; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ prevClose = inClose[today]; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ if( TA_IS_ZERO(tempReal) ) +/* Generated */ outReal[outIdx++] = (double)0.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = diffP/tempReal; +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[outIdx++] = (double)0.0; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = today = startIdx; +/* Generated */ prevPlusDM = 0.0; +/* Generated */ prevTR = 0.0; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ prevClose = inClose[today]; +/* Generated */ i = optInTimePeriod-1; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR += tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DI,PlusDI) + 1; +/* Generated */ while( i-- != 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ } +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ outReal[0] = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ else +/* Generated */ outReal[0] = 0.0; +/* Generated */ outIdx = 1; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ TRUE_RANGE(prevHigh,prevLow,prevClose,tempReal); +/* Generated */ prevTR = prevTR - (prevTR/optInTimePeriod) + tempReal; +/* Generated */ prevClose = inClose[today]; +/* Generated */ if( !TA_IS_ZERO(prevTR) ) +/* Generated */ outReal[outIdx++] = round_pos(100.0*(prevPlusDM/prevTR)); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_PLUS_DM.c b/talib/ta_func/ta_PLUS_DM.c new file mode 100644 index 0000000..5c41740 --- /dev/null +++ b/talib/ta_func/ta_PLUS_DM.c @@ -0,0 +1,590 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * CF Christo Fogelberg + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 122104 MF,CF Fix#1089506 for when optInTimePeriod is 1. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::PlusDMLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int plusDMLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_PLUS_DM_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + if( optInTimePeriod > 1 ) + return optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM) - 1; + else + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_PLUS_DM - Plus Directional Movement + * + * Input = High, Low + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::PlusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::PlusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode plusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_PLUS_DM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int today, lookbackTotal, outIdx; + double prevHigh, prevLow, tempReal; + double prevPlusDM; + double diffP, diffM; + int i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* + * The DM1 (one period) is base on the largest part of + * today's range that is outside of yesterdays range. + * + * The following 7 cases explain how the +DM and -DM are + * calculated on one period: + * + * Case 1: Case 2: + * C| A| + * | | C| + * | +DM1 = (C-A) B| | +DM1 = 0 + * | -DM1 = 0 | -DM1 = (B-D) + * A| | D| + * | D| + * B| + * + * Case 3: Case 4: + * C| C| + * | A| | + * | +DM1 = (C-A) | | +DM1 = 0 + * | -DM1 = 0 B| | -DM1 = (B-D) + * A| | | + * | | D| + * B| | + * D| + * + * Case 5: Case 6: + * A| A| C| + * | C| +DM1 = 0 | | +DM1 = 0 + * | | -DM1 = 0 | | -DM1 = 0 + * | D| | | + * B| B| D| + * + * + * Case 7: + * + * C| + * A| | + * | | +DM=0 + * B| | -DM=0 + * D| + * + * In case 3 and 4, the rule is that the smallest delta between + * (C-A) and (B-D) determine which of +DM or -DM is zero. + * + * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are + * zero. + * + * The rules remain the same when A=B and C=D (when the highs + * equal the lows). + * + * When calculating the DM over a period > 1, the one-period DM + * for the desired period are initialy sum. In other word, + * for a +DM14, sum the +DM1 for the first 14 days (that's + * 13 values because there is no DM for the first day!) + * Subsequent DM are calculated using the Wilder's + * smoothing approach: + * + * Previous +DM14 + * Today's +DM14 = Previous +DM14 - -------------- + Today's +DM1 + * 14 + * + * Reference: + * New Concepts In Technical Trading Systems, J. Welles Wilder Jr + */ + + if( optInTimePeriod > 1 ) + lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM) - 1; + else + lookbackTotal = 1; + + /* Adjust startIdx to account for the lookback period. */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Indicate where the next output should be put + * in the outReal. + */ + outIdx = 0; + + /* Trap the case where no smoothing is needed. */ + if( optInTimePeriod <= 1 ) + { + /* No smoothing needed. Just do a simple DM1 + * for each price bar. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + today = startIdx-1; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + while( today < endIdx ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + outReal[outIdx++] = diffP; + } + else + outReal[outIdx++] = 0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Process the initial DM */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + prevPlusDM = 0.0; + today = startIdx - lookbackTotal; + prevHigh = inHigh[today]; + prevLow = inLow[today]; + i = optInTimePeriod-1; + while( i-- > 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM += diffP; + } + } + + /* Process subsequent DM */ + + /* Skip the unstable period. */ + i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM); + while( i-- != 0 ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; + } + else + { + /* Case 2,4,5 and 7 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); + } + } + + /* Now start to write the output in + * the caller provided outReal. + */ + outReal[0] = prevPlusDM; + outIdx = 1; + + while( today < endIdx ) + { + today++; + tempReal = inHigh[today]; + diffP = tempReal-prevHigh; /* Plus Delta */ + prevHigh = tempReal; + tempReal = inLow[today]; + diffM = prevLow-tempReal; /* Minus Delta */ + prevLow = tempReal; + + if( (diffP > 0) && (diffP > diffM) ) + { + /* Case 1 and 3: +DM=diffP,-DM=0 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; + } + else + { + /* Case 2,4,5 and 7 */ + prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); + } + + outReal[outIdx++] = prevPlusDM; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::PlusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::PlusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode plusDM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_PLUS_DM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, lookbackTotal, outIdx; +/* Generated */ double prevHigh, prevLow, tempReal; +/* Generated */ double prevPlusDM; +/* Generated */ double diffP, diffM; +/* Generated */ int i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ lookbackTotal = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM) - 1; +/* Generated */ else +/* Generated */ lookbackTotal = 1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ if( optInTimePeriod <= 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ today = startIdx-1; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = diffP; +/* Generated */ } +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ prevPlusDM = 0.0; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ prevHigh = inHigh[today]; +/* Generated */ prevLow = inLow[today]; +/* Generated */ i = optInTimePeriod-1; +/* Generated */ while( i-- > 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM += diffP; +/* Generated */ } +/* Generated */ } +/* Generated */ i = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_PLUS_DM,PlusDM); +/* Generated */ while( i-- != 0 ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ } +/* Generated */ outReal[0] = prevPlusDM; +/* Generated */ outIdx = 1; +/* Generated */ while( today < endIdx ) +/* Generated */ { +/* Generated */ today++; +/* Generated */ tempReal = inHigh[today]; +/* Generated */ diffP = tempReal-prevHigh; +/* Generated */ prevHigh = tempReal; +/* Generated */ tempReal = inLow[today]; +/* Generated */ diffM = prevLow-tempReal; +/* Generated */ prevLow = tempReal; +/* Generated */ if( (diffP > 0) && (diffP > diffM) ) +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod) + diffP; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ prevPlusDM = prevPlusDM - (prevPlusDM/optInTimePeriod); +/* Generated */ } +/* Generated */ outReal[outIdx++] = prevPlusDM; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_PPO.c b/talib/ta_func/ta_PPO.c new file mode 100644 index 0000000..22c3190 --- /dev/null +++ b/talib/ta_func/ta_PPO.c @@ -0,0 +1,365 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AA Andrew Atkinson + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 020605 AA Fix #1117666 Lookback bug. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::PpoLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int ppoLookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_PPO_Lookback( int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Lookback is driven by the slowest MA. */ + return LOOKBACK_CALL(MA)( max(optInSlowPeriod,optInFastPeriod), optInMAType ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_PPO - Percentage Price Oscillator + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInFastPeriod:(From 2 to 100000) + * Number of period for the fast MA + * + * optInSlowPeriod:(From 2 to 100000) + * Number of period for the slow MA + * + * optInMAType: + * Type of Moving Average + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ppo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ppo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ppo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_PPO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_REF(tempBuffer); + ENUM_DECLARATION(RetCode) retCode; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastPeriod. */ +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowPeriod. */ +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Allocate an intermediate buffer. */ + ARRAY_ALLOC( tempBuffer, endIdx-startIdx+1 ); + #if !defined( _JAVA ) + if( !tempBuffer ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + + retCode = FUNCTION_CALL(INT_PO)( startIdx, endIdx, inReal, + optInFastPeriod, + optInSlowPeriod, + optInMAType, + outBegIdx, + outNBElement, + outReal, + tempBuffer, + 1 /* Do percentage processing. */ ); + + ARRAY_FREE( tempBuffer ); + + return retCode; +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Ppo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Ppo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ppo( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ MAType optInMAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_PPO( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInFastPeriod, /* From 2 to 100000 */ +/* Generated */ int optInSlowPeriod, /* From 2 to 100000 */ +/* Generated */ TA_MAType optInMAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(tempBuffer); +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastPeriod = 12; +/* Generated */ else if( ((int)optInFastPeriod < 2) || ((int)optInFastPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInSlowPeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowPeriod = 26; +/* Generated */ else if( ((int)optInSlowPeriod < 2) || ((int)optInSlowPeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInMAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInMAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInMAType < 0) || ((int)optInMAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC( tempBuffer, endIdx-startIdx+1 ); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !tempBuffer ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL(INT_PO)( startIdx, endIdx, inReal, +/* Generated */ optInFastPeriod, +/* Generated */ optInSlowPeriod, +/* Generated */ optInMAType, +/* Generated */ outBegIdx, +/* Generated */ outNBElement, +/* Generated */ outReal, +/* Generated */ tempBuffer, +/* Generated */ 1 ); +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_PVI.c b/talib/ta_func/ta_PVI.c new file mode 100644 index 0000000..86d8691 --- /dev/null +++ b/talib/ta_func/ta_PVI.c @@ -0,0 +1,197 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #using +/* Generated */ #include "Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (TA_INTERNAL_ERROR) +/* Generated */ namespace TA { namespace Library { +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::PVI_Lookback( /* Generated */ void ) +/* Generated */ +/* Generated */ #else +/* Generated */ int TA_PVI_Lookback( /* Generated */ void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert lookback code here. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_PVI - Positive Volume Index + * + * Input = Close, Volume + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ enum Core::TA_RetCode Core::PVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inClose __gc [], +/* Generated */ int inVolume __gc [], +/* Generated */ [OutAttribute]Int32 REF(outBegIdx), +/* Generated */ [OutAttribute]Int32 REF(outNBElement), +/* Generated */ double outReal __gc [] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_PVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inClose[], +/* Generated */ const int inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return TA_OUT_OF_RANGE_START_INDEX; +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return TA_OUT_OF_RANGE_END_INDEX; +/* Generated */ +/* Generated */ /* Validate the parameters. */ +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inClose||!inVolume) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ +/* Generated */ if( outReal == NULL ) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Default return values */ + *outBegIdx = 0; + *outNBElement = 0; + + return TA_SUCCESS; +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #if !defined( _MANAGED ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) +/* Generated */ enum Core::TA_RetCode Core::PVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inClose __gc [], +/* Generated */ int inVolume __gc [], +/* Generated */ [OutAttribute]Int32 REF(outBegIdx), +/* Generated */ [OutAttribute]Int32 REF(outNBElement), +/* Generated */ double outReal __gc [] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_PVI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inClose[], +/* Generated */ const int inVolume[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return TA_OUT_OF_RANGE_START_INDEX; +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return TA_OUT_OF_RANGE_END_INDEX; +/* Generated */ if(!inClose||!inVolume) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ if( outReal == NULL ) +/* Generated */ return TA_BAD_PARAM; +/* Generated */ #endif +/* Generated */ *outBegIdx = 0; +/* Generated */ *outNBElement = 0; +/* Generated */ return TA_SUCCESS; +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }} // Close namespace TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ROC.c b/talib/ta_func/ta_ROC.c new file mode 100644 index 0000000..280caa0 --- /dev/null +++ b/talib/ta_func/ta_ROC.c @@ -0,0 +1,355 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::RocLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int rocLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ROC_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ROC - Rate of change : ((price/prevPrice)-1)*100 + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Roc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Roc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode roc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ROC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int inIdx, outIdx, trailingIdx; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* The interpretation of the rate of change varies widely depending + * which software and/or books you are refering to. + * + * The following is the table of Rate-Of-Change implemented in TA-LIB: + * MOM = (price - prevPrice) [Momentum] + * ROC = ((price/prevPrice)-1)*100 [Rate of change] + * ROCP = (price-prevPrice)/prevPrice [Rate of change Percentage] + * ROCR = (price/prevPrice) [Rate of change ratio] + * ROCR100 = (price/prevPrice)*100 [Rate of change ratio 100 Scale] + * + * Here are the equivalent function in other software: + * TA-Lib | Tradestation | Metastock + * ================================================= + * MOM | Momentum | ROC (Point) + * ROC | ROC | ROC (Percent) + * ROCP | PercentChange | - + * ROCR | - | - + * ROCR100 | - | MO + * + * The MOM function is the only one who is not normalized, and thus + * should be avoided for comparing different time serie of prices. + * + * ROC and ROCP are centered at zero and can have positive and negative + * value. Here are some equivalence: + * ROC = ROCP/100 + * = ((price-prevPrice)/prevPrice)/100 + * = ((price/prevPrice)-1)*100 + * + * ROCR and ROCR100 are ratio respectively centered at 1 and 100 and are + * always positive values. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate Rate of change: ((price / prevPrice)-1)*100 */ + outIdx = 0; + inIdx = startIdx; + trailingIdx = startIdx - optInTimePeriod; + + while( inIdx <= endIdx ) + { + tempReal = inReal[trailingIdx++]; + if( tempReal != 0.0 ) + outReal[outIdx++] = ((inReal[inIdx] / tempReal)-1.0)*100.0; + else + outReal[outIdx++] = 0.0; + inIdx++; + } + + /* Set output limits. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Roc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Roc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode roc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ROC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int inIdx, outIdx, trailingIdx; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ inIdx = startIdx; +/* Generated */ trailingIdx = startIdx - optInTimePeriod; +/* Generated */ while( inIdx <= endIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ if( tempReal != 0.0 ) +/* Generated */ outReal[outIdx++] = ((inReal[inIdx] / tempReal)-1.0)*100.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ inIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ROCP.c b/talib/ta_func/ta_ROCP.c new file mode 100644 index 0000000..dd0f607 --- /dev/null +++ b/talib/ta_func/ta_ROCP.c @@ -0,0 +1,356 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::RocPLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int rocPLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ROCP_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ROCP - Rate of change Percentage: (price-prevPrice)/prevPrice + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::RocP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::RocP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rocP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ROCP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int inIdx, outIdx, trailingIdx; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* The interpretation of the rate of change varies widely depending + * which software and/or books you are refering to. + * + * The following is the table of Rate-Of-Change implemented in TA-LIB: + * MOM = (price - prevPrice) [Momentum] + * ROC = ((price/prevPrice)-1)*100 [Rate of change] + * ROCP = (price-prevPrice)/prevPrice [Rate of change Percentage] + * ROCR = (price/prevPrice) [Rate of change ratio] + * ROCR100 = (price/prevPrice)*100 [Rate of change ratio 100 Scale] + * + * Here are the equivalent function in other software: + * TA-Lib | Tradestation | Metastock + * ================================================= + * MOM | Momentum | ROC (Point) + * ROC | ROC | ROC (Percent) + * ROCP | PercentChange | - + * ROCR | - | - + * ROCR100 | - | MO + * + * The MOM function is the only one who is not normalized, and thus + * should be avoided for comparing different time serie of prices. + * + * ROC and ROCP are centered at zero and can have positive and negative + * value. Here are some equivalence: + * ROC = ROCP/100 + * = ((price-prevPrice)/prevPrice)/100 + * = ((price/prevPrice)-1)*100 + * + * ROCR and ROCR100 are ratio respectively centered at 1 and 100 and are + * always positive values. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate Rate of change Ratio: (price / prevPrice) */ + outIdx = 0; + inIdx = startIdx; + trailingIdx = startIdx - optInTimePeriod; + + while( inIdx <= endIdx ) + { + tempReal = inReal[trailingIdx++]; + if( tempReal != 0.0 ) + outReal[outIdx++] = (inReal[inIdx]-tempReal)/tempReal; + else + outReal[outIdx++] = 0.0; + + inIdx++; + } + + /* Set output limits. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::RocP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::RocP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rocP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ROCP( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int inIdx, outIdx, trailingIdx; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ inIdx = startIdx; +/* Generated */ trailingIdx = startIdx - optInTimePeriod; +/* Generated */ while( inIdx <= endIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ if( tempReal != 0.0 ) +/* Generated */ outReal[outIdx++] = (inReal[inIdx]-tempReal)/tempReal; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ inIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ROCR.c b/talib/ta_func/ta_ROCR.c new file mode 100644 index 0000000..be8863f --- /dev/null +++ b/talib/ta_func/ta_ROCR.c @@ -0,0 +1,357 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::RocRLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int rocRLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ROCR_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ROCR - Rate of change ratio: (price/prevPrice) + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::RocR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::RocR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rocR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ROCR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + + int inIdx, outIdx, trailingIdx; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* The interpretation of the rate of change varies widely depending + * which software and/or books you are refering to. + * + * The following is the table of Rate-Of-Change implemented in TA-LIB: + * MOM = (price - prevPrice) [Momentum] + * ROC = ((price/prevPrice)-1)*100 [Rate of change] + * ROCP = (price-prevPrice)/prevPrice [Rate of change Percentage] + * ROCR = (price/prevPrice) [Rate of change ratio] + * ROCR100 = (price/prevPrice)*100 [Rate of change ratio 100 Scale] + * + * Here are the equivalent function in other software: + * TA-Lib | Tradestation | Metastock + * ================================================= + * MOM | Momentum | ROC (Point) + * ROC | ROC | ROC (Percent) + * ROCP | PercentChange | - + * ROCR | - | - + * ROCR100 | - | MO + * + * The MOM function is the only one who is not normalized, and thus + * should be avoided for comparing different time serie of prices. + * + * ROC and ROCP are centered at zero and can have positive and negative + * value. Here are some equivalence: + * ROC = ROCP/100 + * = ((price-prevPrice)/prevPrice)/100 + * = ((price/prevPrice)-1)*100 + * + * ROCR and ROCR100 are ratio respectively centered at 1 and 100 and are + * always positive values. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate Rate of change Ratio: (price / prevPrice) */ + outIdx = 0; + inIdx = startIdx; + trailingIdx = startIdx - optInTimePeriod; + + while( inIdx <= endIdx ) + { + tempReal = inReal[trailingIdx++]; + if( tempReal != 0.0 ) + outReal[outIdx++] = (inReal[inIdx] / tempReal); + else + outReal[outIdx++] = 0.0; + + inIdx++; + } + + /* Set output limits. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::RocR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::RocR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rocR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ROCR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int inIdx, outIdx, trailingIdx; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ inIdx = startIdx; +/* Generated */ trailingIdx = startIdx - optInTimePeriod; +/* Generated */ while( inIdx <= endIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ if( tempReal != 0.0 ) +/* Generated */ outReal[outIdx++] = (inReal[inIdx] / tempReal); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ inIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ROCR100.c b/talib/ta_func/ta_ROCR100.c new file mode 100644 index 0000000..4ce4e16 --- /dev/null +++ b/talib/ta_func/ta_ROCR100.c @@ -0,0 +1,356 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::RocR100Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int rocR100Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ROCR100_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ROCR100 - Rate of change ratio 100 scale: (price/prevPrice)*100 + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::RocR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::RocR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rocR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ROCR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int inIdx, outIdx, trailingIdx; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* The interpretation of the rate of change varies widely depending + * which software and/or books you are refering to. + * + * The following is the table of Rate-Of-Change implemented in TA-LIB: + * MOM = (price - prevPrice) [Momentum] + * ROC = ((price/prevPrice)-1)*100 [Rate of change] + * ROCP = (price-prevPrice)/prevPrice [Rate of change Percentage] + * ROCR = (price/prevPrice) [Rate of change ratio] + * ROCR100 = (price/prevPrice)*100 [Rate of change ratio 100 Scale] + * + * Here are the equivalent function in other software: + * TA-Lib | Tradestation | Metastock + * ================================================= + * MOM | Momentum | ROC (Point) + * ROC | ROC | ROC (Percent) + * ROCP | PercentChange | - + * ROCR | - | - + * ROCR100 | - | MO + * + * The MOM function is the only one who is not normalized, and thus + * should be avoided for comparing different time serie of prices. + * + * ROC and ROCP are centered at zero and can have positive and negative + * value. Here are some equivalence: + * ROC = ROCP/100 + * = ((price-prevPrice)/prevPrice)/100 + * = ((price/prevPrice)-1)*100 + * + * ROCR and ROCR100 are ratio respectively centered at 1 and 100 and are + * always positive values. + */ + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < optInTimePeriod ) + startIdx = optInTimePeriod; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate Rate of change Ratio: (price / prevPrice) */ + outIdx = 0; + inIdx = startIdx; + trailingIdx = startIdx - optInTimePeriod; + + while( inIdx <= endIdx ) + { + tempReal = inReal[trailingIdx++]; + if( tempReal != 0.0 ) + outReal[outIdx++] = (inReal[inIdx] / tempReal)*100.0; + else + outReal[outIdx++] = 0.0; + + inIdx++; + } + + /* Set output limits. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::RocR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::RocR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rocR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ROCR100( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int inIdx, outIdx, trailingIdx; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 10; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < optInTimePeriod ) +/* Generated */ startIdx = optInTimePeriod; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ inIdx = startIdx; +/* Generated */ trailingIdx = startIdx - optInTimePeriod; +/* Generated */ while( inIdx <= endIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ if( tempReal != 0.0 ) +/* Generated */ outReal[outIdx++] = (inReal[inIdx] / tempReal)*100.0; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ inIdx++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_RSI.c b/talib/ta_func/ta_RSI.c new file mode 100644 index 0000000..45361a6 --- /dev/null +++ b/talib/ta_func/ta_RSI.c @@ -0,0 +1,615 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 062804 MF Resolve div by zero bug on limit case. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::RsiLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int rsiLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_RSI_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + retValue = optInTimePeriod + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_RSI,Rsi); + if( TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_METASTOCK,Metastock) ) + retValue--; + + return retValue; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_RSI - Relative Strength Index + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Rsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Rsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_RSI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int outIdx; + + int today, lookbackTotal, unstablePeriod, i; + double prevGain, prevLoss, prevValue, savePrevValue; + double tempValue1, tempValue2; + + #if defined( USE_SINGLE_PRECISION_INPUT ) + ARRAY_MEMMOVEMIX_VAR; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* The following algorithm is base on the original + * work from Wilder's and shall represent the + * original idea behind the classic RSI. + * + * Metastock is starting the calculation one price + * bar earlier. To make this possible, they assume + * that the very first bar will be identical to the + * previous one (no gain or loss). + */ + + /* If changing this function, please check also CMO + * which is mostly identical (just different in one step + * of calculation). + */ + + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(RSI)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + outIdx = 0; /* Index into the output. */ + + /* Trap special case where the period is '1'. + * In that case, just copy the input into the + * output for the requested range (as-is !) + */ + if( optInTimePeriod == 1 ) + { + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + i = (endIdx-startIdx)+1; + VALUE_HANDLE_DEREF(outNBElement) = i; + #if defined( USE_SINGLE_PRECISION_INPUT ) + ARRAY_MEMMOVEMIX( outReal, 0, inReal, startIdx, i ); + #else + ARRAY_MEMMOVE( outReal, 0, inReal, startIdx, i ); + #endif + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Accumulate Wilder's "Average Gain" and "Average Loss" + * among the initial period. + */ + today = startIdx-lookbackTotal; + prevValue = inReal[today]; + + unstablePeriod = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_RSI,Rsi); + + /* If there is no unstable period, + * calculate the 'additional' initial + * price bar who is particuliar to + * metastock. + * If there is an unstable period, + * no need to calculate since this + * first value will be surely skip. + */ + if( (unstablePeriod == 0) && + (TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_METASTOCK,Metastock))) + { + /* Preserve prevValue because it may get + * overwritten by the output. + *(because output ptr could be the same as input ptr). + */ + savePrevValue = prevValue; + + /* No unstable period, so must calculate first output + * particular to Metastock. + * (Metastock re-use the first price bar, so there + * is no loss/gain at first. Beats me why they + * are doing all this). + */ + prevGain = 0.0; + prevLoss = 0.0; + for( i=optInTimePeriod; i > 0; i-- ) + { + tempValue1 = inReal[today++]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + } + + + tempValue1 = prevLoss/optInTimePeriod; + tempValue2 = prevGain/optInTimePeriod; + + /* Write the output. */ + tempValue1 = tempValue2+tempValue1; + if( !TA_IS_ZERO(tempValue1) ) + outReal[outIdx++] = 100*(tempValue2/tempValue1); + else + outReal[outIdx++] = 0.0; + + /* Are we done? */ + if( today > endIdx ) + { + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Start over for the next price bar. */ + today -= optInTimePeriod; + prevValue = savePrevValue; + } + + + /* Remaining of the processing is identical + * for both Classic calculation and Metastock. + */ + prevGain = 0.0; + prevLoss = 0.0; + today++; + for( i=optInTimePeriod; i > 0; i-- ) + { + tempValue1 = inReal[today++]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + } + + + /* Subsequent prevLoss and prevGain are smoothed + * using the previous values (Wilder's approach). + * 1) Multiply the previous by 'period-1'. + * 2) Add today value. + * 3) Divide by 'period'. + */ + prevLoss /= optInTimePeriod; + prevGain /= optInTimePeriod; + + /* Often documentation present the RSI calculation as follow: + * RSI = 100 - (100 / 1 + (prevGain/prevLoss)) + * + * The following is equivalent: + * RSI = 100 * (prevGain/(prevGain+prevLoss)) + * + * The second equation is used here for speed optimization. + */ + if( today > startIdx ) + { + tempValue1 = prevGain+prevLoss; + if( !TA_IS_ZERO(tempValue1) ) + outReal[outIdx++] = 100.0*(prevGain/tempValue1); + else + outReal[outIdx++] = 0.0; + } + else + { + /* Skip the unstable period. Do the processing + * but do not write it in the output. + */ + while( today < startIdx ) + { + tempValue1 = inReal[today]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + + prevLoss *= (optInTimePeriod-1); + prevGain *= (optInTimePeriod-1); + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + + prevLoss /= optInTimePeriod; + prevGain /= optInTimePeriod; + + today++; + } + } + + /* Unstable period skipped... now continue + * processing if needed. + */ + while( today <= endIdx ) + { + tempValue1 = inReal[today++]; + tempValue2 = tempValue1 - prevValue; + prevValue = tempValue1; + + prevLoss *= (optInTimePeriod-1); + prevGain *= (optInTimePeriod-1); + if( tempValue2 < 0 ) + prevLoss -= tempValue2; + else + prevGain += tempValue2; + + prevLoss /= optInTimePeriod; + prevGain /= optInTimePeriod; + tempValue1 = prevGain+prevLoss; + if( !TA_IS_ZERO(tempValue1) ) + outReal[outIdx++] = 100.0*(prevGain/tempValue1); + else + outReal[outIdx++] = 0.0; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Rsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Rsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode rsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_RSI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal, unstablePeriod, i; +/* Generated */ double prevGain, prevLoss, prevValue, savePrevValue; +/* Generated */ double tempValue1, tempValue2; +/* Generated */ #if defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ ARRAY_MEMMOVEMIX_VAR; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackTotal = LOOKBACK_CALL(RSI)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ outIdx = 0; +/* Generated */ if( optInTimePeriod == 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ i = (endIdx-startIdx)+1; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = i; +/* Generated */ #if defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ ARRAY_MEMMOVEMIX( outReal, 0, inReal, startIdx, i ); +/* Generated */ #else +/* Generated */ ARRAY_MEMMOVE( outReal, 0, inReal, startIdx, i ); +/* Generated */ #endif +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ today = startIdx-lookbackTotal; +/* Generated */ prevValue = inReal[today]; +/* Generated */ unstablePeriod = TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_RSI,Rsi); +/* Generated */ if( (unstablePeriod == 0) && +/* Generated */ (TA_GLOBALS_COMPATIBILITY == ENUM_VALUE(Compatibility,TA_COMPATIBILITY_METASTOCK,Metastock))) +/* Generated */ { +/* Generated */ savePrevValue = prevValue; +/* Generated */ prevGain = 0.0; +/* Generated */ prevLoss = 0.0; +/* Generated */ for( i=optInTimePeriod; i > 0; i-- ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today++]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ } +/* Generated */ tempValue1 = prevLoss/optInTimePeriod; +/* Generated */ tempValue2 = prevGain/optInTimePeriod; +/* Generated */ tempValue1 = tempValue2+tempValue1; +/* Generated */ if( !TA_IS_ZERO(tempValue1) ) +/* Generated */ outReal[outIdx++] = 100*(tempValue2/tempValue1); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ if( today > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ today -= optInTimePeriod; +/* Generated */ prevValue = savePrevValue; +/* Generated */ } +/* Generated */ prevGain = 0.0; +/* Generated */ prevLoss = 0.0; +/* Generated */ today++; +/* Generated */ for( i=optInTimePeriod; i > 0; i-- ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today++]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ } +/* Generated */ prevLoss /= optInTimePeriod; +/* Generated */ prevGain /= optInTimePeriod; +/* Generated */ if( today > startIdx ) +/* Generated */ { +/* Generated */ tempValue1 = prevGain+prevLoss; +/* Generated */ if( !TA_IS_ZERO(tempValue1) ) +/* Generated */ outReal[outIdx++] = 100.0*(prevGain/tempValue1); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ while( today < startIdx ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ prevLoss *= (optInTimePeriod-1); +/* Generated */ prevGain *= (optInTimePeriod-1); +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ prevLoss /= optInTimePeriod; +/* Generated */ prevGain /= optInTimePeriod; +/* Generated */ today++; +/* Generated */ } +/* Generated */ } +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tempValue1 = inReal[today++]; +/* Generated */ tempValue2 = tempValue1 - prevValue; +/* Generated */ prevValue = tempValue1; +/* Generated */ prevLoss *= (optInTimePeriod-1); +/* Generated */ prevGain *= (optInTimePeriod-1); +/* Generated */ if( tempValue2 < 0 ) +/* Generated */ prevLoss -= tempValue2; +/* Generated */ else +/* Generated */ prevGain += tempValue2; +/* Generated */ prevLoss /= optInTimePeriod; +/* Generated */ prevGain /= optInTimePeriod; +/* Generated */ tempValue1 = prevGain+prevLoss; +/* Generated */ if( !TA_IS_ZERO(tempValue1) ) +/* Generated */ outReal[outIdx++] = 100.0*(prevGain/tempValue1); +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SAR.c b/talib/ta_func/ta_SAR.c new file mode 100644 index 0000000..4b0c5d3 --- /dev/null +++ b/talib/ta_func/ta_SAR.c @@ -0,0 +1,722 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * CF Christo Fogelberg + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 122104 MF,CF Fix#1089506 for out-of-bound access to ep_temp. + */ + +/* SAR_ROUNDING is just for test purpose when cross-referencing that + * function with example from Wilder's book. Wilder is using two + * decimal rounding for simplification. TA-Lib does not round. + */ +/* #define SAR_ROUNDING(x) x=round_pos_2(x) */ +#define SAR_ROUNDING(x) + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SarLookback( double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int sarLookback( double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SAR_Lookback( double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInAcceleration == TA_REAL_DEFAULT ) +/* Generated */ optInAcceleration = 2.000000e-2; +/* Generated */ else if( (optInAcceleration < 0.000000e+0) ||/* Generated */ (optInAcceleration > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInMaximum == TA_REAL_DEFAULT ) +/* Generated */ optInMaximum = 2.000000e-1; +/* Generated */ else if( (optInMaximum < 0.000000e+0) ||/* Generated */ (optInMaximum > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInAcceleration); + UNUSED_VARIABLE(optInMaximum); + + /* SAR always sacrify one price bar to establish the + * initial extreme price. + */ + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SAR - Parabolic SAR + * + * Input = High, Low + * Output = double + * + * Optional Parameters + * ------------------- + * optInAcceleration:(From 0 to TA_REAL_MAX) + * Acceleration Factor used up to the Maximum value + * + * optInMaximum:(From 0 to TA_REAL_MAX) + * Acceleration Factor Maximum value + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ENUM_DECLARATION(RetCode) retCode; + + int isLong; /* > 0 indicates long. == 0 indicates short */ + int todayIdx, outIdx; + + VALUE_HANDLE_INT(tempInt); + + double newHigh, newLow, prevHigh, prevLow; + double af, ep, sar; + ARRAY_LOCAL(ep_temp,1); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInAcceleration == TA_REAL_DEFAULT ) +/* Generated */ optInAcceleration = 2.000000e-2; +/* Generated */ else if( (optInAcceleration < 0.000000e+0) ||/* Generated */ (optInAcceleration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInMaximum == TA_REAL_DEFAULT ) +/* Generated */ optInMaximum = 2.000000e-1; +/* Generated */ else if( (optInMaximum < 0.000000e+0) ||/* Generated */ (optInMaximum > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Implementation of the SAR has been a little bit open to interpretation + * since Wilder (the original author) did not define a precise algorithm + * on how to bootstrap the algorithm. Take any existing software application + * and you will see slight variation on how the algorithm was adapted. + * + * What is the initial trade direction? Long or short? + * =================================================== + * The interpretation of what should be the initial SAR values is + * open to interpretation, particularly since the caller to the function + * does not specify the initial direction of the trade. + * + * In TA-Lib, the following logic is used: + * - Calculate +DM and -DM between the first and + * second bar. The highest directional indication will + * indicate the assumed direction of the trade for the second + * price bar. + * - In the case of a tie between +DM and -DM, + * the direction is LONG by default. + * + * What is the initial "extreme point" and thus SAR? + * ================================================= + * The following shows how different people took different approach: + * - Metastock use the first price bar high/low depending of + * the direction. No SAR is calculated for the first price + * bar. + * - Tradestation use the closing price of the second bar. No + * SAR are calculated for the first price bar. + * - Wilder (the original author) use the SIP from the + * previous trade (cannot be implement here since the + * direction and length of the previous trade is unknonw). + * - The Magazine TASC seems to follow Wilder approach which + * is not practical here. + * + * TA-Lib "consume" the first price bar and use its high/low as the + * initial SAR of the second price bar. I found that approach to be + * the closest to Wilders idea of having the first entry day use + * the previous extreme point, except that here the extreme point is + * derived solely from the first price bar. I found the same approach + * to be used by Metastock. + */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + * + * Move up the start index if there is not + * enough initial data. + */ + if( startIdx < 1 ) + startIdx = 1; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Make sure the acceleration and maximum are coherent. + * If not, correct the acceleration. + */ + af = optInAcceleration; + if( af > optInMaximum ) + af = optInAcceleration = optInMaximum; + + /* Identify if the initial direction is long or short. + * (ep is just used as a temp buffer here, the name + * of the parameter is not significant). + */ + retCode = FUNCTION_CALL(MINUS_DM)( startIdx, startIdx, inHigh, inLow, 1, + VALUE_HANDLE_OUT(tempInt), VALUE_HANDLE_OUT(tempInt), + ep_temp ); + if( ep_temp[0] > 0 ) + isLong = 0; + else + isLong = 1; + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + outIdx = 0; + + /* Write the first SAR. */ + todayIdx = startIdx; + + newHigh = inHigh[todayIdx-1]; + newLow = inLow[todayIdx-1]; + + SAR_ROUNDING(newHigh); + SAR_ROUNDING(newLow); + + if( isLong == 1 ) + { + ep = inHigh[todayIdx]; + sar = newLow; + } + else + { + ep = inLow[todayIdx]; + sar = newHigh; + } + + SAR_ROUNDING(sar); + + /* Cheat on the newLow and newHigh for the + * first iteration. + */ + newLow = inLow[todayIdx]; + newHigh = inHigh[todayIdx]; + + while( todayIdx <= endIdx ) + { + prevLow = newLow; + prevHigh = newHigh; + newLow = inLow[todayIdx]; + newHigh = inHigh[todayIdx]; + todayIdx++; + + SAR_ROUNDING(newLow); + SAR_ROUNDING(newHigh); + + if( isLong == 1 ) + { + /* Switch to short if the low penetrates the SAR value. */ + if( newLow <= sar ) + { + /* Switch and Overide the SAR with the ep */ + isLong = 0; + sar = ep; + + /* Make sure the overide SAR is within + * yesterday's and today's range. + */ + if( sar < prevHigh ) + sar = prevHigh; + if( sar < newHigh ) + sar = newHigh; + + /* Output the overide SAR */ + outReal[outIdx++] = sar; + + /* Adjust af and ep */ + af = optInAcceleration; + ep = newLow; + + /* Calculate the new SAR */ + sar = sar + af * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar < prevHigh ) + sar = prevHigh; + if( sar < newHigh ) + sar = newHigh; + } + else + { + /* No switch */ + + /* Output the SAR (was calculated in the previous iteration) */ + outReal[outIdx++] = sar; + + /* Adjust af and ep. */ + if( newHigh > ep ) + { + ep = newHigh; + af += optInAcceleration; + if( af > optInMaximum ) + af = optInMaximum; + } + + /* Calculate the new SAR */ + sar = sar + af * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar > prevLow ) + sar = prevLow; + if( sar > newLow ) + sar = newLow; + } + } + else + { + /* Switch to long if the high penetrates the SAR value. */ + if( newHigh >= sar ) + { + /* Switch and Overide the SAR with the ep */ + isLong = 1; + sar = ep; + + /* Make sure the overide SAR is within + * yesterday's and today's range. + */ + if( sar > prevLow ) + sar = prevLow; + if( sar > newLow ) + sar = newLow; + + /* Output the overide SAR */ + outReal[outIdx++] = sar; + + /* Adjust af and ep */ + af = optInAcceleration; + ep = newHigh; + + /* Calculate the new SAR */ + sar = sar + af * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar > prevLow ) + sar = prevLow; + if( sar > newLow ) + sar = newLow; + } + else + { + /* No switch */ + + /* Output the SAR (was calculated in the previous iteration) */ + outReal[outIdx++] = sar; + + /* Adjust af and ep. */ + if( newLow < ep ) + { + ep = newLow; + af += optInAcceleration; + if( af > optInMaximum ) + af = optInMaximum; + } + + /* Calculate the new SAR */ + sar = sar + af * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar < prevHigh ) + sar = prevHigh; + if( sar < newHigh ) + sar = newHigh; + } + } + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sar( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ double optInAcceleration, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInMaximum, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int isLong; +/* Generated */ int todayIdx, outIdx; +/* Generated */ VALUE_HANDLE_INT(tempInt); +/* Generated */ double newHigh, newLow, prevHigh, prevLow; +/* Generated */ double af, ep, sar; +/* Generated */ ARRAY_LOCAL(ep_temp,1); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInAcceleration == TA_REAL_DEFAULT ) +/* Generated */ optInAcceleration = 2.000000e-2; +/* Generated */ else if( (optInAcceleration < 0.000000e+0) || (optInAcceleration > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInMaximum == TA_REAL_DEFAULT ) +/* Generated */ optInMaximum = 2.000000e-1; +/* Generated */ else if( (optInMaximum < 0.000000e+0) || (optInMaximum > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < 1 ) +/* Generated */ startIdx = 1; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ af = optInAcceleration; +/* Generated */ if( af > optInMaximum ) +/* Generated */ af = optInAcceleration = optInMaximum; +/* Generated */ retCode = FUNCTION_CALL(MINUS_DM)( startIdx, startIdx, inHigh, inLow, 1, +/* Generated */ VALUE_HANDLE_OUT(tempInt), VALUE_HANDLE_OUT(tempInt), +/* Generated */ ep_temp ); +/* Generated */ if( ep_temp[0] > 0 ) +/* Generated */ isLong = 0; +/* Generated */ else +/* Generated */ isLong = 1; +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ todayIdx = startIdx; +/* Generated */ newHigh = inHigh[todayIdx-1]; +/* Generated */ newLow = inLow[todayIdx-1]; +/* Generated */ SAR_ROUNDING(newHigh); +/* Generated */ SAR_ROUNDING(newLow); +/* Generated */ if( isLong == 1 ) +/* Generated */ { +/* Generated */ ep = inHigh[todayIdx]; +/* Generated */ sar = newLow; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ ep = inLow[todayIdx]; +/* Generated */ sar = newHigh; +/* Generated */ } +/* Generated */ SAR_ROUNDING(sar); +/* Generated */ newLow = inLow[todayIdx]; +/* Generated */ newHigh = inHigh[todayIdx]; +/* Generated */ while( todayIdx <= endIdx ) +/* Generated */ { +/* Generated */ prevLow = newLow; +/* Generated */ prevHigh = newHigh; +/* Generated */ newLow = inLow[todayIdx]; +/* Generated */ newHigh = inHigh[todayIdx]; +/* Generated */ todayIdx++; +/* Generated */ SAR_ROUNDING(newLow); +/* Generated */ SAR_ROUNDING(newHigh); +/* Generated */ if( isLong == 1 ) +/* Generated */ { +/* Generated */ if( newLow <= sar ) +/* Generated */ { +/* Generated */ isLong = 0; +/* Generated */ sar = ep; +/* Generated */ if( sar < prevHigh ) +/* Generated */ sar = prevHigh; +/* Generated */ if( sar < newHigh ) +/* Generated */ sar = newHigh; +/* Generated */ outReal[outIdx++] = sar; +/* Generated */ af = optInAcceleration; +/* Generated */ ep = newLow; +/* Generated */ sar = sar + af * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar < prevHigh ) +/* Generated */ sar = prevHigh; +/* Generated */ if( sar < newHigh ) +/* Generated */ sar = newHigh; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ outReal[outIdx++] = sar; +/* Generated */ if( newHigh > ep ) +/* Generated */ { +/* Generated */ ep = newHigh; +/* Generated */ af += optInAcceleration; +/* Generated */ if( af > optInMaximum ) +/* Generated */ af = optInMaximum; +/* Generated */ } +/* Generated */ sar = sar + af * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar > prevLow ) +/* Generated */ sar = prevLow; +/* Generated */ if( sar > newLow ) +/* Generated */ sar = newLow; +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ if( newHigh >= sar ) +/* Generated */ { +/* Generated */ isLong = 1; +/* Generated */ sar = ep; +/* Generated */ if( sar > prevLow ) +/* Generated */ sar = prevLow; +/* Generated */ if( sar > newLow ) +/* Generated */ sar = newLow; +/* Generated */ outReal[outIdx++] = sar; +/* Generated */ af = optInAcceleration; +/* Generated */ ep = newHigh; +/* Generated */ sar = sar + af * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar > prevLow ) +/* Generated */ sar = prevLow; +/* Generated */ if( sar > newLow ) +/* Generated */ sar = newLow; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ outReal[outIdx++] = sar; +/* Generated */ if( newLow < ep ) +/* Generated */ { +/* Generated */ ep = newLow; +/* Generated */ af += optInAcceleration; +/* Generated */ if( af > optInMaximum ) +/* Generated */ af = optInMaximum; +/* Generated */ } +/* Generated */ sar = sar + af * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar < prevHigh ) +/* Generated */ sar = prevHigh; +/* Generated */ if( sar < newHigh ) +/* Generated */ sar = newHigh; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SAREXT.c b/talib/ta_func/ta_SAREXT.c new file mode 100644 index 0000000..33a92c4 --- /dev/null +++ b/talib/ta_func/ta_SAREXT.c @@ -0,0 +1,1002 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * PP Peter Pudaite + * CF Christo Fogelberg + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 091503 PP Reworked TA_SAR to allow customisation of more SAR params. + * 092103 MF Some changes related on first round of tests + * 092303 PP Minor bug fixes. + * 122104 MF,CF Fix#1089506 for out-of-bound access to ep_temp. + * + */ + +/* SAR_ROUNDING is just for test purpose when cross-referencing that + * function with example from Wilder's book. Wilder is using two + * decimal rounding for simplification. TA-Lib does not round. + */ +/* #define SAR_ROUNDING(x) x=round_pos_2(x) */ +#define SAR_ROUNDING(x) + + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SarExtLookback( double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int sarExtLookback( double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SAREXT_Lookback( double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort ) /* From 0 to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( optInStartValue == TA_REAL_DEFAULT ) +/* Generated */ optInStartValue = 0.000000e+0; +/* Generated */ else if( (optInStartValue < -3.000000e+37) ||/* Generated */ (optInStartValue > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInOffsetOnReverse == TA_REAL_DEFAULT ) +/* Generated */ optInOffsetOnReverse = 0.000000e+0; +/* Generated */ else if( (optInOffsetOnReverse < 0.000000e+0) ||/* Generated */ (optInOffsetOnReverse > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInAccelerationInitLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationInitLong = 2.000000e-2; +/* Generated */ else if( (optInAccelerationInitLong < 0.000000e+0) ||/* Generated */ (optInAccelerationInitLong > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInAccelerationLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationLong = 2.000000e-2; +/* Generated */ else if( (optInAccelerationLong < 0.000000e+0) ||/* Generated */ (optInAccelerationLong > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInAccelerationMaxLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationMaxLong = 2.000000e-1; +/* Generated */ else if( (optInAccelerationMaxLong < 0.000000e+0) ||/* Generated */ (optInAccelerationMaxLong > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInAccelerationInitShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationInitShort = 2.000000e-2; +/* Generated */ else if( (optInAccelerationInitShort < 0.000000e+0) ||/* Generated */ (optInAccelerationInitShort > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInAccelerationShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationShort = 2.000000e-2; +/* Generated */ else if( (optInAccelerationShort < 0.000000e+0) ||/* Generated */ (optInAccelerationShort > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInAccelerationMaxShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationMaxShort = 2.000000e-1; +/* Generated */ else if( (optInAccelerationMaxShort < 0.000000e+0) ||/* Generated */ (optInAccelerationMaxShort > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInStartValue); + UNUSED_VARIABLE(optInOffsetOnReverse); + UNUSED_VARIABLE(optInAccelerationInitLong); + UNUSED_VARIABLE(optInAccelerationLong); + UNUSED_VARIABLE(optInAccelerationMaxLong); + UNUSED_VARIABLE(optInAccelerationInitShort); + UNUSED_VARIABLE(optInAccelerationShort); + UNUSED_VARIABLE(optInAccelerationMaxShort); + + /* SAR always sacrifices one price bar to establish the + * initial extreme price. + */ + + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SAREXT - Parabolic SAR - Extended + * + * Input = High, Low + * Output = double + * + * Optional Parameters + * ------------------- + * optInStartValue:(From TA_REAL_MIN to TA_REAL_MAX) + * Start value and direction. 0 for Auto, >0 for Long, <0 for Short + * + * optInOffsetOnReverse:(From 0 to TA_REAL_MAX) + * Percent offset added/removed to initial stop on short/long reversal + * + * optInAccelerationInitLong:(From 0 to TA_REAL_MAX) + * Acceleration Factor initial value for the Long direction + * + * optInAccelerationLong:(From 0 to TA_REAL_MAX) + * Acceleration Factor for the Long direction + * + * optInAccelerationMaxLong:(From 0 to TA_REAL_MAX) + * Acceleration Factor maximum value for the Long direction + * + * optInAccelerationInitShort:(From 0 to TA_REAL_MAX) + * Acceleration Factor initial value for the Short direction + * + * optInAccelerationShort:(From 0 to TA_REAL_MAX) + * Acceleration Factor for the Short direction + * + * optInAccelerationMaxShort:(From 0 to TA_REAL_MAX) + * Acceleration Factor maximum value for the Short direction + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::SarExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::SarExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sarExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SAREXT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ENUM_DECLARATION(RetCode) retCode; + + int isLong; /* > 0 indicates long. == 0 indicates short */ + int todayIdx, outIdx; + + VALUE_HANDLE_INT(tempInt); + + double newHigh, newLow, prevHigh, prevLow; + double afLong, afShort, ep, sar; + ARRAY_LOCAL(ep_temp,1); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ if( optInStartValue == TA_REAL_DEFAULT ) +/* Generated */ optInStartValue = 0.000000e+0; +/* Generated */ else if( (optInStartValue < -3.000000e+37) ||/* Generated */ (optInStartValue > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInOffsetOnReverse == TA_REAL_DEFAULT ) +/* Generated */ optInOffsetOnReverse = 0.000000e+0; +/* Generated */ else if( (optInOffsetOnReverse < 0.000000e+0) ||/* Generated */ (optInOffsetOnReverse > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInAccelerationInitLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationInitLong = 2.000000e-2; +/* Generated */ else if( (optInAccelerationInitLong < 0.000000e+0) ||/* Generated */ (optInAccelerationInitLong > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInAccelerationLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationLong = 2.000000e-2; +/* Generated */ else if( (optInAccelerationLong < 0.000000e+0) ||/* Generated */ (optInAccelerationLong > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInAccelerationMaxLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationMaxLong = 2.000000e-1; +/* Generated */ else if( (optInAccelerationMaxLong < 0.000000e+0) ||/* Generated */ (optInAccelerationMaxLong > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInAccelerationInitShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationInitShort = 2.000000e-2; +/* Generated */ else if( (optInAccelerationInitShort < 0.000000e+0) ||/* Generated */ (optInAccelerationInitShort > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInAccelerationShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationShort = 2.000000e-2; +/* Generated */ else if( (optInAccelerationShort < 0.000000e+0) ||/* Generated */ (optInAccelerationShort > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInAccelerationMaxShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationMaxShort = 2.000000e-1; +/* Generated */ else if( (optInAccelerationMaxShort < 0.000000e+0) ||/* Generated */ (optInAccelerationMaxShort > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* This function is the same as TA_SAR, except that the caller has + * greater control on the SAR dynamic and initial state. + * + * In additon, the TA_SAREXT returns negative values when the position + * is short. This allow to distinguish when the SAR do actually reverse. + */ + + /* Implementation of the SAR has been a little bit open to interpretation + * since Wilder (the original author) did not define a precise algorithm + * on how to bootstrap the algorithm. Take any existing software application + * and you will see slight variation on how the algorithm was adapted. + * + * What is the initial trade direction? Long or short? + * =================================================== + * The interpretation of what should be the initial SAR values is + * open to interpretation, particularly since the caller to the function + * does not specify the initial direction of the trade. + * + * In TA-Lib, the following default logic is used: + * - Calculate +DM and -DM between the first and + * second bar. The highest directional indication will + * indicate the assumed direction of the trade for the second + * price bar. + * - In the case of a tie between +DM and -DM, + * the direction is LONG by default. + * + * What is the initial "extreme point" and thus SAR? + * ================================================= + * The following shows how different people took different approach: + * - Metastock use the first price bar high/low depending of + * the direction. No SAR is calculated for the first price + * bar. + * - Tradestation use the closing price of the second bar. No + * SAR are calculated for the first price bar. + * - Wilder (the original author) use the SIP from the + * previous trade (cannot be implement here since the + * direction and length of the previous trade is unknonw). + * - The Magazine TASC seems to follow Wilder approach which + * is not practical here. + * + * TA-Lib "consume" the first price bar and use its high/low as the + * initial SAR of the second price bar. I found that approach to be + * the closest to Wilders idea of having the first entry day use + * the previous extreme point, except that here the extreme point is + * derived solely from the first price bar. I found the same approach + * to be used by Metastock. + * + * + * Can I force the initial SAR? + * ============================ + * Yes. Using the optInStartValue_0 parameter: + * optInStartValue_0 > 0 : SAR is long at optInStartValue_0. + * optInStartValue_0 < 0 : SAR is short at fabs(optInStartValue_0). + * + * And when optInStartValue_0 == 0, the logic is the same as for TA_SAR + * (See previous two sections). + */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + * + * Move up the start index if there is not + * enough initial data. + */ + if( startIdx < 1 ) + startIdx = 1; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + + /* Check if the acceleration factors are being defined by the user. + * Make sure the acceleration and maximum are coherent. + * If not, correct the acceleration. + * Default afLong = 0.02 + * Default afShort = 0.02 + */ + + afLong = optInAccelerationInitLong; + afShort = optInAccelerationInitShort; + + if( afLong > optInAccelerationMaxLong ) + afLong = optInAccelerationInitLong = optInAccelerationMaxLong; + + if( optInAccelerationLong > optInAccelerationMaxLong ) + optInAccelerationLong = optInAccelerationMaxLong; + + if( afShort > optInAccelerationMaxShort) + afShort = optInAccelerationInitShort = optInAccelerationMaxShort; + + if( optInAccelerationShort > optInAccelerationMaxShort ) + optInAccelerationShort = optInAccelerationMaxShort; + + /* Initialise SAR calculations */ + + if(optInStartValue == 0) /* Default action */ + { + /* Identify if the initial direction is long or short. + * (ep is just used as a temp buffer here, the name + * of the parameter is not significant). + */ + retCode = FUNCTION_CALL(MINUS_DM)( startIdx, startIdx, inHigh, inLow, 1, + VALUE_HANDLE_OUT(tempInt), VALUE_HANDLE_OUT(tempInt), + ep_temp ); + if( ep_temp[0] > 0 ) + isLong = 0; + else + isLong = 1; + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + } + else if( optInStartValue > 0 ) /* Start Long */ + { + isLong = 1; + } + else /* optInStartValue_0 < 0 => Start Short */ + { + isLong = 0; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + outIdx = 0; + + + /* Write the first SAR. */ + todayIdx = startIdx; + + newHigh = inHigh[todayIdx-1]; + newLow = inLow[todayIdx-1]; + + SAR_ROUNDING(newHigh); + SAR_ROUNDING(newLow); + + if(optInStartValue == 0) /* Default action */ + { + if( isLong == 1 ) + { + ep = inHigh[todayIdx]; + sar = newLow; + } + else + { + ep = inLow[todayIdx]; + sar = newHigh; + } + } + else if ( optInStartValue > 0 ) /* Start Long at specified value. */ + { + ep = inHigh[todayIdx]; + sar = optInStartValue; + } + else /* if optInStartValue < 0 => Start Short at specified value. */ + { + ep = inLow[todayIdx]; + sar = std_fabs(optInStartValue); + } + + SAR_ROUNDING(sar); + + /* Cheat on the newLow and newHigh for the + * first iteration. + */ + newLow = inLow[todayIdx]; + newHigh = inHigh[todayIdx]; + + while( todayIdx <= endIdx ) + { + prevLow = newLow; + prevHigh = newHigh; + newLow = inLow[todayIdx]; + newHigh = inHigh[todayIdx]; + todayIdx++; + + SAR_ROUNDING(newLow); + SAR_ROUNDING(newHigh); + + if( isLong == 1 ) + { + /* Switch to short if the low penetrates the SAR value. */ + if( newLow <= sar ) + { + /* Switch and Overide the SAR with the ep */ + isLong = 0; + sar = ep; + + /* Make sure the overide SAR is within + * yesterday's and today's range. + */ + if( sar < prevHigh ) + sar = prevHigh; + if( sar < newHigh ) + sar = newHigh; + + /* Output the overide SAR */ + if( optInOffsetOnReverse != 0.0 ) + sar += sar * optInOffsetOnReverse; + outReal[outIdx++] = -sar; + + /* Adjust afShort and ep */ + afShort = optInAccelerationInitShort; + ep = newLow; + + /* Calculate the new SAR */ + sar = sar + afShort * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar < prevHigh ) + sar = prevHigh; + if( sar < newHigh ) + sar = newHigh; + } + else + { + /* No switch */ + + /* Output the SAR (was calculated in the previous iteration) */ + outReal[outIdx++] = sar; + + /* Adjust afLong and ep. */ + if( newHigh > ep ) + { + ep = newHigh; + afLong += optInAccelerationLong; + if( afLong > optInAccelerationMaxLong ) + afLong = optInAccelerationMaxLong; + } + + /* Calculate the new SAR */ + sar = sar + afLong * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar > prevLow ) + sar = prevLow; + if( sar > newLow ) + sar = newLow; + } + } + else + { + /* Switch to long if the high penetrates the SAR value. */ + if( newHigh >= sar ) + { + /* Switch and Overide the SAR with the ep */ + isLong = 1; + sar = ep; + + /* Make sure the overide SAR is within + * yesterday's and today's range. + */ + if( sar > prevLow ) + sar = prevLow; + if( sar > newLow ) + sar = newLow; + + /* Output the overide SAR */ + if( optInOffsetOnReverse != 0.0 ) + sar -= sar * optInOffsetOnReverse; + outReal[outIdx++] = sar; + + /* Adjust afLong and ep */ + afLong = optInAccelerationInitLong; + ep = newHigh; + + /* Calculate the new SAR */ + sar = sar + afLong * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar > prevLow ) + sar = prevLow; + if( sar > newLow ) + sar = newLow; + } + else + { + /* No switch */ + + /* Output the SAR (was calculated in the previous iteration) */ + outReal[outIdx++] = -sar; + + /* Adjust afShort and ep. */ + if( newLow < ep ) + { + ep = newLow; + afShort += optInAccelerationShort; + if( afShort > optInAccelerationMaxShort ) + afShort = optInAccelerationMaxShort; + } + + /* Calculate the new SAR */ + sar = sar + afShort * (ep - sar); + SAR_ROUNDING( sar ); + + /* Make sure the new SAR is within + * yesterday's and today's range. + */ + if( sar < prevHigh ) + sar = prevHigh; + if( sar < newHigh ) + sar = newHigh; + } + } + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::SarExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::SarExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sarExt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SAREXT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ double optInStartValue, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ double optInOffsetOnReverse, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxLong, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationInitShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ double optInAccelerationMaxShort, /* From 0 to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int isLong; +/* Generated */ int todayIdx, outIdx; +/* Generated */ VALUE_HANDLE_INT(tempInt); +/* Generated */ double newHigh, newLow, prevHigh, prevLow; +/* Generated */ double afLong, afShort, ep, sar; +/* Generated */ ARRAY_LOCAL(ep_temp,1); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( optInStartValue == TA_REAL_DEFAULT ) +/* Generated */ optInStartValue = 0.000000e+0; +/* Generated */ else if( (optInStartValue < -3.000000e+37) || (optInStartValue > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInOffsetOnReverse == TA_REAL_DEFAULT ) +/* Generated */ optInOffsetOnReverse = 0.000000e+0; +/* Generated */ else if( (optInOffsetOnReverse < 0.000000e+0) || (optInOffsetOnReverse > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInAccelerationInitLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationInitLong = 2.000000e-2; +/* Generated */ else if( (optInAccelerationInitLong < 0.000000e+0) || (optInAccelerationInitLong > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInAccelerationLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationLong = 2.000000e-2; +/* Generated */ else if( (optInAccelerationLong < 0.000000e+0) || (optInAccelerationLong > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInAccelerationMaxLong == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationMaxLong = 2.000000e-1; +/* Generated */ else if( (optInAccelerationMaxLong < 0.000000e+0) || (optInAccelerationMaxLong > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInAccelerationInitShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationInitShort = 2.000000e-2; +/* Generated */ else if( (optInAccelerationInitShort < 0.000000e+0) || (optInAccelerationInitShort > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInAccelerationShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationShort = 2.000000e-2; +/* Generated */ else if( (optInAccelerationShort < 0.000000e+0) || (optInAccelerationShort > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInAccelerationMaxShort == TA_REAL_DEFAULT ) +/* Generated */ optInAccelerationMaxShort = 2.000000e-1; +/* Generated */ else if( (optInAccelerationMaxShort < 0.000000e+0) || (optInAccelerationMaxShort > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < 1 ) +/* Generated */ startIdx = 1; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ afLong = optInAccelerationInitLong; +/* Generated */ afShort = optInAccelerationInitShort; +/* Generated */ if( afLong > optInAccelerationMaxLong ) +/* Generated */ afLong = optInAccelerationInitLong = optInAccelerationMaxLong; +/* Generated */ if( optInAccelerationLong > optInAccelerationMaxLong ) +/* Generated */ optInAccelerationLong = optInAccelerationMaxLong; +/* Generated */ if( afShort > optInAccelerationMaxShort) +/* Generated */ afShort = optInAccelerationInitShort = optInAccelerationMaxShort; +/* Generated */ if( optInAccelerationShort > optInAccelerationMaxShort ) +/* Generated */ optInAccelerationShort = optInAccelerationMaxShort; +/* Generated */ if(optInStartValue == 0) +/* Generated */ { +/* Generated */ retCode = FUNCTION_CALL(MINUS_DM)( startIdx, startIdx, inHigh, inLow, 1, +/* Generated */ VALUE_HANDLE_OUT(tempInt), VALUE_HANDLE_OUT(tempInt), +/* Generated */ ep_temp ); +/* Generated */ if( ep_temp[0] > 0 ) +/* Generated */ isLong = 0; +/* Generated */ else +/* Generated */ isLong = 1; +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ } +/* Generated */ else if( optInStartValue > 0 ) +/* Generated */ { +/* Generated */ isLong = 1; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ isLong = 0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ todayIdx = startIdx; +/* Generated */ newHigh = inHigh[todayIdx-1]; +/* Generated */ newLow = inLow[todayIdx-1]; +/* Generated */ SAR_ROUNDING(newHigh); +/* Generated */ SAR_ROUNDING(newLow); +/* Generated */ if(optInStartValue == 0) +/* Generated */ { +/* Generated */ if( isLong == 1 ) +/* Generated */ { +/* Generated */ ep = inHigh[todayIdx]; +/* Generated */ sar = newLow; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ ep = inLow[todayIdx]; +/* Generated */ sar = newHigh; +/* Generated */ } +/* Generated */ } +/* Generated */ else if ( optInStartValue > 0 ) +/* Generated */ { +/* Generated */ ep = inHigh[todayIdx]; +/* Generated */ sar = optInStartValue; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ ep = inLow[todayIdx]; +/* Generated */ sar = std_fabs(optInStartValue); +/* Generated */ } +/* Generated */ SAR_ROUNDING(sar); +/* Generated */ newLow = inLow[todayIdx]; +/* Generated */ newHigh = inHigh[todayIdx]; +/* Generated */ while( todayIdx <= endIdx ) +/* Generated */ { +/* Generated */ prevLow = newLow; +/* Generated */ prevHigh = newHigh; +/* Generated */ newLow = inLow[todayIdx]; +/* Generated */ newHigh = inHigh[todayIdx]; +/* Generated */ todayIdx++; +/* Generated */ SAR_ROUNDING(newLow); +/* Generated */ SAR_ROUNDING(newHigh); +/* Generated */ if( isLong == 1 ) +/* Generated */ { +/* Generated */ if( newLow <= sar ) +/* Generated */ { +/* Generated */ isLong = 0; +/* Generated */ sar = ep; +/* Generated */ if( sar < prevHigh ) +/* Generated */ sar = prevHigh; +/* Generated */ if( sar < newHigh ) +/* Generated */ sar = newHigh; +/* Generated */ if( optInOffsetOnReverse != 0.0 ) +/* Generated */ sar += sar * optInOffsetOnReverse; +/* Generated */ outReal[outIdx++] = -sar; +/* Generated */ afShort = optInAccelerationInitShort; +/* Generated */ ep = newLow; +/* Generated */ sar = sar + afShort * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar < prevHigh ) +/* Generated */ sar = prevHigh; +/* Generated */ if( sar < newHigh ) +/* Generated */ sar = newHigh; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ outReal[outIdx++] = sar; +/* Generated */ if( newHigh > ep ) +/* Generated */ { +/* Generated */ ep = newHigh; +/* Generated */ afLong += optInAccelerationLong; +/* Generated */ if( afLong > optInAccelerationMaxLong ) +/* Generated */ afLong = optInAccelerationMaxLong; +/* Generated */ } +/* Generated */ sar = sar + afLong * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar > prevLow ) +/* Generated */ sar = prevLow; +/* Generated */ if( sar > newLow ) +/* Generated */ sar = newLow; +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ if( newHigh >= sar ) +/* Generated */ { +/* Generated */ isLong = 1; +/* Generated */ sar = ep; +/* Generated */ if( sar > prevLow ) +/* Generated */ sar = prevLow; +/* Generated */ if( sar > newLow ) +/* Generated */ sar = newLow; +/* Generated */ if( optInOffsetOnReverse != 0.0 ) +/* Generated */ sar -= sar * optInOffsetOnReverse; +/* Generated */ outReal[outIdx++] = sar; +/* Generated */ afLong = optInAccelerationInitLong; +/* Generated */ ep = newHigh; +/* Generated */ sar = sar + afLong * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar > prevLow ) +/* Generated */ sar = prevLow; +/* Generated */ if( sar > newLow ) +/* Generated */ sar = newLow; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ outReal[outIdx++] = -sar; +/* Generated */ if( newLow < ep ) +/* Generated */ { +/* Generated */ ep = newLow; +/* Generated */ afShort += optInAccelerationShort; +/* Generated */ if( afShort > optInAccelerationMaxShort ) +/* Generated */ afShort = optInAccelerationMaxShort; +/* Generated */ } +/* Generated */ sar = sar + afShort * (ep - sar); +/* Generated */ SAR_ROUNDING( sar ); +/* Generated */ if( sar < prevHigh ) +/* Generated */ sar = prevHigh; +/* Generated */ if( sar < newHigh ) +/* Generated */ sar = newHigh; +/* Generated */ } +/* Generated */ } +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + + diff --git a/talib/ta_func/ta_SIN.c b/talib/ta_func/ta_SIN.c new file mode 100644 index 0000000..e7fa924 --- /dev/null +++ b/talib/ta_func/ta_SIN.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 082507 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SinLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int sinLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SIN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SIN - Vector Trigonometric Sin + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SIN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + #ifndef TA_LIB_PRO + int i; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_sin(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sin( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SIN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_sin(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SINH.c b/talib/ta_func/ta_SINH.c new file mode 100644 index 0000000..4d85e5d --- /dev/null +++ b/talib/ta_func/ta_SINH.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SinhLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int sinhLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SINH_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SINH - Vector Trigonometric Sinh + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sinh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sinh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sinh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SINH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_sinh(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sinh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sinh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sinh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SINH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_sinh(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SMA.c b/talib/ta_func/ta_SMA.c new file mode 100644 index 0000000..5b7abca --- /dev/null +++ b/talib/ta_func/ta_SMA.c @@ -0,0 +1,429 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SmaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int smaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return optInTimePeriod - 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SMA - Simple Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + return FUNCTION_CALL(INT_SMA)( startIdx, endIdx, + inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); +} + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + // No INT function +#else + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) + enum class Core::RetCode Core::TA_INT_SMA( int startIdx, + int endIdx, + SubArray^ inReal, + int optInTimePeriod, + [Out]int% outBegIdx, + [Out]int% outNBElement, + SubArray^ outReal) +#elif defined( _MANAGED ) + enum class Core::RetCode Core::TA_INT_SMA( int startIdx, + int endIdx, + cli::array^ inReal, + int optInTimePeriod, + [Out]int% outBegIdx, + [Out]int% outNBElement, + cli::array^ outReal) +#elif defined( _JAVA ) +RetCode TA_INT_SMA( int startIdx, + int endIdx, + INPUT_TYPE inReal[], + int optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + MInteger outBegIdx, + MInteger outNBElement, + double outReal[] ) +#else +TA_RetCode TA_PREFIX(INT_SMA)( int startIdx, + int endIdx, + const INPUT_TYPE *inReal, + int optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + int *outBegIdx, + int *outNBElement, + double *outReal ) +#endif +{ + double periodTotal, tempReal; + int i, outIdx, trailingIdx, lookbackTotal; + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the MA calculation using tight loops. */ + /* Add-up the initial period, except for the last value. */ + periodTotal = 0; + trailingIdx = startIdx-lookbackTotal; + + i=trailingIdx; + if( optInTimePeriod > 1 ) + { + while( i < startIdx ) + periodTotal += inReal[i++]; + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the inReal and + * outReal to be the same buffer. + */ + outIdx = 0; + do + { + periodTotal += inReal[i++]; + tempReal = periodTotal; + periodTotal -= inReal[trailingIdx++]; + outReal[outIdx++] = tempReal / optInTimePeriod; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +#endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ return FUNCTION_CALL(INT_SMA)( startIdx, endIdx, +/* Generated */ inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ } +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ // No INT function +/* Generated */ #else +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TA_INT_SMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TA_INT_SMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ RetCode TA_INT_SMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ INPUT_TYPE inReal[], +/* Generated */ int optInTimePeriod, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_PREFIX(INT_SMA)( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const INPUT_TYPE *inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double *outReal ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double periodTotal, tempReal; +/* Generated */ int i, outIdx, trailingIdx, lookbackTotal; +/* Generated */ lookbackTotal = (optInTimePeriod-1); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ periodTotal = 0; +/* Generated */ trailingIdx = startIdx-lookbackTotal; +/* Generated */ i=trailingIdx; +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ { +/* Generated */ while( i < startIdx ) +/* Generated */ periodTotal += inReal[i++]; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ periodTotal += inReal[i++]; +/* Generated */ tempReal = periodTotal; +/* Generated */ periodTotal -= inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = tempReal / optInTimePeriod; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ #endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SQRT.c b/talib/ta_func/ta_SQRT.c new file mode 100644 index 0000000..e86f682 --- /dev/null +++ b/talib/ta_func/ta_SQRT.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SqrtLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int sqrtLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SQRT_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SQRT - Vector Square Root + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sqrt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sqrt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sqrt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SQRT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_sqrt(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sqrt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sqrt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sqrt( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SQRT( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_sqrt(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_STDDEV.c b/talib/ta_func/ta_STDDEV.c new file mode 100644 index 0000000..14c29e5 --- /dev/null +++ b/talib/ta_func/ta_STDDEV.c @@ -0,0 +1,517 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JV Jesus Viver <324122@cienz.unizar.es> + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 100502 JV Speed optimization of the algorithm + * 052603 MF Adapt code to compile with .NET Managed C++ + * 090404 MF Fix #978056. Trap sqrt with negative zero values. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::StdDevLookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev ) /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int stdDevLookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev ) /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_STDDEV_Lookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev ) /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInNbDev == TA_REAL_DEFAULT ) +/* Generated */ optInNbDev = 1.000000e+0; +/* Generated */ else if( (optInNbDev < -3.000000e+37) ||/* Generated */ (optInNbDev > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Lookback is driven by the variance. */ + return LOOKBACK_CALL(VAR)( optInTimePeriod, optInNbDev ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_STDDEV - Standard Deviation + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * optInNbDev:(From TA_REAL_MIN to TA_REAL_MAX) + * Nb of deviations + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::StdDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::StdDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stdDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_STDDEV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int i; + ENUM_DECLARATION(RetCode) retCode; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInNbDev == TA_REAL_DEFAULT ) +/* Generated */ optInNbDev = 1.000000e+0; +/* Generated */ else if( (optInNbDev < -3.000000e+37) ||/* Generated */ (optInNbDev > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Calculate the variance. */ + retCode = FUNCTION_CALL(INT_VAR)( startIdx, endIdx, + inReal, optInTimePeriod, + outBegIdx, outNBElement, outReal ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + return retCode; + + /* Calculate the square root of each variance, this + * is the standard deviation. + * + * Multiply also by the ratio specified. + */ + if( optInNbDev != 1.0 ) + { + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = outReal[i]; + if( !TA_IS_ZERO_OR_NEG(tempReal) ) + outReal[i] = std_sqrt(tempReal) * optInNbDev; + else + outReal[i] = (double)0.0; + } + } + else + { + for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) + { + tempReal = outReal[i]; + if( !TA_IS_ZERO_OR_NEG(tempReal) ) + outReal[i] = std_sqrt(tempReal); + else + outReal[i] = (double)0.0; + } + } + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) + // No INT function +#else + +/* The inMovAvg is the moving average of the inReal. + * + * inMovAvgBegIdx is relative to inReal, in other word + * this is the 'outBegIdx' who was returned when doing the + * MA on the inReal. + * + * inMovAvgNbElement is the number of element who was returned + * when doing the MA on the inReal. + * + * Note: This function is not used by TA_STDDEV, since TA_STDDEV + * is optimized considering it uses always a simple moving + * average. Still the function is put here because it is + * closely related. + */ +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) +void Core::TA_INT_stddev_using_precalc_ma( SubArray^ inReal, + SubArray^ inMovAvg, + int inMovAvgBegIdx, + int inMovAvgNbElement, + int timePeriod, + SubArray^ output) +#elif defined( _MANAGED ) +void Core::TA_INT_stddev_using_precalc_ma( cli::array^ inReal, + cli::array^ inMovAvg, + int inMovAvgBegIdx, + int inMovAvgNbElement, + int timePeriod, + cli::array^ output) +#elif defined( _JAVA ) +void TA_INT_stddev_using_precalc_ma( INPUT_TYPE inReal[], + double inMovAvg[], + int inMovAvgBegIdx, + int inMovAvgNbElement, + int timePeriod, + double output[] ) +#else +void TA_PREFIX(INT_stddev_using_precalc_ma)( const INPUT_TYPE *inReal, + const double *inMovAvg, + int inMovAvgBegIdx, + int inMovAvgNbElement, + int timePeriod, + double *output ) +#endif +{ + double tempReal, periodTotal2, meanValue2; + int outIdx; + + /* Start/end index for sumation. */ + int startSum, endSum; + + startSum = 1+inMovAvgBegIdx-timePeriod; + endSum = inMovAvgBegIdx; + + periodTotal2 = 0; + + for( outIdx = startSum; outIdx < endSum; outIdx++) + { + tempReal = inReal[outIdx]; + tempReal *= tempReal; + periodTotal2 += tempReal; + } + + for( outIdx=0; outIdx < inMovAvgNbElement; outIdx++, startSum++, endSum++ ) + { + tempReal = inReal[endSum]; + tempReal *= tempReal; + periodTotal2 += tempReal; + meanValue2 = periodTotal2/timePeriod; + + tempReal = inReal[startSum]; + tempReal *= tempReal; + periodTotal2 -= tempReal; + + tempReal = inMovAvg[outIdx]; + tempReal *= tempReal; + meanValue2 -= tempReal; + + if( !TA_IS_ZERO_OR_NEG(meanValue2) ) + output[outIdx] = std_sqrt(meanValue2); + else + output[outIdx] = (double)0.0; + } +} +#endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::StdDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::StdDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stdDev( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_STDDEV( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int i; +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInNbDev == TA_REAL_DEFAULT ) +/* Generated */ optInNbDev = 1.000000e+0; +/* Generated */ else if( (optInNbDev < -3.000000e+37) || (optInNbDev > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL(INT_VAR)( startIdx, endIdx, +/* Generated */ inReal, optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ return retCode; +/* Generated */ if( optInNbDev != 1.0 ) +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = outReal[i]; +/* Generated */ if( !TA_IS_ZERO_OR_NEG(tempReal) ) +/* Generated */ outReal[i] = std_sqrt(tempReal) * optInNbDev; +/* Generated */ else +/* Generated */ outReal[i] = (double)0.0; +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ for( i=0; i < (int)VALUE_HANDLE_DEREF(outNBElement); i++ ) +/* Generated */ { +/* Generated */ tempReal = outReal[i]; +/* Generated */ if( !TA_IS_ZERO_OR_NEG(tempReal) ) +/* Generated */ outReal[i] = std_sqrt(tempReal); +/* Generated */ else +/* Generated */ outReal[i] = (double)0.0; +/* Generated */ } +/* Generated */ } +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ // No INT function +/* Generated */ #else +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ void Core::TA_INT_stddev_using_precalc_ma( SubArray^ inReal, +/* Generated */ SubArray^ inMovAvg, +/* Generated */ int inMovAvgBegIdx, +/* Generated */ int inMovAvgNbElement, +/* Generated */ int timePeriod, +/* Generated */ SubArray^ output) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ void Core::TA_INT_stddev_using_precalc_ma( cli::array^ inReal, +/* Generated */ cli::array^ inMovAvg, +/* Generated */ int inMovAvgBegIdx, +/* Generated */ int inMovAvgNbElement, +/* Generated */ int timePeriod, +/* Generated */ cli::array^ output) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ void TA_INT_stddev_using_precalc_ma( INPUT_TYPE inReal[], +/* Generated */ double inMovAvg[], +/* Generated */ int inMovAvgBegIdx, +/* Generated */ int inMovAvgNbElement, +/* Generated */ int timePeriod, +/* Generated */ double output[] ) +/* Generated */ #else +/* Generated */ void TA_PREFIX(INT_stddev_using_precalc_ma)( const INPUT_TYPE *inReal, +/* Generated */ const double *inMovAvg, +/* Generated */ int inMovAvgBegIdx, +/* Generated */ int inMovAvgNbElement, +/* Generated */ int timePeriod, +/* Generated */ double *output ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double tempReal, periodTotal2, meanValue2; +/* Generated */ int outIdx; +/* Generated */ int startSum, endSum; +/* Generated */ startSum = 1+inMovAvgBegIdx-timePeriod; +/* Generated */ endSum = inMovAvgBegIdx; +/* Generated */ periodTotal2 = 0; +/* Generated */ for( outIdx = startSum; outIdx < endSum; outIdx++) +/* Generated */ { +/* Generated */ tempReal = inReal[outIdx]; +/* Generated */ tempReal *= tempReal; +/* Generated */ periodTotal2 += tempReal; +/* Generated */ } +/* Generated */ for( outIdx=0; outIdx < inMovAvgNbElement; outIdx++, startSum++, endSum++ ) +/* Generated */ { +/* Generated */ tempReal = inReal[endSum]; +/* Generated */ tempReal *= tempReal; +/* Generated */ periodTotal2 += tempReal; +/* Generated */ meanValue2 = periodTotal2/timePeriod; +/* Generated */ tempReal = inReal[startSum]; +/* Generated */ tempReal *= tempReal; +/* Generated */ periodTotal2 -= tempReal; +/* Generated */ tempReal = inMovAvg[outIdx]; +/* Generated */ tempReal *= tempReal; +/* Generated */ meanValue2 -= tempReal; +/* Generated */ if( !TA_IS_ZERO_OR_NEG(meanValue2) ) +/* Generated */ output[outIdx] = std_sqrt(meanValue2); +/* Generated */ else +/* Generated */ output[outIdx] = (double)0.0; +/* Generated */ } +/* Generated */ } +/* Generated */ #endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_STOCH.c b/talib/ta_func/ta_STOCH.c new file mode 100644 index 0000000..e1db015 --- /dev/null +++ b/talib/ta_func/ta_STOCH.c @@ -0,0 +1,818 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::StochLookback( int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int stochLookback( int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_STOCH_Lookback( int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSlowD_MAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastK_Period. */ +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowK_Period. */ +/* Generated */ if( (int)optInSlowK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowK_Period = 3; +/* Generated */ else if( ((int)optInSlowK_Period < 1) || ((int)optInSlowK_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowK_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowK_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowK_MAType < 0) || ((int)optInSlowK_MAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSlowD_Period. */ +/* Generated */ if( (int)optInSlowD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowD_Period = 3; +/* Generated */ else if( ((int)optInSlowD_Period < 1) || ((int)optInSlowD_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowD_MAType < 0) || ((int)optInSlowD_MAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Account for the initial data needed for Fast-K. */ + retValue = (optInFastK_Period - 1); + + /* Add the smoothing being done for %K slow */ + retValue += LOOKBACK_CALL(MA)( optInSlowK_Period, optInSlowK_MAType ); + + /* Add the smoothing being done for %D slow. */ + retValue += LOOKBACK_CALL(MA)( optInSlowD_Period, optInSlowD_MAType ); + + return retValue; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_STOCH - Stochastic + * + * Input = High, Low, Close + * Output = double, double + * + * Optional Parameters + * ------------------- + * optInFastK_Period:(From 1 to 100000) + * Time period for building the Fast-K line + * + * optInSlowK_Period:(From 1 to 100000) + * Smoothing for making the Slow-K line. Usually set to 3 + * + * optInSlowK_MAType: + * Type of Moving Average for Slow-K + * + * optInSlowD_Period:(From 1 to 100000) + * Smoothing for making the Slow-D line + * + * optInSlowD_MAType: + * Type of Moving Average for Slow-D + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Stoch( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outSlowK, +/* Generated */ SubArray^ outSlowD ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Stoch( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outSlowK, +/* Generated */ cli::array^ outSlowD ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stoch( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outSlowK[], +/* Generated */ double outSlowD[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_STOCH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSlowD_MAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outSlowK[], +/* Generated */ double outSlowD[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ENUM_DECLARATION(RetCode) retCode; + double lowest, highest, tmp, diff; + ARRAY_REF( tempBuffer ); + int outIdx, lowestIdx, highestIdx; + int lookbackTotal, lookbackK, lookbackKSlow, lookbackDSlow; + int trailingIdx, today, i; + #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) &&!defined(_JAVA) + int bufferIsAllocated; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastK_Period. */ +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInSlowK_Period. */ +/* Generated */ if( (int)optInSlowK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowK_Period = 3; +/* Generated */ else if( ((int)optInSlowK_Period < 1) || ((int)optInSlowK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowK_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowK_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowK_MAType < 0) || ((int)optInSlowK_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInSlowD_Period. */ +/* Generated */ if( (int)optInSlowD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowD_Period = 3; +/* Generated */ else if( ((int)optInSlowD_Period < 1) || ((int)optInSlowD_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowD_MAType < 0) || ((int)optInSlowD_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outSlowK ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outSlowD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* With stochastic, there is a total of 4 different lines that + * are defined: FASTK, FASTD, SLOWK and SLOWD. + * + * The D is the signal line usually drawn over its + * corresponding K function. + * + * (Today's Close - LowestLow) + * FASTK(Kperiod) = --------------------------- * 100 + * (HighestHigh - LowestLow) + * + * FASTD(FastDperiod, MA type) = MA Smoothed FASTK over FastDperiod + * + * SLOWK(SlowKperiod, MA type) = MA Smoothed FASTK over SlowKperiod + * + * SLOWD(SlowDperiod, MA Type) = MA Smoothed SLOWK over SlowDperiod + * + * The HighestHigh and LowestLow are the extreme values among the + * last 'Kperiod'. + * + * SLOWK and FASTD are equivalent when using the same period. + * + * The following shows how these four lines are made available in TA-LIB: + * + * TA_STOCH : Returns the SLOWK and SLOWD + * TA_STOCHF : Returns the FASTK and FASTD + * + * The TA_STOCH function correspond to the more widely implemented version + * found in many software/charting package. The TA_STOCHF is more rarely + * used because its higher volatility cause often whipsaws. + */ + + /* Identify the lookback needed. */ + lookbackK = optInFastK_Period-1; + lookbackKSlow = LOOKBACK_CALL(MA)( optInSlowK_Period, optInSlowK_MAType ); + lookbackDSlow = LOOKBACK_CALL(MA)( optInSlowD_Period, optInSlowD_MAType ); + lookbackTotal = lookbackK + lookbackDSlow + lookbackKSlow; + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + /* Succeed... but no data in the output. */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the K calculation: + * + * Kt = 100 x ((Ct-Lt)/(Ht-Lt)) + * + * Kt is today stochastic + * Ct is today closing price. + * Lt is the lowest price of the last K Period (including today) + * Ht is the highest price of the last K Period (including today) + */ + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + + /* Calculate just enough K for ending up with the caller + * requested range. (The range of k must consider all + * the lookback involve with the smoothing). + */ + trailingIdx = startIdx-lookbackTotal; + today = trailingIdx+lookbackK; + lowestIdx = highestIdx = -1; + diff = highest = lowest = 0.0; + + /* Allocate a temporary buffer large enough to + * store the K. + * + * If the output is the same as the input, great + * we just save ourself one memory allocation. + */ + #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA ) + bufferIsAllocated = 0; + #endif + + #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) + /* Always alloc, since output is of different type and + * its allocated size is not guarantee to be as large as + * the input. + */ + ARRAY_ALLOC( tempBuffer, endIdx-today+1 ); + #else + if( (outSlowK == inHigh) || + (outSlowK == inLow) || + (outSlowK == inClose) ) + { + tempBuffer = outSlowK; + } + else if( (outSlowD == inHigh) || + (outSlowD == inLow) || + (outSlowD == inClose) ) + { + tempBuffer = outSlowD; + } + else + { + #if !defined( _MANAGED ) && !defined(_JAVA) + bufferIsAllocated = 1; + #endif + ARRAY_ALLOC( tempBuffer, endIdx-today+1 ); + } + #endif + + /* Do the K calculation */ + while( today <= endIdx ) + { + /* Set the lowest low */ + tmp = inLow[today]; + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inLow[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inLow[i]; + if( tmp < lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + diff = (highest - lowest)/100.0; + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + diff = (highest - lowest)/100.0; + } + + /* Set the highest high */ + tmp = inHigh[today]; + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inHigh[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inHigh[i]; + if( tmp > highest ) + { + highestIdx = i; + highest = tmp; + } + } + diff = (highest - lowest)/100.0; + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + diff = (highest - lowest)/100.0; + } + + /* Calculate stochastic. */ + if( diff != 0.0 ) + tempBuffer[outIdx++] = (inClose[today]-lowest)/diff; + else + tempBuffer[outIdx++] = 0.0; + + trailingIdx++; + today++; + } + + /* Un-smoothed K calculation completed. This K calculation is not returned + * to the caller. It is always smoothed and then return. + * Some documentation will refer to the smoothed version as being + * "K-Slow", but often this end up to be shorten to "K". + */ + retCode = FUNCTION_CALL_DOUBLE(MA)( 0, outIdx-1, + tempBuffer, optInSlowK_Period, + optInSlowK_MAType, + outBegIdx, outNBElement, tempBuffer ); + + + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) ) + { + #if defined(USE_SINGLE_PRECISION_INPUT) + ARRAY_FREE( tempBuffer ); + #else + ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); + #endif + /* Something wrong happen? No further data? */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Calculate the %D which is simply a moving average of + * the already smoothed %K. + */ + retCode = FUNCTION_CALL_DOUBLE(MA)( 0, (int)VALUE_HANDLE_DEREF(outNBElement)-1, + tempBuffer, optInSlowD_Period, + optInSlowD_MAType, + outBegIdx, outNBElement, outSlowD ); + + /* Copy tempBuffer into the caller buffer. + * (Calculation could not be done directly in the + * caller buffer because more input data then the + * requested range was needed for doing %D). + */ + ARRAY_MEMMOVE( outSlowK, 0, tempBuffer,lookbackDSlow,(int)VALUE_HANDLE_DEREF(outNBElement)); + + /* Don't need K anymore, free it if it was allocated here. */ + #if defined(USE_SINGLE_PRECISION_INPUT) + ARRAY_FREE( tempBuffer ); + #else + ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); + #endif + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + /* Something wrong happen while processing %D? */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Note: Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Stoch( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outSlowK, +/* Generated */ SubArray^ outSlowD ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Stoch( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outSlowK, +/* Generated */ cli::array^ outSlowD ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stoch( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInSlowD_MAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outSlowK[], +/* Generated */ double outSlowD[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_STOCH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInSlowK_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSlowK_MAType, +/* Generated */ int optInSlowD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInSlowD_MAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outSlowK[], +/* Generated */ double outSlowD[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ double lowest, highest, tmp, diff; +/* Generated */ ARRAY_REF( tempBuffer ); +/* Generated */ int outIdx, lowestIdx, highestIdx; +/* Generated */ int lookbackTotal, lookbackK, lookbackKSlow, lookbackDSlow; +/* Generated */ int trailingIdx, today, i; +/* Generated */ #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) &&!defined(_JAVA) +/* Generated */ int bufferIsAllocated; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInSlowK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowK_Period = 3; +/* Generated */ else if( ((int)optInSlowK_Period < 1) || ((int)optInSlowK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowK_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowK_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowK_MAType < 0) || ((int)optInSlowK_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInSlowD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowD_Period = 3; +/* Generated */ else if( ((int)optInSlowD_Period < 1) || ((int)optInSlowD_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInSlowD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInSlowD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInSlowD_MAType < 0) || ((int)optInSlowD_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outSlowK ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outSlowD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackK = optInFastK_Period-1; +/* Generated */ lookbackKSlow = LOOKBACK_CALL(MA)( optInSlowK_Period, optInSlowK_MAType ); +/* Generated */ lookbackDSlow = LOOKBACK_CALL(MA)( optInSlowD_Period, optInSlowD_MAType ); +/* Generated */ lookbackTotal = lookbackK + lookbackDSlow + lookbackKSlow; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ trailingIdx = startIdx-lookbackTotal; +/* Generated */ today = trailingIdx+lookbackK; +/* Generated */ lowestIdx = highestIdx = -1; +/* Generated */ diff = highest = lowest = 0.0; +/* Generated */ #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA ) +/* Generated */ bufferIsAllocated = 0; +/* Generated */ #endif +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) +/* Generated */ ARRAY_ALLOC( tempBuffer, endIdx-today+1 ); +/* Generated */ #else +/* Generated */ if( (outSlowK == inHigh) || +/* Generated */ (outSlowK == inLow) || +/* Generated */ (outSlowK == inClose) ) +/* Generated */ { +/* Generated */ tempBuffer = outSlowK; +/* Generated */ } +/* Generated */ else if( (outSlowD == inHigh) || +/* Generated */ (outSlowD == inLow) || +/* Generated */ (outSlowD == inClose) ) +/* Generated */ { +/* Generated */ tempBuffer = outSlowD; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ #if !defined( _MANAGED ) && !defined(_JAVA) +/* Generated */ bufferIsAllocated = 1; +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC( tempBuffer, endIdx-today+1 ); +/* Generated */ } +/* Generated */ #endif +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inLow[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inLow[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inLow[i]; +/* Generated */ if( tmp < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ tmp = inHigh[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inHigh[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inHigh[i]; +/* Generated */ if( tmp > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ if( diff != 0.0 ) +/* Generated */ tempBuffer[outIdx++] = (inClose[today]-lowest)/diff; +/* Generated */ else +/* Generated */ tempBuffer[outIdx++] = 0.0; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(MA)( 0, outIdx-1, +/* Generated */ tempBuffer, optInSlowK_Period, +/* Generated */ optInSlowK_MAType, +/* Generated */ outBegIdx, outNBElement, tempBuffer ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) ) +/* Generated */ { +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ #else +/* Generated */ ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(MA)( 0, (int)VALUE_HANDLE_DEREF(outNBElement)-1, +/* Generated */ tempBuffer, optInSlowD_Period, +/* Generated */ optInSlowD_MAType, +/* Generated */ outBegIdx, outNBElement, outSlowD ); +/* Generated */ ARRAY_MEMMOVE( outSlowK, 0, tempBuffer,lookbackDSlow,(int)VALUE_HANDLE_DEREF(outNBElement)); +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ #else +/* Generated */ ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); +/* Generated */ #endif +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_STOCHF.c b/talib/ta_func/ta_STOCHF.c new file mode 100644 index 0000000..3dc355b --- /dev/null +++ b/talib/ta_func/ta_STOCHF.c @@ -0,0 +1,736 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * EKO echo999@ifrance.com + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 051103 EKO Found bug and fix related to outFastD. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::StochFLookback( int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int stochFLookback( int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_STOCHF_Lookback( int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInFastD_MAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInFastK_Period. */ +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInFastD_Period. */ +/* Generated */ if( (int)optInFastD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_Period = 3; +/* Generated */ else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Account for the initial data needed for Fast-K. */ + retValue = (optInFastK_Period - 1); + + /* Add the smoothing being done for Fast-D */ + retValue += LOOKBACK_CALL(MA)( optInFastD_Period, optInFastD_MAType ); + + return retValue; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_STOCHF - Stochastic Fast + * + * Input = High, Low, Close + * Output = double, double + * + * Optional Parameters + * ------------------- + * optInFastK_Period:(From 1 to 100000) + * Time period for building the Fast-K line + * + * optInFastD_Period:(From 1 to 100000) + * Smoothing for making the Fast-D line. Usually set to 3 + * + * optInFastD_MAType: + * Type of Moving Average for Fast-D + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::StochF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outFastK, +/* Generated */ SubArray^ outFastD ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::StochF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outFastK, +/* Generated */ cli::array^ outFastD ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stochF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_STOCHF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInFastD_MAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ENUM_DECLARATION(RetCode) retCode; + double lowest, highest, tmp, diff; + ARRAY_REF( tempBuffer ); + int outIdx, lowestIdx, highestIdx; + int lookbackTotal, lookbackK, lookbackFastD; + int trailingIdx, today, i; + + #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA ) + int bufferIsAllocated; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInFastK_Period. */ +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInFastD_Period. */ +/* Generated */ if( (int)optInFastD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_Period = 3; +/* Generated */ else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outFastK ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outFastD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* With stochastic, there is a total of 4 different lines that + * are defined: FASTK, FASTD, SLOWK and SLOWD. + * + * The D is the signal line usually drawn over its + * corresponding K function. + * + * (Today's Close - LowestLow) + * FASTK(Kperiod) = --------------------------- * 100 + * (HighestHigh - LowestLow) + * + * FASTD(FastDperiod, MA type) = MA Smoothed FASTK over FastDperiod + * + * SLOWK(SlowKperiod, MA type) = MA Smoothed FASTK over SlowKperiod + * + * SLOWD(SlowDperiod, MA Type) = MA Smoothed SLOWK over SlowDperiod + * + * The HighestHigh and LowestLow are the extreme values among the + * last 'Kperiod'. + * + * SLOWK and FASTD are equivalent when using the same period. + * + * The following shows how these four lines are made available in TA-LIB: + * + * TA_STOCH : Returns the SLOWK and SLOWD + * TA_STOCHF : Returns the FASTK and FASTD + * + * The TA_STOCH function correspond to the more widely implemented version + * found in many software/charting package. The TA_STOCHF is more rarely + * used because its higher volatility cause often whipsaws. + */ + + /* Identify the lookback needed. */ + lookbackK = optInFastK_Period-1; + lookbackFastD = LOOKBACK_CALL(MA)( optInFastD_Period, optInFastD_MAType ); + lookbackTotal = lookbackK + lookbackFastD; + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + /* Succeed... but no data in the output. */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the K calculation: + * + * Kt = 100 x ((Ct-Lt)/(Ht-Lt)) + * + * Kt is today stochastic + * Ct is today closing price. + * Lt is the lowest price of the last K Period (including today) + * Ht is the highest price of the last K Period (including today) + */ + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + + /* Calculate just enough K for ending up with the caller + * requested range. (The range of k must consider all + * the lookback involve with the smoothing). + */ + trailingIdx = startIdx-lookbackTotal; + today = trailingIdx+lookbackK; + lowestIdx = highestIdx = -1; + diff = highest = lowest = 0.0; + + /* Allocate a temporary buffer large enough to + * store the K. + * + * If the output is the same as the input, great + * we just save ourself one memory allocation. + */ + #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA ) + bufferIsAllocated = 0; + #endif + + #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) + /* Always alloc, since output is of different type and + * its allocated size is not guarantee to be as large as + * the input. + */ + ARRAY_ALLOC( tempBuffer, endIdx-today+1 ); + #else + if( (outFastK == inHigh) || + (outFastK == inLow) || + (outFastK == inClose) ) + { + tempBuffer = outFastK; + } + else if( (outFastD == inHigh) || + (outFastD == inLow) || + (outFastD == inClose) ) + { + tempBuffer = outFastD; + } + else + { + #if !defined( _MANAGED ) && !defined( _JAVA ) + bufferIsAllocated = 1; + #endif + ARRAY_ALLOC(tempBuffer, endIdx-today+1 ); + } + #endif + + /* Do the K calculation */ + while( today <= endIdx ) + { + /* Set the lowest low */ + tmp = inLow[today]; + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inLow[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inLow[i]; + if( tmp < lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + diff = (highest - lowest)/100.0; + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + diff = (highest - lowest)/100.0; + } + + /* Set the highest high */ + tmp = inHigh[today]; + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inHigh[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inHigh[i]; + if( tmp > highest ) + { + highestIdx = i; + highest = tmp; + } + } + diff = (highest - lowest)/100.0; + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + diff = (highest - lowest)/100.0; + } + + /* Calculate stochastic. */ + if( diff != 0.0 ) + tempBuffer[outIdx++] = (inClose[today]-lowest)/diff; + else + tempBuffer[outIdx++] = 0.0; + + trailingIdx++; + today++; + } + + /* Fast-K calculation completed. This K calculation is returned + * to the caller. It is smoothed to become Fast-D. + */ + retCode = FUNCTION_CALL_DOUBLE(MA)( 0, outIdx-1, + tempBuffer, optInFastD_Period, + optInFastD_MAType, + outBegIdx, outNBElement, outFastD ); + + + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement)) == 0 ) + { + #if defined(USE_SINGLE_PRECISION_INPUT) + ARRAY_FREE( tempBuffer ); + #else + ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); + #endif + /* Something wrong happen? No further data? */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Copy tempBuffer into the caller buffer. + * (Calculation could not be done directly in the + * caller buffer because more input data then the + * requested range was needed for doing %D). + */ + ARRAY_MEMMOVE( outFastK, 0, tempBuffer, lookbackFastD, (int)VALUE_HANDLE_DEREF(outNBElement) ); + + /* Don't need K anymore, free it if it was allocated here. */ + #if defined(USE_SINGLE_PRECISION_INPUT) + ARRAY_FREE( tempBuffer ); + #else + ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); + #endif + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) + { + /* Something wrong happen while processing %D? */ + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + /* Note: Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::StochF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outFastK, +/* Generated */ SubArray^ outFastD ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::StochF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outFastK, +/* Generated */ cli::array^ outFastD ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stochF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_STOCHF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInFastD_MAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ double lowest, highest, tmp, diff; +/* Generated */ ARRAY_REF( tempBuffer ); +/* Generated */ int outIdx, lowestIdx, highestIdx; +/* Generated */ int lookbackTotal, lookbackK, lookbackFastD; +/* Generated */ int trailingIdx, today, i; +/* Generated */ #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA ) +/* Generated */ int bufferIsAllocated; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInFastD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_Period = 3; +/* Generated */ else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outFastK ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outFastD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackK = optInFastK_Period-1; +/* Generated */ lookbackFastD = LOOKBACK_CALL(MA)( optInFastD_Period, optInFastD_MAType ); +/* Generated */ lookbackTotal = lookbackK + lookbackFastD; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ trailingIdx = startIdx-lookbackTotal; +/* Generated */ today = trailingIdx+lookbackK; +/* Generated */ lowestIdx = highestIdx = -1; +/* Generated */ diff = highest = lowest = 0.0; +/* Generated */ #if !defined( _MANAGED ) && !defined(USE_SINGLE_PRECISION_INPUT) && !defined( _JAVA ) +/* Generated */ bufferIsAllocated = 0; +/* Generated */ #endif +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) || defined( USE_SUBARRAY ) +/* Generated */ ARRAY_ALLOC( tempBuffer, endIdx-today+1 ); +/* Generated */ #else +/* Generated */ if( (outFastK == inHigh) || +/* Generated */ (outFastK == inLow) || +/* Generated */ (outFastK == inClose) ) +/* Generated */ { +/* Generated */ tempBuffer = outFastK; +/* Generated */ } +/* Generated */ else if( (outFastD == inHigh) || +/* Generated */ (outFastD == inLow) || +/* Generated */ (outFastD == inClose) ) +/* Generated */ { +/* Generated */ tempBuffer = outFastD; +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ bufferIsAllocated = 1; +/* Generated */ #endif +/* Generated */ ARRAY_ALLOC(tempBuffer, endIdx-today+1 ); +/* Generated */ } +/* Generated */ #endif +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inLow[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inLow[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inLow[i]; +/* Generated */ if( tmp < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ tmp = inHigh[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inHigh[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inHigh[i]; +/* Generated */ if( tmp > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ diff = (highest - lowest)/100.0; +/* Generated */ } +/* Generated */ if( diff != 0.0 ) +/* Generated */ tempBuffer[outIdx++] = (inClose[today]-lowest)/diff; +/* Generated */ else +/* Generated */ tempBuffer[outIdx++] = 0.0; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(MA)( 0, outIdx-1, +/* Generated */ tempBuffer, optInFastD_Period, +/* Generated */ optInFastD_MAType, +/* Generated */ outBegIdx, outNBElement, outFastD ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement)) == 0 ) +/* Generated */ { +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ #else +/* Generated */ ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ ARRAY_MEMMOVE( outFastK, 0, tempBuffer, lookbackFastD, (int)VALUE_HANDLE_DEREF(outNBElement) ); +/* Generated */ #if defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ #else +/* Generated */ ARRAY_FREE_COND( bufferIsAllocated, tempBuffer ); +/* Generated */ #endif +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_STOCHRSI.c b/talib/ta_func/ta_STOCHRSI.c new file mode 100644 index 0000000..e8aaa60 --- /dev/null +++ b/talib/ta_func/ta_STOCHRSI.c @@ -0,0 +1,520 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * PP Peter Pudaite + * AA Andrew Atkinson + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 101103 PP Initial creation of code. + * 112603 MF Add independent control to the RSI period. + * 020605 AA Fix #1117656. NULL pointer assignement. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::StochRsiLookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType ) /* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int stochRsiLookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType ) /* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_STOCHRSI_Lookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInFastD_MAType ) /* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInFastK_Period. */ +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInFastD_Period. */ +/* Generated */ if( (int)optInFastD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_Period = 3; +/* Generated */ else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + retValue = LOOKBACK_CALL(RSI)( optInTimePeriod ) + LOOKBACK_CALL(STOCHF)( optInFastK_Period, optInFastD_Period, optInFastD_MAType ); + + return retValue; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_STOCHRSI - Stochastic Relative Strength Index + * + * Input = double + * Output = double, double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * optInFastK_Period:(From 1 to 100000) + * Time period for building the Fast-K line + * + * optInFastD_Period:(From 1 to 100000) + * Smoothing for making the Fast-D line. Usually set to 3 + * + * optInFastD_MAType: + * Type of Moving Average for Fast-D + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::StochRsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outFastK, +/* Generated */ SubArray^ outFastD ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::StochRsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outFastK, +/* Generated */ cli::array^ outFastD ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stochRsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_STOCHRSI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInFastD_MAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + ARRAY_REF(tempRSIBuffer); + + ENUM_DECLARATION(RetCode) retCode; + int lookbackTotal, lookbackSTOCHF, tempArraySize; + VALUE_HANDLE_INT(outBegIdx1); + VALUE_HANDLE_INT(outBegIdx2); + VALUE_HANDLE_INT(outNbElement1); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInFastK_Period. */ +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInFastD_Period. */ +/* Generated */ if( (int)optInFastD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_Period = 3; +/* Generated */ else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_MANAGED) && !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outFastK ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( !outFastD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Stochastic RSI + * + * Reference: "Stochastic RSI and Dynamic Momentum Index" + * by Tushar Chande and Stanley Kroll + * Stock&Commodities V.11:5 (189-199) + * + * The TA-Lib version offer flexibility beyond what is explain + * in the Stock&Commodities article. + * + * To calculate the "Unsmoothed stochastic RSI" with symetry like + * explain in the article, keep the optInTimePeriod and optInFastK_Period + * equal. Example: + * + * unsmoothed stoch RSI 14 : optInTimePeriod = 14 + * optInFastK_Period = 14 + * optInFastD_Period = 'x' + * + * The outFastK is the unsmoothed RSI discuss in the article. + * + * You can set the optInFastD_Period to smooth the RSI. The smooth + * version will be found in outFastD. The outFastK will still contain + * the unsmoothed stoch RSI. If you do not care about the smoothing of + * the StochRSI, just leave optInFastD_Period to 1 and ignore outFastD. + */ + + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Adjust startIdx to account for the lookback period. */ + lookbackSTOCHF = LOOKBACK_CALL(STOCHF)( optInFastK_Period, optInFastD_Period, optInFastD_MAType ); + lookbackTotal = LOOKBACK_CALL(RSI)( optInTimePeriod ) + lookbackSTOCHF; + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + tempArraySize = (endIdx - startIdx) + 1 + lookbackSTOCHF; + + ARRAY_ALLOC( tempRSIBuffer, tempArraySize ); + + retCode = FUNCTION_CALL(RSI)(startIdx-lookbackSTOCHF, + endIdx, + inReal, + optInTimePeriod, + VALUE_HANDLE_OUT(outBegIdx1), + VALUE_HANDLE_OUT(outNbElement1), + tempRSIBuffer); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) || VALUE_HANDLE_GET(outNbElement1) == 0 ) + { + ARRAY_FREE( tempRSIBuffer ); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + retCode = FUNCTION_CALL_DOUBLE(STOCHF)(0, + tempArraySize-1, + tempRSIBuffer, + tempRSIBuffer, + tempRSIBuffer, + optInFastK_Period, + optInFastD_Period, + optInFastD_MAType, + VALUE_HANDLE_OUT(outBegIdx2), + outNBElement, + outFastK, + outFastD); + + ARRAY_FREE( tempRSIBuffer ); + + if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) || ((int)VALUE_HANDLE_DEREF(outNBElement)) == 0 ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return retCode; + } + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::StochRsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outFastK, +/* Generated */ SubArray^ outFastD ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::StochRsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outFastK, +/* Generated */ cli::array^ outFastD ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode stochRsi( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ MAType optInFastD_MAType, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_STOCHRSI( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int optInFastK_Period, /* From 1 to 100000 */ +/* Generated */ int optInFastD_Period, /* From 1 to 100000 */ +/* Generated */ TA_MAType optInFastD_MAType, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outFastK[], +/* Generated */ double outFastD[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(tempRSIBuffer); +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int lookbackTotal, lookbackSTOCHF, tempArraySize; +/* Generated */ VALUE_HANDLE_INT(outBegIdx1); +/* Generated */ VALUE_HANDLE_INT(outBegIdx2); +/* Generated */ VALUE_HANDLE_INT(outNbElement1); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInFastK_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastK_Period = 5; +/* Generated */ else if( ((int)optInFastK_Period < 1) || ((int)optInFastK_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInFastD_Period == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_Period = 3; +/* Generated */ else if( ((int)optInFastD_Period < 1) || ((int)optInFastD_Period > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_MANAGED) && !defined(_JAVA) +/* Generated */ if( (int)optInFastD_MAType == TA_INTEGER_DEFAULT ) +/* Generated */ optInFastD_MAType = (TA_MAType)0; +/* Generated */ else if( ((int)optInFastD_MAType < 0) || ((int)optInFastD_MAType > 8) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outFastK ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !outFastD ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ lookbackSTOCHF = LOOKBACK_CALL(STOCHF)( optInFastK_Period, optInFastD_Period, optInFastD_MAType ); +/* Generated */ lookbackTotal = LOOKBACK_CALL(RSI)( optInTimePeriod ) + lookbackSTOCHF; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ tempArraySize = (endIdx - startIdx) + 1 + lookbackSTOCHF; +/* Generated */ ARRAY_ALLOC( tempRSIBuffer, tempArraySize ); +/* Generated */ retCode = FUNCTION_CALL(RSI)(startIdx-lookbackSTOCHF, +/* Generated */ endIdx, +/* Generated */ inReal, +/* Generated */ optInTimePeriod, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx1), +/* Generated */ VALUE_HANDLE_OUT(outNbElement1), +/* Generated */ tempRSIBuffer); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) || VALUE_HANDLE_GET(outNbElement1) == 0 ) +/* Generated */ { +/* Generated */ ARRAY_FREE( tempRSIBuffer ); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(STOCHF)(0, +/* Generated */ tempArraySize-1, +/* Generated */ tempRSIBuffer, +/* Generated */ tempRSIBuffer, +/* Generated */ tempRSIBuffer, +/* Generated */ optInFastK_Period, +/* Generated */ optInFastD_Period, +/* Generated */ optInFastD_MAType, +/* Generated */ VALUE_HANDLE_OUT(outBegIdx2), +/* Generated */ outNBElement, +/* Generated */ outFastK, +/* Generated */ outFastD); +/* Generated */ ARRAY_FREE( tempRSIBuffer ); +/* Generated */ if( retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) || ((int)VALUE_HANDLE_DEREF(outNBElement)) == 0 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SUB.c b/talib/ta_func/ta_SUB.c new file mode 100644 index 0000000..6a3ab39 --- /dev/null +++ b/talib/ta_func/ta_SUB.c @@ -0,0 +1,271 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SubLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int subLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SUB_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SUB - Vector Arithmetic Substraction + * + * Input = double, double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sub( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sub( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sub( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal0[], +/* Generated */ double inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SUB( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal0[], +/* Generated */ const double inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + +#ifndef TA_LIB_PRO + int i; +#endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Default return values */ +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = inReal0[i]-inReal1[i]; + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sub( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal0, +/* Generated */ SubArray^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sub( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal0, +/* Generated */ cli::array^ inReal1, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sub( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal0[], +/* Generated */ float inReal1[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SUB( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal0[], +/* Generated */ const float inReal1[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal0 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( !inReal1 ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = inReal0[i]-inReal1[i]; +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_SUM.c b/talib/ta_func/ta_SUM.c new file mode 100644 index 0000000..c28c5b6 --- /dev/null +++ b/talib/ta_func/ta_SUM.c @@ -0,0 +1,348 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::SumLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int sumLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_SUM_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_SUM - Summation + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sum( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sum( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sum( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_SUM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double periodTotal, tempReal; + int i, outIdx, trailingIdx, lookbackTotal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the MA calculation using tight loops. */ + + /* Add-up the initial period, except for the last value. */ + periodTotal = 0; + trailingIdx = startIdx-lookbackTotal; + + i=trailingIdx; + if( optInTimePeriod > 1 ) + { + while( i < startIdx ) + periodTotal += inReal[i++]; + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the inReal and + * outReal to be the same buffer. + */ + outIdx = 0; +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + do + { + periodTotal += inReal[i++]; + tempReal = periodTotal; + periodTotal -= inReal[trailingIdx++]; + outReal[outIdx++] = tempReal; + } while( i <= endIdx ); +#endif + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Sum( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Sum( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode sum( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_SUM( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double periodTotal, tempReal; +/* Generated */ int i, outIdx, trailingIdx, lookbackTotal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = (optInTimePeriod-1); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ periodTotal = 0; +/* Generated */ trailingIdx = startIdx-lookbackTotal; +/* Generated */ i=trailingIdx; +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ { +/* Generated */ while( i < startIdx ) +/* Generated */ periodTotal += inReal[i++]; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ do +/* Generated */ { +/* Generated */ periodTotal += inReal[i++]; +/* Generated */ tempReal = periodTotal; +/* Generated */ periodTotal -= inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = tempReal; +/* Generated */ } while( i <= endIdx ); +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_T3.c b/talib/ta_func/ta_T3.c new file mode 100644 index 0000000..d3675cf --- /dev/null +++ b/talib/ta_func/ta_T3.c @@ -0,0 +1,534 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MHL Matthew Lindblom + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 120802 MF Template creation. + * 032003 MHL Implementation of T3 + * 040503 MF Adapt for compatibility with published code + * for TradeStation and Metastock. + * See "Smoothing Techniques For More Accurate Signals" + * from Tim Tillson in Stock&Commodities V16:1 Page 33-37 + * 052603 MF Adapt code to compile with .NET Managed C++ + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::T3Lookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor ) /* From 0 to 1 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int t3Lookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor ) /* From 0 to 1 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_T3_Lookback( int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor ) /* From 0 to 1 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInVFactor == TA_REAL_DEFAULT ) +/* Generated */ optInVFactor = 7.000000e-1; +/* Generated */ else if( (optInVFactor < 0.000000e+0) ||/* Generated */ (optInVFactor > 1.000000e+0) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInVFactor); + return 6 * (optInTimePeriod-1) + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_T3,T3); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_T3 - Triple Exponential Moving Average (T3) + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * optInVFactor:(From 0 to 1) + * Volume Factor + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::T3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::T3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode t3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_T3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + + int outIdx, lookbackTotal; + int today, i; + double k, one_minus_k; + double e1, e2, e3, e4, e5, e6; + double c1, c2, c3, c4; + double tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInVFactor == TA_REAL_DEFAULT ) +/* Generated */ optInVFactor = 7.000000e-1; +/* Generated */ else if( (optInVFactor < 0.000000e+0) ||/* Generated */ (optInVFactor > 1.000000e+0) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* For an explanation of this function, please read: + * + * Magazine articles written by Tim Tillson + * + * Essentially, a T3 of time serie 't' is: + * EMA1(x,Period) = EMA(x,Period) + * EMA2(x,Period) = EMA(EMA1(x,Period),Period) + * GD(x,Period,vFactor) = (EMA1(x,Period)*(1+vFactor)) - (EMA2(x,Period)*vFactor) + * T3 = GD (GD ( GD(t, Period, vFactor), Period, vFactor), Period, vFactor); + * + * T3 offers a moving average with less lags then the + * traditional EMA. + * + * Do not confuse a T3 with EMA3. Both are called "Triple EMA" + * in the litterature. + * + */ + lookbackTotal = 6 * (optInTimePeriod - 1) + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_T3,T3); + if( startIdx <= lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + today = startIdx - lookbackTotal; + + k = 2.0/(optInTimePeriod+1.0); + one_minus_k = 1.0-k; + + /* Initialize e1 */ + tempReal = inReal[today++]; + for( i=optInTimePeriod-1; i > 0 ; i-- ) + tempReal += inReal[today++]; + e1 = tempReal / optInTimePeriod; + + /* Initialize e2 */ + tempReal = e1; + for( i=optInTimePeriod-1; i > 0 ; i-- ) + { + e1 = (k*inReal[today++])+(one_minus_k*e1); + tempReal += e1; + } + e2 = tempReal / optInTimePeriod; + + /* Initialize e3 */ + tempReal = e2; + for( i=optInTimePeriod-1; i > 0 ; i-- ) + { + e1 = (k*inReal[today++])+(one_minus_k*e1); + e2 = (k*e1)+(one_minus_k*e2); + tempReal += e2; + } + e3 = tempReal / optInTimePeriod; + + /* Initialize e4 */ + tempReal = e3; + for( i=optInTimePeriod-1; i > 0 ; i-- ) + { + e1 = (k*inReal[today++])+(one_minus_k*e1); + e2 = (k*e1)+(one_minus_k*e2); + e3 = (k*e2)+(one_minus_k*e3); + tempReal += e3; + } + e4 = tempReal / optInTimePeriod; + + /* Initialize e5 */ + tempReal = e4; + for( i=optInTimePeriod-1; i > 0 ; i-- ) + { + e1 = (k*inReal[today++])+(one_minus_k*e1); + e2 = (k*e1)+(one_minus_k*e2); + e3 = (k*e2)+(one_minus_k*e3); + e4 = (k*e3)+(one_minus_k*e4); + tempReal += e4; + } + e5 = tempReal / optInTimePeriod; + + /* Initialize e6 */ + tempReal = e5; + for( i=optInTimePeriod-1; i > 0 ; i-- ) + { + e1 = (k*inReal[today++])+(one_minus_k*e1); + e2 = (k*e1)+(one_minus_k*e2); + e3 = (k*e2)+(one_minus_k*e3); + e4 = (k*e3)+(one_minus_k*e4); + e5 = (k*e4)+(one_minus_k*e5); + tempReal += e5; + } + e6 = tempReal / optInTimePeriod; + + /* Skip the unstable period */ + while( today <= startIdx ) + { + /* Do the calculation but do not write the output */ + e1 = (k*inReal[today++])+(one_minus_k*e1); + e2 = (k*e1)+(one_minus_k*e2); + e3 = (k*e2)+(one_minus_k*e3); + e4 = (k*e3)+(one_minus_k*e4); + e5 = (k*e4)+(one_minus_k*e5); + e6 = (k*e5)+(one_minus_k*e6); + } + + /* Calculate the constants */ + tempReal = optInVFactor * optInVFactor; + c1 = -(tempReal * optInVFactor); + c2 = 3.0 * (tempReal - c1); + c3 = -6.0 * tempReal - 3.0 * (optInVFactor-c1); + c4 = 1.0 + 3.0 * optInVFactor - c1 + 3.0 * tempReal; + + /* Write the first output */ + outIdx = 0; + outReal[outIdx++] = c1*e6+c2*e5+c3*e4+c4*e3; + + /* Calculate and output the remaining of the range. */ + while( today <= endIdx ) + { + e1 = (k*inReal[today++])+(one_minus_k*e1); + e2 = (k*e1)+(one_minus_k*e2); + e3 = (k*e2)+(one_minus_k*e3); + e4 = (k*e3)+(one_minus_k*e4); + e5 = (k*e4)+(one_minus_k*e5); + e6 = (k*e5)+(one_minus_k*e6); + outReal[outIdx++] = c1*e6+c2*e5+c3*e4+c4*e3; + } + + /* Indicates to the caller the number of output + * successfully calculated. + */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::T3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::T3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode t3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_T3( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ double optInVFactor, /* From 0 to 1 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, lookbackTotal; +/* Generated */ int today, i; +/* Generated */ double k, one_minus_k; +/* Generated */ double e1, e2, e3, e4, e5, e6; +/* Generated */ double c1, c2, c3, c4; +/* Generated */ double tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInVFactor == TA_REAL_DEFAULT ) +/* Generated */ optInVFactor = 7.000000e-1; +/* Generated */ else if( (optInVFactor < 0.000000e+0) || (optInVFactor > 1.000000e+0) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = 6 * (optInTimePeriod - 1) + TA_GLOBALS_UNSTABLE_PERIOD(TA_FUNC_UNST_T3,T3); +/* Generated */ if( startIdx <= lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ today = startIdx - lookbackTotal; +/* Generated */ k = 2.0/(optInTimePeriod+1.0); +/* Generated */ one_minus_k = 1.0-k; +/* Generated */ tempReal = inReal[today++]; +/* Generated */ for( i=optInTimePeriod-1; i > 0 ; i-- ) +/* Generated */ tempReal += inReal[today++]; +/* Generated */ e1 = tempReal / optInTimePeriod; +/* Generated */ tempReal = e1; +/* Generated */ for( i=optInTimePeriod-1; i > 0 ; i-- ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ tempReal += e1; +/* Generated */ } +/* Generated */ e2 = tempReal / optInTimePeriod; +/* Generated */ tempReal = e2; +/* Generated */ for( i=optInTimePeriod-1; i > 0 ; i-- ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ e2 = (k*e1)+(one_minus_k*e2); +/* Generated */ tempReal += e2; +/* Generated */ } +/* Generated */ e3 = tempReal / optInTimePeriod; +/* Generated */ tempReal = e3; +/* Generated */ for( i=optInTimePeriod-1; i > 0 ; i-- ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ e2 = (k*e1)+(one_minus_k*e2); +/* Generated */ e3 = (k*e2)+(one_minus_k*e3); +/* Generated */ tempReal += e3; +/* Generated */ } +/* Generated */ e4 = tempReal / optInTimePeriod; +/* Generated */ tempReal = e4; +/* Generated */ for( i=optInTimePeriod-1; i > 0 ; i-- ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ e2 = (k*e1)+(one_minus_k*e2); +/* Generated */ e3 = (k*e2)+(one_minus_k*e3); +/* Generated */ e4 = (k*e3)+(one_minus_k*e4); +/* Generated */ tempReal += e4; +/* Generated */ } +/* Generated */ e5 = tempReal / optInTimePeriod; +/* Generated */ tempReal = e5; +/* Generated */ for( i=optInTimePeriod-1; i > 0 ; i-- ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ e2 = (k*e1)+(one_minus_k*e2); +/* Generated */ e3 = (k*e2)+(one_minus_k*e3); +/* Generated */ e4 = (k*e3)+(one_minus_k*e4); +/* Generated */ e5 = (k*e4)+(one_minus_k*e5); +/* Generated */ tempReal += e5; +/* Generated */ } +/* Generated */ e6 = tempReal / optInTimePeriod; +/* Generated */ while( today <= startIdx ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ e2 = (k*e1)+(one_minus_k*e2); +/* Generated */ e3 = (k*e2)+(one_minus_k*e3); +/* Generated */ e4 = (k*e3)+(one_minus_k*e4); +/* Generated */ e5 = (k*e4)+(one_minus_k*e5); +/* Generated */ e6 = (k*e5)+(one_minus_k*e6); +/* Generated */ } +/* Generated */ tempReal = optInVFactor * optInVFactor; +/* Generated */ c1 = -(tempReal * optInVFactor); +/* Generated */ c2 = 3.0 * (tempReal - c1); +/* Generated */ c3 = -6.0 * tempReal - 3.0 * (optInVFactor-c1); +/* Generated */ c4 = 1.0 + 3.0 * optInVFactor - c1 + 3.0 * tempReal; +/* Generated */ outIdx = 0; +/* Generated */ outReal[outIdx++] = c1*e6+c2*e5+c3*e4+c4*e3; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ e1 = (k*inReal[today++])+(one_minus_k*e1); +/* Generated */ e2 = (k*e1)+(one_minus_k*e2); +/* Generated */ e3 = (k*e2)+(one_minus_k*e3); +/* Generated */ e4 = (k*e3)+(one_minus_k*e4); +/* Generated */ e5 = (k*e4)+(one_minus_k*e5); +/* Generated */ e6 = (k*e5)+(one_minus_k*e6); +/* Generated */ outReal[outIdx++] = c1*e6+c2*e5+c3*e4+c4*e3; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TAN.c b/talib/ta_func/ta_TAN.c new file mode 100644 index 0000000..32b1b05 --- /dev/null +++ b/talib/ta_func/ta_TAN.c @@ -0,0 +1,259 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TanLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int tanLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TAN_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TAN - Vector Trigonometric Tan + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + #ifndef TA_LIB_PRO + int i; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_tan(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tan( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TAN( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_tan(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TANH.c b/talib/ta_func/ta_TANH.c new file mode 100644 index 0000000..007c4fa --- /dev/null +++ b/talib/ta_func/ta_TANH.c @@ -0,0 +1,260 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090807 MF Initial Version + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TanhLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int tanhLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TANH_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TANH - Vector Trigonometric Tanh + * + * Input = double + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tanh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tanh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tanh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TANH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + #ifndef TA_LIB_PRO + int i; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + +#ifdef TA_LIB_PRO + /* Section for code distributed with TA-Lib Pro only. */ +#else + for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) + { + outReal[outIdx] = std_tanh(inReal[i]); + } +#endif + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tanh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tanh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tanh( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TANH( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ #ifndef TA_LIB_PRO +/* Generated */ int i; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ #ifdef TA_LIB_PRO +/* Generated */ #else +/* Generated */ for( i=startIdx, outIdx=0; i <= endIdx; i++, outIdx++ ) +/* Generated */ { +/* Generated */ outReal[outIdx] = std_tanh(inReal[i]); +/* Generated */ } +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TEMA.c b/talib/ta_func/ta_TEMA.c new file mode 100644 index 0000000..5b74a40 --- /dev/null +++ b/talib/ta_func/ta_TEMA.c @@ -0,0 +1,490 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TemaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int temaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TEMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int retValue; + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* Get lookack for one EMA. */ + retValue = LOOKBACK_CALL(EMA)( optInTimePeriod ); + + return retValue * 3; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TEMA - Triple Exponential Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TEMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + ARRAY_REF(firstEMA); + ARRAY_REF(secondEMA); + double k; + + VALUE_HANDLE_INT(firstEMABegIdx); + VALUE_HANDLE_INT(firstEMANbElement); + VALUE_HANDLE_INT(secondEMABegIdx); + VALUE_HANDLE_INT(secondEMANbElement); + VALUE_HANDLE_INT(thirdEMABegIdx); + VALUE_HANDLE_INT(thirdEMANbElement); + + int tempInt, outIdx, lookbackTotal, lookbackEMA; + int firstEMAIdx, secondEMAIdx; + + ENUM_DECLARATION(RetCode) retCode; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* For an explanation of this function, please read: + * + * Stocks & Commodities V. 12:1 (11-19): + * Smoothing Data With Faster Moving Averages + * Stocks & Commodities V. 12:2 (72-80): + * Smoothing Data With Less Lag + * + * Both magazine articles written by Patrick G. Mulloy + * + * Essentially, a TEMA of time serie 't' is: + * EMA1 = EMA(t,period) + * EMA2 = EMA(EMA(t,period),period) + * EMA3 = EMA(EMA(EMA(t,period),period)) + * TEMA = 3*EMA1 - 3*EMA2 + EMA3 + * + * TEMA offers a moving average with less lags then the + * traditional EMA. + * + * Do not confuse a TEMA with EMA3. Both are called "Triple EMA" + * in the litterature. + * + * DEMA is very similar (and from the same author). + */ + + /* Will change only on success. */ + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + + /* Adjust startIdx to account for the lookback period. */ + lookbackEMA = LOOKBACK_CALL(EMA)( optInTimePeriod ); + lookbackTotal = lookbackEMA * 3; + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + /* Allocate a temporary buffer for the firstEMA. */ + tempInt = lookbackTotal+(endIdx-startIdx)+1; + ARRAY_ALLOC(firstEMA,tempInt); + #if !defined( _JAVA ) + if( !firstEMA ) + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + #endif + + /* Calculate the first EMA */ + k = PER_TO_K(optInTimePeriod); + retCode = FUNCTION_CALL(INT_EMA)( startIdx-(lookbackEMA*2), endIdx, inReal, + optInTimePeriod, k, + VALUE_HANDLE_OUT(firstEMABegIdx), VALUE_HANDLE_OUT(firstEMANbElement), + firstEMA ); + + /* Verify for failure or if not enough data after + * calculating the first EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(firstEMANbElement) == 0) ) + { + ARRAY_FREE( firstEMA ); + return retCode; + } + + /* Allocate a temporary buffer for storing the EMA2 */ + ARRAY_ALLOC(secondEMA,VALUE_HANDLE_GET(firstEMANbElement)); + #if !defined( _JAVA ) && !defined( USE_SUBARRAY ) + if( !secondEMA ) + { + ARRAY_FREE( firstEMA ); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(firstEMANbElement)-1, firstEMA, + optInTimePeriod, k, + VALUE_HANDLE_OUT(secondEMABegIdx), VALUE_HANDLE_OUT(secondEMANbElement), + secondEMA ); + + /* Return empty output on failure or if not enough data after + * calculating the second EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(secondEMANbElement) == 0) ) + { + ARRAY_FREE( firstEMA ); + ARRAY_FREE( secondEMA ); + return retCode; + } + + /* Calculate the EMA3 into the caller provided output. */ + retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(secondEMANbElement)-1, secondEMA, + optInTimePeriod, k, + VALUE_HANDLE_OUT(thirdEMABegIdx), VALUE_HANDLE_OUT(thirdEMANbElement), + outReal ); + + /* Return empty output on failure or if not enough data after + * calculating the third EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(thirdEMANbElement) == 0) ) + { + ARRAY_FREE( firstEMA ); + ARRAY_FREE( secondEMA ); + return retCode; + } + + /* Indicate where the output starts relative to + * the caller input. + */ + firstEMAIdx = VALUE_HANDLE_GET(thirdEMABegIdx) + VALUE_HANDLE_GET(secondEMABegIdx); + secondEMAIdx = VALUE_HANDLE_GET(thirdEMABegIdx); + VALUE_HANDLE_DEREF(outBegIdx) = firstEMAIdx + VALUE_HANDLE_GET(firstEMABegIdx); + + /* Do the TEMA: + * Iterate through the EMA3 (output buffer) and adjust + * the value by using the EMA2 and EMA1. + */ + outIdx = 0; + while( outIdx < VALUE_HANDLE_GET(thirdEMANbElement) ) + { + outReal[outIdx] += (3.0*firstEMA[firstEMAIdx++]) - (3.0*secondEMA[secondEMAIdx++]); + outIdx++; + } + + ARRAY_FREE( firstEMA ); + ARRAY_FREE( secondEMA ); + + /* Indicates to the caller the number of output + * successfully calculated. + */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tema( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TEMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ ARRAY_REF(firstEMA); +/* Generated */ ARRAY_REF(secondEMA); +/* Generated */ double k; +/* Generated */ VALUE_HANDLE_INT(firstEMABegIdx); +/* Generated */ VALUE_HANDLE_INT(firstEMANbElement); +/* Generated */ VALUE_HANDLE_INT(secondEMABegIdx); +/* Generated */ VALUE_HANDLE_INT(secondEMANbElement); +/* Generated */ VALUE_HANDLE_INT(thirdEMABegIdx); +/* Generated */ VALUE_HANDLE_INT(thirdEMANbElement); +/* Generated */ int tempInt, outIdx, lookbackTotal, lookbackEMA; +/* Generated */ int firstEMAIdx, secondEMAIdx; +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ lookbackEMA = LOOKBACK_CALL(EMA)( optInTimePeriod ); +/* Generated */ lookbackTotal = lookbackEMA * 3; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ tempInt = lookbackTotal+(endIdx-startIdx)+1; +/* Generated */ ARRAY_ALLOC(firstEMA,tempInt); +/* Generated */ #if !defined( _JAVA ) +/* Generated */ if( !firstEMA ) +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ #endif +/* Generated */ k = PER_TO_K(optInTimePeriod); +/* Generated */ retCode = FUNCTION_CALL(INT_EMA)( startIdx-(lookbackEMA*2), endIdx, inReal, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(firstEMABegIdx), VALUE_HANDLE_OUT(firstEMANbElement), +/* Generated */ firstEMA ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(firstEMANbElement) == 0) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ ARRAY_ALLOC(secondEMA,VALUE_HANDLE_GET(firstEMANbElement)); +/* Generated */ #if !defined( _JAVA ) && !defined( USE_SUBARRAY ) +/* Generated */ if( !secondEMA ) +/* Generated */ { +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(firstEMANbElement)-1, firstEMA, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(secondEMABegIdx), VALUE_HANDLE_OUT(secondEMANbElement), +/* Generated */ secondEMA ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(secondEMANbElement) == 0) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ ARRAY_FREE( secondEMA ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, VALUE_HANDLE_GET(secondEMANbElement)-1, secondEMA, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(thirdEMABegIdx), VALUE_HANDLE_OUT(thirdEMANbElement), +/* Generated */ outReal ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(thirdEMANbElement) == 0) ) +/* Generated */ { +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ ARRAY_FREE( secondEMA ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ firstEMAIdx = VALUE_HANDLE_GET(thirdEMABegIdx) + VALUE_HANDLE_GET(secondEMABegIdx); +/* Generated */ secondEMAIdx = VALUE_HANDLE_GET(thirdEMABegIdx); +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = firstEMAIdx + VALUE_HANDLE_GET(firstEMABegIdx); +/* Generated */ outIdx = 0; +/* Generated */ while( outIdx < VALUE_HANDLE_GET(thirdEMANbElement) ) +/* Generated */ { +/* Generated */ outReal[outIdx] += (3.0*firstEMA[firstEMAIdx++]) - (3.0*secondEMA[secondEMAIdx++]); +/* Generated */ outIdx++; +/* Generated */ } +/* Generated */ ARRAY_FREE( firstEMA ); +/* Generated */ ARRAY_FREE( secondEMA ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TRANGE.c b/talib/ta_func/ta_TRANGE.c new file mode 100644 index 0000000..9a60dcc --- /dev/null +++ b/talib/ta_func/ta_TRANGE.c @@ -0,0 +1,338 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TrueRangeLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int trueRangeLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TRANGE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TRANGE - True Range + * + * Input = High, Low, Close + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TrueRange( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TrueRange( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode trueRange( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TRANGE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int today, outIdx; + double val2, val3, greatest; + double tempCY, tempLT, tempHT; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* True Range is the greatest of the following: + * + * val1 = distance from today's high to today's low. + * val2 = distance from yesterday's close to today's high. + * val3 = distance from yesterday's close to today's low. + * + * Some books and software makes the first TR value to be + * the (high - low) of the first bar. This function instead + * ignore the first price bar, and only output starting at the + * second price bar are valid. This is done for avoiding + * inconsistency. + */ + + /* Move up the start index if there is not + * enough initial data. + * Always one price bar gets consumed. + */ + if( startIdx < 1 ) + startIdx = 1; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; + today = startIdx; + while( today <= endIdx ) + { + + /* Find the greatest of the 3 values. */ + tempLT = inLow[today]; + tempHT = inHigh[today]; + tempCY = inClose[today-1]; + greatest = tempHT - tempLT; /* val1 */ + + val2 = std_fabs( tempCY - tempHT ); + if( val2 > greatest ) + greatest = val2; + + val3 = std_fabs( tempCY - tempLT ); + if( val3 > greatest ) + greatest = val3; + + outReal[outIdx++] = greatest; + today++; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TrueRange( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TrueRange( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode trueRange( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TRANGE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int today, outIdx; +/* Generated */ double val2, val3, greatest; +/* Generated */ double tempCY, tempLT, tempHT; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ if( startIdx < 1 ) +/* Generated */ startIdx = 1; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tempLT = inLow[today]; +/* Generated */ tempHT = inHigh[today]; +/* Generated */ tempCY = inClose[today-1]; +/* Generated */ greatest = tempHT - tempLT; +/* Generated */ val2 = std_fabs( tempCY - tempHT ); +/* Generated */ if( val2 > greatest ) +/* Generated */ greatest = val2; +/* Generated */ val3 = std_fabs( tempCY - tempLT ); +/* Generated */ if( val3 > greatest ) +/* Generated */ greatest = val3; +/* Generated */ outReal[outIdx++] = greatest; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TRIMA.c b/talib/ta_func/ta_TRIMA.c new file mode 100644 index 0000000..ddb6719 --- /dev/null +++ b/talib/ta_func/ta_TRIMA.c @@ -0,0 +1,657 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * CR Chris (crokusek@hotmail.com) + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010503 MF Initial Coding + * 031703 MF Fix #701060. Correct logic when using a range with + * startIdx/endIdx. Thanks to Chris for reporting this. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TrimaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int trimaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TRIMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TRIMA - Triangular Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Trima( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Trima( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode trima( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TRIMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int lookbackTotal; + + double numerator; + double numeratorSub; + double numeratorAdd; + + int i, outIdx, todayIdx, trailingIdx, middleIdx; + double factor, tempReal; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to calculate at least one output. + */ + lookbackTotal = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* TRIMA Description + * ================= + * The triangular MA is a weighted moving average. Instead of the + * TA_WMA who put more weigth on the latest price bar, the triangular + * put more weigth on the data in the middle of the specified period. + * + * Examples: + * For TimeSerie={a,b,c,d,e,f...} ('a' is the older price) + * + * 1st value for TRIMA 4-Period is: ((1*a)+(2*b)+(2*c)+(1*d)) / 6 + * 2nd value for TRIMA 4-Period is: ((1*b)+(2*c)+(2*d)+(1*e)) / 6 + * + * 1st value for TRIMA 5-Period is: ((1*a)+(2*b)+(3*c)+(2*d)+(1*e)) / 9 + * 2nd value for TRIMA 5-Period is: ((1*b)+(2*c)+(3*d)+(2*e)+(1*f)) / 9 + * + * Generally Accepted Implementation + * ================================== + * Using algebra, it can be demonstrated that the TRIMA is equivalent to + * doing a SMA of a SMA. The following explain the rules: + * + * (1) When the period is even, TRIMA(x,period)=SMA(SMA(x,period/2),(period/2)+1) + * (2) When the period is odd, TRIMA(x,period)=SMA(SMA(x,(period+1)/2),(period+1)/2) + * + * In other word: + * (1) A period of 4 becomes TRIMA(x,4) = SMA( SMA( x, 2), 3 ) + * (2) A period of 5 becomes TRIMA(x,5) = SMA( SMA( x, 3), 3 ) + * + * The SMA of a SMA is the algorithm generaly found in books. + * + * Tradestation Implementation + * =========================== + * Tradestation deviate from the generally accepted implementation by + * making the TRIMA to be as follow: + * TRIMA(x,period) = SMA( SMA( x, (int)(period/2)+1), (int)(period/2)+1 ); + * This formula is done regardless if the period is even or odd. + * + * In other word: + * (1) A period of 4 becomes TRIMA(x,4) = SMA( SMA( x, 3), 3 ) + * (2) A period of 5 becomes TRIMA(x,5) = SMA( SMA( x, 3), 3 ) + * (3) A period of 6 becomes TRIMA(x,5) = SMA( SMA( x, 4), 4 ) + * (4) A period of 7 becomes TRIMA(x,5) = SMA( SMA( x, 4), 4 ) + * + * It is not clear to me if the Tradestation approach is a bug or a deliberate + * decision to do things differently. + * + * Metastock Implementation + * ======================== + * Output is the same as the generally accepted implementation. + * + * TA-Lib Implementation + * ===================== + * Output is also the same as the generally accepted implementation. + * + * For speed optimization and avoid memory allocation, TA-Lib use + * a better algorithm than the usual SMA of a SMA. + * + * The calculation from one TRIMA value to the next is done by doing 4 + * little adjustment (the following show a TRIMA 4-period): + * + * TRIMA at time 'd': ((1*a)+(2*b)+(2*c)+(1*d)) / 6 + * TRIMA at time 'e': ((1*b)+(2*c)+(2*d)+(1*e)) / 6 + * + * To go from TRIMA 'd' to 'e', the following is done: + * 1) 'a' and 'b' are substract from the numerator. + * 2) 'd' is added to the numerator. + * 3) 'e' is added to the numerator. + * 4) Calculate TRIMA by doing numerator / 6 + * 5) Repeat sequence for next output + * + * These operations are the same steps done by TA-LIB: + * 1) is done by numeratorSub + * 2) is done by numeratorAdd. + * 3) is obtain from the latest input + * 4) Calculate and write TRIMA in the output + * 5) Repeat for next output. + * + * Of course, numerotrAdd and numeratorSub needs to be + * adjusted for each iteration. + * + * The update of numeratorSub needs values from the input at + * the trailingIdx and middleIdx position. + * + * The update of numeratorAdd needs values from the input at + * the middleIdx and todayIdx. + */ + + outIdx = 0; + + if( (optInTimePeriod % 2) == 1 ) + { + /* Logic for Odd period */ + + /* Calculate the factor which is 1 divided by the + * sumation of the weight. + * + * The sum of the weight is calculated as follow: + * + * The simple sumation serie 1+2+3... n can be + * express as n(n+1)/2 + * + * From this logic, a "triangular" sumation formula + * can be found depending if the period is odd or even. + * + * Odd Period Formula: + * period = 5 and with n=(int)(period/2) + * the formula for a "triangular" serie is: + * 1+2+3+2+1 = (n*(n+1))+n+1 + * = (n+1)*(n+1) + * = 3 * 3 = 9 + * + * Even period Formula: + * period = 6 and with n=(int)(period/2) + * the formula for a "triangular" serie is: + * 1+2+3+3+2+1 = n*(n+1) + * = 3 * 4 = 12 + */ + + /* Note: entirely done with int and becomes double only + * on assignement to the factor variable. + */ + i = (optInTimePeriod>>1); + factor = (i+1)*(i+1); + factor = 1.0/factor; + + /* Initialize all the variable before + * starting to iterate for each output. + */ + trailingIdx = startIdx-lookbackTotal; + middleIdx = trailingIdx + i; + todayIdx = middleIdx + i; + numerator = 0.0; + numeratorSub = 0.0; + for( i=middleIdx; i >= trailingIdx; i-- ) + { + tempReal = inReal[i]; + numeratorSub += tempReal; + numerator += numeratorSub; + } + numeratorAdd = 0.0; + middleIdx++; + for( i=middleIdx; i <= todayIdx; i++ ) + { + tempReal = inReal[i]; + numeratorAdd += tempReal; + numerator += numeratorAdd; + } + + /* Write the first output */ + outIdx = 0; + tempReal = inReal[trailingIdx++]; + outReal[outIdx++] = numerator * factor; + todayIdx++; + + /* Note: The value at the trailingIdx was saved + * in tempReal to account for the case where + * outReal and inReal are ptr on the same + * buffer. + */ + + /* Iterate for remaining output */ + while( todayIdx <= endIdx ) + { + /* Step (1) */ + numerator -= numeratorSub; + numeratorSub -= tempReal; + tempReal = inReal[middleIdx++]; + numeratorSub += tempReal; + + /* Step (2) */ + numerator += numeratorAdd; + numeratorAdd -= tempReal; + tempReal = inReal[todayIdx++]; + numeratorAdd += tempReal; + + /* Step (3) */ + numerator += tempReal; + + /* Step (4) */ + tempReal = inReal[trailingIdx++]; + outReal[outIdx++] = numerator * factor; + } + } + else + { + /* Even logic. + * + * Very similar to the odd logic, except: + * - calculation of the factor is different. + * - the coverage of the numeratorSub and numeratorAdd is + * slightly different. + * - Adjustment of numeratorAdd is different. See Step (2). + */ + i = (optInTimePeriod>>1); + factor = i*(i+1); + factor = 1.0/factor; + + /* Initialize all the variable before + * starting to iterate for each output. + */ + trailingIdx = startIdx-lookbackTotal; + middleIdx = trailingIdx + i - 1; + todayIdx = middleIdx + i; + numerator = 0.0; + + numeratorSub = 0.0; + + for( i=middleIdx; i >= trailingIdx; i-- ) + { + tempReal = inReal[i]; + numeratorSub += tempReal; + numerator += numeratorSub; + } + numeratorAdd = 0.0; + middleIdx++; + for( i=middleIdx; i <= todayIdx; i++ ) + { + tempReal = inReal[i]; + numeratorAdd += tempReal; + numerator += numeratorAdd; + } + + /* Write the first output */ + outIdx = 0; + tempReal = inReal[trailingIdx++]; + outReal[outIdx++] = numerator * factor; + todayIdx++; + + /* Note: The value at the trailingIdx was saved + * in tempReal to account for the case where + * outReal and inReal are ptr on the same + * buffer. + */ + + /* Iterate for remaining output */ + while( todayIdx <= endIdx ) + { + /* Step (1) */ + numerator -= numeratorSub; + numeratorSub -= tempReal; + tempReal = inReal[middleIdx++]; + numeratorSub += tempReal; + + /* Step (2) */ + numeratorAdd -= tempReal; + numerator += numeratorAdd; + tempReal = inReal[todayIdx++]; + numeratorAdd += tempReal; + + /* Step (3) */ + numerator += tempReal; + + /* Step (4) */ + tempReal = inReal[trailingIdx++]; + outReal[outIdx++] = numerator * factor; + } + + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Trima( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Trima( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode trima( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TRIMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int lookbackTotal; +/* Generated */ double numerator; +/* Generated */ double numeratorSub; +/* Generated */ double numeratorAdd; +/* Generated */ int i, outIdx, todayIdx, trailingIdx, middleIdx; +/* Generated */ double factor, tempReal; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = (optInTimePeriod-1); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ if( (optInTimePeriod % 2) == 1 ) +/* Generated */ { +/* Generated */ i = (optInTimePeriod>>1); +/* Generated */ factor = (i+1)*(i+1); +/* Generated */ factor = 1.0/factor; +/* Generated */ trailingIdx = startIdx-lookbackTotal; +/* Generated */ middleIdx = trailingIdx + i; +/* Generated */ todayIdx = middleIdx + i; +/* Generated */ numerator = 0.0; +/* Generated */ numeratorSub = 0.0; +/* Generated */ for( i=middleIdx; i >= trailingIdx; i-- ) +/* Generated */ { +/* Generated */ tempReal = inReal[i]; +/* Generated */ numeratorSub += tempReal; +/* Generated */ numerator += numeratorSub; +/* Generated */ } +/* Generated */ numeratorAdd = 0.0; +/* Generated */ middleIdx++; +/* Generated */ for( i=middleIdx; i <= todayIdx; i++ ) +/* Generated */ { +/* Generated */ tempReal = inReal[i]; +/* Generated */ numeratorAdd += tempReal; +/* Generated */ numerator += numeratorAdd; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = numerator * factor; +/* Generated */ todayIdx++; +/* Generated */ while( todayIdx <= endIdx ) +/* Generated */ { +/* Generated */ numerator -= numeratorSub; +/* Generated */ numeratorSub -= tempReal; +/* Generated */ tempReal = inReal[middleIdx++]; +/* Generated */ numeratorSub += tempReal; +/* Generated */ numerator += numeratorAdd; +/* Generated */ numeratorAdd -= tempReal; +/* Generated */ tempReal = inReal[todayIdx++]; +/* Generated */ numeratorAdd += tempReal; +/* Generated */ numerator += tempReal; +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = numerator * factor; +/* Generated */ } +/* Generated */ } +/* Generated */ else +/* Generated */ { +/* Generated */ i = (optInTimePeriod>>1); +/* Generated */ factor = i*(i+1); +/* Generated */ factor = 1.0/factor; +/* Generated */ trailingIdx = startIdx-lookbackTotal; +/* Generated */ middleIdx = trailingIdx + i - 1; +/* Generated */ todayIdx = middleIdx + i; +/* Generated */ numerator = 0.0; +/* Generated */ numeratorSub = 0.0; +/* Generated */ for( i=middleIdx; i >= trailingIdx; i-- ) +/* Generated */ { +/* Generated */ tempReal = inReal[i]; +/* Generated */ numeratorSub += tempReal; +/* Generated */ numerator += numeratorSub; +/* Generated */ } +/* Generated */ numeratorAdd = 0.0; +/* Generated */ middleIdx++; +/* Generated */ for( i=middleIdx; i <= todayIdx; i++ ) +/* Generated */ { +/* Generated */ tempReal = inReal[i]; +/* Generated */ numeratorAdd += tempReal; +/* Generated */ numerator += numeratorAdd; +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = numerator * factor; +/* Generated */ todayIdx++; +/* Generated */ while( todayIdx <= endIdx ) +/* Generated */ { +/* Generated */ numerator -= numeratorSub; +/* Generated */ numeratorSub -= tempReal; +/* Generated */ tempReal = inReal[middleIdx++]; +/* Generated */ numeratorSub += tempReal; +/* Generated */ numeratorAdd -= tempReal; +/* Generated */ numerator += numeratorAdd; +/* Generated */ tempReal = inReal[todayIdx++]; +/* Generated */ numeratorAdd += tempReal; +/* Generated */ numerator += tempReal; +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = numerator * factor; +/* Generated */ } +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TRIX.c b/talib/ta_func/ta_TRIX.c new file mode 100644 index 0000000..7cf609c --- /dev/null +++ b/talib/ta_func/ta_TRIX.c @@ -0,0 +1,459 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * AA Andrew Atkinson + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 020605 AA Fix #1117656. NULL pointer assignement. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TrixLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int trixLookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TRIX_Lookback( int optInTimePeriod ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int emaLookback; +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + emaLookback = LOOKBACK_CALL(EMA)( optInTimePeriod ); + return (emaLookback*3) + LOOKBACK_CALL(ROCR)( 1 ); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TRIX - 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Trix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Trix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode trix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TRIX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + double k; + ARRAY_REF(tempBuffer); + VALUE_HANDLE_INT(nbElement); + VALUE_HANDLE_INT(begIdx); + int totalLookback; + int emaLookback, rocLookback; + ENUM_DECLARATION(RetCode) retCode; + int nbElementToOutput; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Adjust the startIdx to account for the lookback. */ + emaLookback = LOOKBACK_CALL(EMA)( optInTimePeriod ); + rocLookback = LOOKBACK_CALL(ROCR)( 1 ); + totalLookback = (emaLookback*3) + rocLookback; + + if( startIdx < totalLookback ) + startIdx = totalLookback; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + nbElementToOutput = (endIdx-startIdx)+1+totalLookback; + + /* Allocate a temporary buffer for performing + * the calculation. + */ + ARRAY_ALLOC(tempBuffer, nbElementToOutput ); + + #if !defined( _JAVA ) && !defined( USE_SUBARRAY ) + if( !tempBuffer ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); + } + #endif + + /* Calculate the first EMA */ + k = PER_TO_K(optInTimePeriod); + retCode = FUNCTION_CALL(INT_EMA)( (startIdx-totalLookback), endIdx, inReal, + optInTimePeriod, k, + VALUE_HANDLE_OUT(begIdx), VALUE_HANDLE_OUT(nbElement), + tempBuffer ); + + /* Verify for failure or if not enough data after + * calculating the EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(nbElement) == 0) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + ARRAY_FREE( tempBuffer ); + return retCode; + } + + nbElementToOutput--; /* Make this variable zero base from now on. */ + + /* Calculate the second EMA */ + nbElementToOutput -= emaLookback; + retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, nbElementToOutput, tempBuffer, + optInTimePeriod, k, + VALUE_HANDLE_OUT(begIdx), VALUE_HANDLE_OUT(nbElement), + tempBuffer ); + + /* Verify for failure or if not enough data after + * calculating the EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(nbElement) == 0) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + ARRAY_FREE( tempBuffer ); + return retCode; + } + + /* Calculate the third EMA */ + nbElementToOutput -= emaLookback; + retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, nbElementToOutput, tempBuffer, + optInTimePeriod, k, + VALUE_HANDLE_OUT(begIdx), VALUE_HANDLE_OUT(nbElement), + tempBuffer ); + + /* Verify for failure or if not enough data after + * calculating the EMA. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(nbElement) == 0) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + ARRAY_FREE( tempBuffer ); + return retCode; + } + + /* Calculate the 1-day Rate-Of-Change */ + nbElementToOutput -= emaLookback; + retCode = FUNCTION_CALL_DOUBLE(ROC)( 0, nbElementToOutput, + tempBuffer, + 1, VALUE_HANDLE_OUT(begIdx), outNBElement, + outReal ); + + ARRAY_FREE( tempBuffer ); + /* Verify for failure or if not enough data after + * calculating the rate-of-change. + */ + if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + return retCode; + } + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Trix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Trix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode trix( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TRIX( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double k; +/* Generated */ ARRAY_REF(tempBuffer); +/* Generated */ VALUE_HANDLE_INT(nbElement); +/* Generated */ VALUE_HANDLE_INT(begIdx); +/* Generated */ int totalLookback; +/* Generated */ int emaLookback, rocLookback; +/* Generated */ ENUM_DECLARATION(RetCode) retCode; +/* Generated */ int nbElementToOutput; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ emaLookback = LOOKBACK_CALL(EMA)( optInTimePeriod ); +/* Generated */ rocLookback = LOOKBACK_CALL(ROCR)( 1 ); +/* Generated */ totalLookback = (emaLookback*3) + rocLookback; +/* Generated */ if( startIdx < totalLookback ) +/* Generated */ startIdx = totalLookback; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ nbElementToOutput = (endIdx-startIdx)+1+totalLookback; +/* Generated */ ARRAY_ALLOC(tempBuffer, nbElementToOutput ); +/* Generated */ #if !defined( _JAVA ) && !defined( USE_SUBARRAY ) +/* Generated */ if( !tempBuffer ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ return ENUM_VALUE(RetCode,TA_ALLOC_ERR,AllocErr); +/* Generated */ } +/* Generated */ #endif +/* Generated */ k = PER_TO_K(optInTimePeriod); +/* Generated */ retCode = FUNCTION_CALL(INT_EMA)( (startIdx-totalLookback), endIdx, inReal, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(begIdx), VALUE_HANDLE_OUT(nbElement), +/* Generated */ tempBuffer ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(nbElement) == 0) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ nbElementToOutput--; +/* Generated */ nbElementToOutput -= emaLookback; +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, nbElementToOutput, tempBuffer, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(begIdx), VALUE_HANDLE_OUT(nbElement), +/* Generated */ tempBuffer ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(nbElement) == 0) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ nbElementToOutput -= emaLookback; +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(INT_EMA)( 0, nbElementToOutput, tempBuffer, +/* Generated */ optInTimePeriod, k, +/* Generated */ VALUE_HANDLE_OUT(begIdx), VALUE_HANDLE_OUT(nbElement), +/* Generated */ tempBuffer ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || (VALUE_HANDLE_GET(nbElement) == 0) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ nbElementToOutput -= emaLookback; +/* Generated */ retCode = FUNCTION_CALL_DOUBLE(ROC)( 0, nbElementToOutput, +/* Generated */ tempBuffer, +/* Generated */ 1, VALUE_HANDLE_OUT(begIdx), outNBElement, +/* Generated */ outReal ); +/* Generated */ ARRAY_FREE( tempBuffer ); +/* Generated */ if( (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success) ) || ((int)VALUE_HANDLE_DEREF(outNBElement) == 0) ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ return retCode; +/* Generated */ } +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TSF.c b/talib/ta_func/ta_TSF.c new file mode 100644 index 0000000..5276fd2 --- /dev/null +++ b/talib/ta_func/ta_TSF.c @@ -0,0 +1,363 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 090103 MF Initial coding re-using the existing TA_LinearReg + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TsfLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int tsfLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TSF_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TSF - Time Series Forecast + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tsf( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tsf( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tsf( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TSF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int outIdx; + + int today, lookbackTotal; + double SumX, SumXY, SumY, SumXSqr, Divisor; + + double m, b; + int i; + + double tempValue1; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Linear Regression is a concept also known as the + * "least squares method" or "best fit." Linear + * Regression attempts to fit a straight line between + * several data points in such a way that distance + * between each data point and the line is minimized. + * + * For each point, a straight line over the specified + * previous bar period is determined in terms + * of y = b + m*x: + * + * TA_LINEARREG : Returns b+m*(period-1) + * TA_LINEARREG_SLOPE : Returns 'm' + * TA_LINEARREG_ANGLE : Returns 'm' in degree. + * TA_LINEARREG_INTERCEPT: Returns 'b' + * TA_TSF : Returns b+m*(period) + */ + + /* Adjust startIdx to account for the lookback period. */ + lookbackTotal = LOOKBACK_CALL(TSF)( optInTimePeriod ); + + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + outIdx = 0; /* Index into the output. */ + today = startIdx; + + SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; + SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; + Divisor = SumX * SumX - optInTimePeriod * SumXSqr; + + while( today <= endIdx ) + { + SumXY = 0; + SumY = 0; + for( i = optInTimePeriod; i-- != 0; ) + { + SumY += tempValue1 = inReal[today - i]; + SumXY += (double)i * tempValue1; + } + m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; + b = ( SumY - m * SumX ) / (double)optInTimePeriod; + outReal[outIdx++] = b + m * (double)optInTimePeriod; + today++; + } + + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Tsf( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Tsf( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode tsf( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TSF( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx; +/* Generated */ int today, lookbackTotal; +/* Generated */ double SumX, SumXY, SumY, SumXSqr, Divisor; +/* Generated */ double m, b; +/* Generated */ int i; +/* Generated */ double tempValue1; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = LOOKBACK_CALL(TSF)( optInTimePeriod ); +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ SumX = optInTimePeriod * ( optInTimePeriod - 1 ) * 0.5; +/* Generated */ SumXSqr = optInTimePeriod * ( optInTimePeriod - 1 ) * ( 2 * optInTimePeriod - 1 ) / 6; +/* Generated */ Divisor = SumX * SumX - optInTimePeriod * SumXSqr; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ SumXY = 0; +/* Generated */ SumY = 0; +/* Generated */ for( i = optInTimePeriod; i-- != 0; ) +/* Generated */ { +/* Generated */ SumY += tempValue1 = inReal[today - i]; +/* Generated */ SumXY += (double)i * tempValue1; +/* Generated */ } +/* Generated */ m = ( optInTimePeriod * SumXY - SumX * SumY) / Divisor; +/* Generated */ b = ( SumY - m * SumX ) / (double)optInTimePeriod; +/* Generated */ outReal[outIdx++] = b + m * (double)optInTimePeriod; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_TYPPRICE.c b/talib/ta_func/ta_TYPPRICE.c new file mode 100644 index 0000000..218c8fc --- /dev/null +++ b/talib/ta_func/ta_TYPPRICE.c @@ -0,0 +1,281 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 112605 MF Fix outBegIdx when startIdx != 0 + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::TypPriceLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int typPriceLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_TYPPRICE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* This function have no lookback needed. */ + + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_TYPPRICE - Typical Price + * + * Input = High, Low, Close + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TypPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TypPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode typPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_TYPPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int outIdx, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Typical price = (High + Low + Close ) / 3 */ + outIdx = 0; + + for( i= startIdx; i <= endIdx; i++ ) + { + outReal[outIdx++] = ( inHigh [i] + + inLow [i] + + inClose[i] ) / 3.0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TypPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TypPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode typPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_TYPPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ for( i= startIdx; i <= endIdx; i++ ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = ( inHigh [i] + +/* Generated */ inLow [i] + +/* Generated */ inClose[i] ) / 3.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_ULTOSC.c b/talib/ta_func/ta_ULTOSC.c new file mode 100644 index 0000000..00f4eaa --- /dev/null +++ b/talib/ta_func/ta_ULTOSC.c @@ -0,0 +1,592 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * DM Drew McCormack (http://www.trade-strategist.com) + * MF Mario Fortier + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 281206 DM Initial Implementation + * 010606 MF Abstract local arrays. Detect divide by zero. + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::UltOscLookback( int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3 ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int ultOscLookback( int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3 ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_ULTOSC_Lookback( int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3 ) /* From 1 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + int maxPeriod; +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod1. */ +/* Generated */ if( (int)optInTimePeriod1 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod1 = 7; +/* Generated */ else if( ((int)optInTimePeriod1 < 1) || ((int)optInTimePeriod1 > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInTimePeriod2. */ +/* Generated */ if( (int)optInTimePeriod2 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod2 = 14; +/* Generated */ else if( ((int)optInTimePeriod2 < 1) || ((int)optInTimePeriod2 > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ /* min/max are checked for optInTimePeriod3. */ +/* Generated */ if( (int)optInTimePeriod3 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod3 = 28; +/* Generated */ else if( ((int)optInTimePeriod3 < 1) || ((int)optInTimePeriod3 > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* Lookback for the Ultimate Oscillator is the lookback of the SMA with the longest + * time period, plus 1 for the True Range. + */ + maxPeriod = max( max(optInTimePeriod1, optInTimePeriod2), optInTimePeriod3); + return LOOKBACK_CALL(SMA)( maxPeriod ) + 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_ULTOSC - Ultimate Oscillator + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod1:(From 1 to 100000) + * Number of bars for 1st period. + * + * optInTimePeriod2:(From 1 to 100000) + * Number of bars fro 2nd period + * + * optInTimePeriod3:(From 1 to 100000) + * Number of bars for 3rd period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::UltOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::UltOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ultOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_ULTOSC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double a1Total, a2Total, a3Total; + double b1Total, b2Total, b3Total; + double trueLow, trueRange, closeMinusTrueLow; + double tempDouble, output, tempHT, tempLT, tempCY; + int lookbackTotal; + int longestPeriod, longestIndex; + int i,j,today,outIdx; + int trailingIdx1, trailingIdx2, trailingIdx3; + + ARRAY_INT_LOCAL(usedFlag,3); + ARRAY_INT_LOCAL(periods,3); + ARRAY_INT_LOCAL(sortedPeriods,3); + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod1. */ +/* Generated */ if( (int)optInTimePeriod1 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod1 = 7; +/* Generated */ else if( ((int)optInTimePeriod1 < 1) || ((int)optInTimePeriod1 > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInTimePeriod2. */ +/* Generated */ if( (int)optInTimePeriod2 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod2 = 14; +/* Generated */ else if( ((int)optInTimePeriod2 < 1) || ((int)optInTimePeriod2 > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ /* min/max are checked for optInTimePeriod3. */ +/* Generated */ if( (int)optInTimePeriod3 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod3 = 28; +/* Generated */ else if( ((int)optInTimePeriod3 < 1) || ((int)optInTimePeriod3 > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + + /* Ensure that the time periods are ordered from shortest to longest. + * Sort. */ + periods[0] = optInTimePeriod1; + periods[1] = optInTimePeriod2; + periods[2] = optInTimePeriod3; + usedFlag[0] = 0; + usedFlag[1] = 0; + usedFlag[2] = 0; + for ( i = 0; i < 3; ++i ) + { + longestPeriod = 0; + longestIndex = 0; + for ( j = 0; j < 3; ++j ) + { + if ( (usedFlag[j] == 0) && (periods[j] > longestPeriod) ) + { + longestPeriod = periods[j]; + longestIndex = j; + } + } + usedFlag[longestIndex] = 1; + sortedPeriods[i] = longestPeriod; + } + optInTimePeriod1 = sortedPeriods[2]; + optInTimePeriod2 = sortedPeriods[1]; + optInTimePeriod3 = sortedPeriods[0]; + + /* Adjust startIdx for lookback period. */ + lookbackTotal = LOOKBACK_CALL(ULTOSC)( optInTimePeriod1, optInTimePeriod2, optInTimePeriod3 ); + if( startIdx < lookbackTotal ) startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + + /* Prime running totals used in moving averages */ + #define CALC_TERMS(day) \ + { \ + tempLT = inLow[day]; \ + tempHT = inHigh[day]; \ + tempCY = inClose[day-1]; \ + trueLow = min( tempLT, tempCY ); \ + closeMinusTrueLow = inClose[day] - trueLow; \ + trueRange = tempHT - tempLT; \ + tempDouble = std_fabs( tempCY - tempHT ); \ + if( tempDouble > trueRange ) \ + trueRange = tempDouble; \ + tempDouble = std_fabs( tempCY - tempLT ); \ + if( tempDouble > trueRange ) \ + trueRange = tempDouble; \ + } + + #define PRIME_TOTALS(aTotal, bTotal, period) \ + { \ + aTotal = 0; \ + bTotal = 0; \ + for ( i = startIdx-period+1; i < startIdx; ++i ) \ + { \ + CALC_TERMS(i); \ + aTotal += closeMinusTrueLow; \ + bTotal += trueRange; \ + } \ + } + + PRIME_TOTALS(a1Total, b1Total, optInTimePeriod1); + PRIME_TOTALS(a2Total, b2Total, optInTimePeriod2); + PRIME_TOTALS(a3Total, b3Total, optInTimePeriod3); + + #undef PRIME_TOTALS + + /* Calculate oscillator */ + today = startIdx; + outIdx = 0; + trailingIdx1 = today - optInTimePeriod1 + 1; + trailingIdx2 = today - optInTimePeriod2 + 1; + trailingIdx3 = today - optInTimePeriod3 + 1; + while( today <= endIdx ) + { + /* Add on today's terms */ + CALC_TERMS(today); + a1Total += closeMinusTrueLow; + a2Total += closeMinusTrueLow; + a3Total += closeMinusTrueLow; + b1Total += trueRange; + b2Total += trueRange; + b3Total += trueRange; + + /* Calculate the oscillator value for today */ + output = 0.0; + + if( !TA_IS_ZERO(b1Total) ) output += 4.0*(a1Total/b1Total); + if( !TA_IS_ZERO(b2Total) ) output += 2.0*(a2Total/b2Total); + if( !TA_IS_ZERO(b3Total) ) output += a3Total/b3Total; + + /* Remove the trailing terms to prepare for next day */ + CALC_TERMS(trailingIdx1); + a1Total -= closeMinusTrueLow; + b1Total -= trueRange; + + CALC_TERMS(trailingIdx2); + a2Total -= closeMinusTrueLow; + b2Total -= trueRange; + + CALC_TERMS(trailingIdx3); + a3Total -= closeMinusTrueLow; + b3Total -= trueRange; + + /* Last operation is to write the output. Must + * be done after the trailing index have all been + * taken care of because the caller is allowed + * to have the input array to be also the output + * array. + */ + outReal[outIdx] = 100.0 * (output / 7.0); + + /* Increment indexes */ + outIdx++; + today++; + trailingIdx1++; + trailingIdx2++; + trailingIdx3++; + } + #undef CALC_TERMS + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::UltOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::UltOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode ultOsc( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_ULTOSC( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod1, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod2, /* From 1 to 100000 */ +/* Generated */ int optInTimePeriod3, /* From 1 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double a1Total, a2Total, a3Total; +/* Generated */ double b1Total, b2Total, b3Total; +/* Generated */ double trueLow, trueRange, closeMinusTrueLow; +/* Generated */ double tempDouble, output, tempHT, tempLT, tempCY; +/* Generated */ int lookbackTotal; +/* Generated */ int longestPeriod, longestIndex; +/* Generated */ int i,j,today,outIdx; +/* Generated */ int trailingIdx1, trailingIdx2, trailingIdx3; +/* Generated */ ARRAY_INT_LOCAL(usedFlag,3); +/* Generated */ ARRAY_INT_LOCAL(periods,3); +/* Generated */ ARRAY_INT_LOCAL(sortedPeriods,3); +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod1 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod1 = 7; +/* Generated */ else if( ((int)optInTimePeriod1 < 1) || ((int)optInTimePeriod1 > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInTimePeriod2 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod2 = 14; +/* Generated */ else if( ((int)optInTimePeriod2 < 1) || ((int)optInTimePeriod2 > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( (int)optInTimePeriod3 == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod3 = 28; +/* Generated */ else if( ((int)optInTimePeriod3 < 1) || ((int)optInTimePeriod3 > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ periods[0] = optInTimePeriod1; +/* Generated */ periods[1] = optInTimePeriod2; +/* Generated */ periods[2] = optInTimePeriod3; +/* Generated */ usedFlag[0] = 0; +/* Generated */ usedFlag[1] = 0; +/* Generated */ usedFlag[2] = 0; +/* Generated */ for ( i = 0; i < 3; ++i ) +/* Generated */ { +/* Generated */ longestPeriod = 0; +/* Generated */ longestIndex = 0; +/* Generated */ for ( j = 0; j < 3; ++j ) +/* Generated */ { +/* Generated */ if ( (usedFlag[j] == 0) && (periods[j] > longestPeriod) ) +/* Generated */ { +/* Generated */ longestPeriod = periods[j]; +/* Generated */ longestIndex = j; +/* Generated */ } +/* Generated */ } +/* Generated */ usedFlag[longestIndex] = 1; +/* Generated */ sortedPeriods[i] = longestPeriod; +/* Generated */ } +/* Generated */ optInTimePeriod1 = sortedPeriods[2]; +/* Generated */ optInTimePeriod2 = sortedPeriods[1]; +/* Generated */ optInTimePeriod3 = sortedPeriods[0]; +/* Generated */ lookbackTotal = LOOKBACK_CALL(ULTOSC)( optInTimePeriod1, optInTimePeriod2, optInTimePeriod3 ); +/* Generated */ if( startIdx < lookbackTotal ) startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ #define CALC_TERMS(day) \ +/* Generated */ { \ +/* Generated */ tempLT = inLow[day]; \ +/* Generated */ tempHT = inHigh[day]; \ +/* Generated */ tempCY = inClose[day-1]; \ +/* Generated */ trueLow = min( tempLT, tempCY ); \ +/* Generated */ closeMinusTrueLow = inClose[day] - trueLow; \ +/* Generated */ trueRange = tempHT - tempLT; \ +/* Generated */ tempDouble = std_fabs( tempCY - tempHT ); \ +/* Generated */ if( tempDouble > trueRange ) \ +/* Generated */ trueRange = tempDouble; \ +/* Generated */ tempDouble = std_fabs( tempCY - tempLT ); \ +/* Generated */ if( tempDouble > trueRange ) \ +/* Generated */ trueRange = tempDouble; \ +/* Generated */ } +/* Generated */ #define PRIME_TOTALS(aTotal, bTotal, period) \ +/* Generated */ { \ +/* Generated */ aTotal = 0; \ +/* Generated */ bTotal = 0; \ +/* Generated */ for ( i = startIdx-period+1; i < startIdx; ++i ) \ +/* Generated */ { \ +/* Generated */ CALC_TERMS(i); \ +/* Generated */ aTotal += closeMinusTrueLow; \ +/* Generated */ bTotal += trueRange; \ +/* Generated */ } \ +/* Generated */ } +/* Generated */ PRIME_TOTALS(a1Total, b1Total, optInTimePeriod1); +/* Generated */ PRIME_TOTALS(a2Total, b2Total, optInTimePeriod2); +/* Generated */ PRIME_TOTALS(a3Total, b3Total, optInTimePeriod3); +/* Generated */ #undef PRIME_TOTALS +/* Generated */ today = startIdx; +/* Generated */ outIdx = 0; +/* Generated */ trailingIdx1 = today - optInTimePeriod1 + 1; +/* Generated */ trailingIdx2 = today - optInTimePeriod2 + 1; +/* Generated */ trailingIdx3 = today - optInTimePeriod3 + 1; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ CALC_TERMS(today); +/* Generated */ a1Total += closeMinusTrueLow; +/* Generated */ a2Total += closeMinusTrueLow; +/* Generated */ a3Total += closeMinusTrueLow; +/* Generated */ b1Total += trueRange; +/* Generated */ b2Total += trueRange; +/* Generated */ b3Total += trueRange; +/* Generated */ output = 0.0; +/* Generated */ if( !TA_IS_ZERO(b1Total) ) output += 4.0*(a1Total/b1Total); +/* Generated */ if( !TA_IS_ZERO(b2Total) ) output += 2.0*(a2Total/b2Total); +/* Generated */ if( !TA_IS_ZERO(b3Total) ) output += a3Total/b3Total; +/* Generated */ CALC_TERMS(trailingIdx1); +/* Generated */ a1Total -= closeMinusTrueLow; +/* Generated */ b1Total -= trueRange; +/* Generated */ CALC_TERMS(trailingIdx2); +/* Generated */ a2Total -= closeMinusTrueLow; +/* Generated */ b2Total -= trueRange; +/* Generated */ CALC_TERMS(trailingIdx3); +/* Generated */ a3Total -= closeMinusTrueLow; +/* Generated */ b3Total -= trueRange; +/* Generated */ outReal[outIdx] = 100.0 * (output / 7.0); +/* Generated */ outIdx++; +/* Generated */ today++; +/* Generated */ trailingIdx1++; +/* Generated */ trailingIdx2++; +/* Generated */ trailingIdx3++; +/* Generated */ } +/* Generated */ #undef CALC_TERMS +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_VAR.c b/talib/ta_func/ta_VAR.c new file mode 100644 index 0000000..59a48b6 --- /dev/null +++ b/talib/ta_func/ta_VAR.c @@ -0,0 +1,496 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * JV Jesus Viver <324122@cienz.unizar.es> + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 100502 JV Speed optimization of the algorithm + * 052603 MF Adapt code to compile with .NET Managed C++ + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::VarianceLookback( int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev ) /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int varianceLookback( int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev ) /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_VAR_Lookback( int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev ) /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ if( optInNbDev == TA_REAL_DEFAULT ) +/* Generated */ optInNbDev = 1.000000e+0; +/* Generated */ else if( (optInNbDev < -3.000000e+37) ||/* Generated */ (optInNbDev > 3.000000e+37) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + UNUSED_VARIABLE(optInNbDev); + + return optInTimePeriod-1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_VAR - Variance + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 1 to 100000) + * Number of period + * + * optInNbDev:(From TA_REAL_MIN to TA_REAL_MAX) + * Nb of deviations + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Variance( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Variance( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode variance( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_VAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ if( optInNbDev == TA_REAL_DEFAULT ) +/* Generated */ optInNbDev = 1.000000e+0; +/* Generated */ else if( (optInNbDev < -3.000000e+37) ||/* Generated */ (optInNbDev > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + return FUNCTION_CALL(INT_VAR)( startIdx, endIdx, inReal, + optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + outBegIdx, outNBElement, outReal ); +} + + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) + // No INT function +#else + +#if defined( _MANAGED ) && defined( USE_SUBARRAY ) +enum class Core::RetCode Core::TA_INT_VAR( int startIdx, + int endIdx, + SubArray^ inReal, + int optInTimePeriod, + [Out]int% outBegIdx, + [Out]int% outNBElement, + SubArray^ outReal ) +#elif defined( _MANAGED ) +enum class Core::RetCode Core::TA_INT_VAR( int startIdx, + int endIdx, + cli::array^ inReal, + int optInTimePeriod, + [Out]int% outBegIdx, + [Out]int% outNBElement, + cli::array^ outReal ) +#elif defined( _JAVA ) +public RetCode TA_INT_VAR( int startIdx, + int endIdx, + INPUT_TYPE inReal[], + int optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + MInteger outBegIdx, + MInteger outNBElement, + double outReal[] ) +#else +TA_RetCode TA_PREFIX(INT_VAR)( int startIdx, + int endIdx, + const INPUT_TYPE *inReal, + int optInTimePeriod, /* From 1 to TA_INTEGER_MAX */ + int *outBegIdx, + int *outNBElement, + double *outReal ) +#endif +{ + double tempReal, periodTotal1, periodTotal2, meanValue1, meanValue2; + int i, outIdx, trailingIdx, nbInitialElementNeeded; + + /* Validate the calculation method type and + * identify the minimum number of price bar needed + * to calculate at least one output. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Do the MA calculation using tight loops. */ + /* Add-up the initial periods, except for the last value. */ + periodTotal1 = 0; + periodTotal2 = 0; + trailingIdx = startIdx-nbInitialElementNeeded; + + i=trailingIdx; + if( optInTimePeriod > 1 ) + { + while( i < startIdx ) { + tempReal = inReal[i++]; + periodTotal1 += tempReal; + tempReal *= tempReal; + periodTotal2 += tempReal; + } + } + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the inReal and + * outReal to be the same buffer. + */ + outIdx = 0; + do + { + tempReal = inReal[i++]; + + /* Square and add all the deviation over + * the same periods. + */ + + periodTotal1 += tempReal; + tempReal *= tempReal; + periodTotal2 += tempReal; + + /* Square and add all the deviation over + * the same period. + */ + + meanValue1 = periodTotal1 / optInTimePeriod; + meanValue2 = periodTotal2 / optInTimePeriod; + + tempReal = inReal[trailingIdx++]; + periodTotal1 -= tempReal; + tempReal *= tempReal; + periodTotal2 -= tempReal; + + outReal[outIdx++] = meanValue2-meanValue1*meanValue1; + } while( i <= endIdx ); + + /* All done. Indicate the output limits and return. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} +#endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Variance( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Variance( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode variance( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_VAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 1 to 100000 */ +/* Generated */ double optInNbDev, /* From TA_REAL_MIN to TA_REAL_MAX */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 5; +/* Generated */ else if( ((int)optInTimePeriod < 1) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ if( optInNbDev == TA_REAL_DEFAULT ) +/* Generated */ optInNbDev = 1.000000e+0; +/* Generated */ else if( (optInNbDev < -3.000000e+37) || (optInNbDev > 3.000000e+37) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ return FUNCTION_CALL(INT_VAR)( startIdx, endIdx, inReal, +/* Generated */ optInTimePeriod, +/* Generated */ outBegIdx, outNBElement, outReal ); +/* Generated */ } +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined(USE_SINGLE_PRECISION_INPUT) +/* Generated */ // No INT function +/* Generated */ #else +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::TA_INT_VAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::TA_INT_VAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode TA_INT_VAR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ INPUT_TYPE inReal[], +/* Generated */ int optInTimePeriod, +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_PREFIX(INT_VAR)( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const INPUT_TYPE *inReal, +/* Generated */ int optInTimePeriod, +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double *outReal ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double tempReal, periodTotal1, periodTotal2, meanValue1, meanValue2; +/* Generated */ int i, outIdx, trailingIdx, nbInitialElementNeeded; +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ periodTotal1 = 0; +/* Generated */ periodTotal2 = 0; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ i=trailingIdx; +/* Generated */ if( optInTimePeriod > 1 ) +/* Generated */ { +/* Generated */ while( i < startIdx ) { +/* Generated */ tempReal = inReal[i++]; +/* Generated */ periodTotal1 += tempReal; +/* Generated */ tempReal *= tempReal; +/* Generated */ periodTotal2 += tempReal; +/* Generated */ } +/* Generated */ } +/* Generated */ outIdx = 0; +/* Generated */ do +/* Generated */ { +/* Generated */ tempReal = inReal[i++]; +/* Generated */ periodTotal1 += tempReal; +/* Generated */ tempReal *= tempReal; +/* Generated */ periodTotal2 += tempReal; +/* Generated */ meanValue1 = periodTotal1 / optInTimePeriod; +/* Generated */ meanValue2 = periodTotal2 / optInTimePeriod; +/* Generated */ tempReal = inReal[trailingIdx++]; +/* Generated */ periodTotal1 -= tempReal; +/* Generated */ tempReal *= tempReal; +/* Generated */ periodTotal2 -= tempReal; +/* Generated */ outReal[outIdx++] = meanValue2-meanValue1*meanValue1; +/* Generated */ } while( i <= endIdx ); +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ #endif // Not defined( _MANAGED ) && defined( USE_SUBARRAY ) && defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_WCLPRICE.c b/talib/ta_func/ta_WCLPRICE.c new file mode 100644 index 0000000..ab198cf --- /dev/null +++ b/talib/ta_func/ta_WCLPRICE.c @@ -0,0 +1,280 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * 112605 MF Fix outBegIdx when startIdx != 0 + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::WclPriceLookback( void ) +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int wclPriceLookback( ) +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_WCLPRICE_Lookback( void ) +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ /* No parameters to validate. */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + /* This function have no lookback needed. */ + return 0; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_WCLPRICE - Weighted Close Price + * + * Input = High, Low, Close + * Output = double + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::WclPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::WclPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode wclPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_WCLPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int outIdx, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Weighted Close Price = (High + Low + (Close*2) ) / 4 */ + + outIdx = 0; + + for( i= startIdx; i <= endIdx; i++ ) + { + outReal[outIdx++] = ( inHigh [i] + + inLow [i] + + (inClose[i]*2.0) ) / 4.0; + } + + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::WclPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::WclPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode wclPrice( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_WCLPRICE( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int outIdx, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ outIdx = 0; +/* Generated */ for( i= startIdx; i <= endIdx; i++ ) +/* Generated */ { +/* Generated */ outReal[outIdx++] = ( inHigh [i] + +/* Generated */ inLow [i] + +/* Generated */ (inClose[i]*2.0) ) / 4.0; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_WILLR.c b/talib/ta_func/ta_WILLR.c new file mode 100644 index 0000000..917e3e0 --- /dev/null +++ b/talib/ta_func/ta_WILLR.c @@ -0,0 +1,464 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 010802 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::WillRLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int willRLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_WILLR_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + + return (optInTimePeriod-1); +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_WILLR - Williams' %R + * + * Input = High, Low, Close + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::WillR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::WillR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode willR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inHigh[], +/* Generated */ double inLow[], +/* Generated */ double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_WILLR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inHigh[], +/* Generated */ const double inLow[], +/* Generated */ const double inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + double lowest, highest, tmp, diff; + int outIdx, nbInitialElementNeeded; + int trailingIdx, lowestIdx, highestIdx; + int today, i; + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ /* Verify required price component. */ +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + + /* Identify the minimum number of price bar needed + * to identify at least one output over the specified + * period. + */ + nbInitialElementNeeded = (optInTimePeriod-1); + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < nbInitialElementNeeded ) + startIdx = nbInitialElementNeeded; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Initialize 'diff', just to avoid warning. */ + diff = 0.0; + + /* Proceed with the calculation for the requested range. + * Note that this algorithm allows the input and + * output to be the same buffer. + */ + outIdx = 0; + today = startIdx; + trailingIdx = startIdx-nbInitialElementNeeded; + lowestIdx = highestIdx = -1; + diff = highest = lowest = 0.0; + + while( today <= endIdx ) + { + /* Set the lowest low */ + tmp = inLow[today]; + if( lowestIdx < trailingIdx ) + { + lowestIdx = trailingIdx; + lowest = inLow[lowestIdx]; + i = lowestIdx; + while( ++i<=today ) + { + tmp = inLow[i]; + if( tmp < lowest ) + { + lowestIdx = i; + lowest = tmp; + } + } + diff = (highest - lowest)/(-100.0); + } + else if( tmp <= lowest ) + { + lowestIdx = today; + lowest = tmp; + diff = (highest - lowest)/(-100.0); + } + + /* Set the highest high */ + tmp = inHigh[today]; + if( highestIdx < trailingIdx ) + { + highestIdx = trailingIdx; + highest = inHigh[highestIdx]; + i = highestIdx; + while( ++i<=today ) + { + tmp = inHigh[i]; + if( tmp > highest ) + { + highestIdx = i; + highest = tmp; + } + } + diff = (highest - lowest)/(-100.0); + } + else if( tmp >= highest ) + { + highestIdx = today; + highest = tmp; + diff = (highest - lowest)/(-100.0); + } + + if( diff != 0.0 ) + outReal[outIdx++] = (highest-inClose[today])/diff; + else + outReal[outIdx++] = 0.0; + + trailingIdx++; + today++; + } + + /* Keep the outBegIdx relative to the + * caller input before returning. + */ + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::WillR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inHigh, +/* Generated */ SubArray^ inLow, +/* Generated */ SubArray^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::WillR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inHigh, +/* Generated */ cli::array^ inLow, +/* Generated */ cli::array^ inClose, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode willR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inHigh[], +/* Generated */ float inLow[], +/* Generated */ float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_WILLR( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inHigh[], +/* Generated */ const float inLow[], +/* Generated */ const float inClose[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ double lowest, highest, tmp, diff; +/* Generated */ int outIdx, nbInitialElementNeeded; +/* Generated */ int trailingIdx, lowestIdx, highestIdx; +/* Generated */ int today, i; +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if(!inHigh||!inLow||!inClose) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 14; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ nbInitialElementNeeded = (optInTimePeriod-1); +/* Generated */ if( startIdx < nbInitialElementNeeded ) +/* Generated */ startIdx = nbInitialElementNeeded; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ diff = 0.0; +/* Generated */ outIdx = 0; +/* Generated */ today = startIdx; +/* Generated */ trailingIdx = startIdx-nbInitialElementNeeded; +/* Generated */ lowestIdx = highestIdx = -1; +/* Generated */ diff = highest = lowest = 0.0; +/* Generated */ while( today <= endIdx ) +/* Generated */ { +/* Generated */ tmp = inLow[today]; +/* Generated */ if( lowestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ lowestIdx = trailingIdx; +/* Generated */ lowest = inLow[lowestIdx]; +/* Generated */ i = lowestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inLow[i]; +/* Generated */ if( tmp < lowest ) +/* Generated */ { +/* Generated */ lowestIdx = i; +/* Generated */ lowest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ diff = (highest - lowest)/(-100.0); +/* Generated */ } +/* Generated */ else if( tmp <= lowest ) +/* Generated */ { +/* Generated */ lowestIdx = today; +/* Generated */ lowest = tmp; +/* Generated */ diff = (highest - lowest)/(-100.0); +/* Generated */ } +/* Generated */ tmp = inHigh[today]; +/* Generated */ if( highestIdx < trailingIdx ) +/* Generated */ { +/* Generated */ highestIdx = trailingIdx; +/* Generated */ highest = inHigh[highestIdx]; +/* Generated */ i = highestIdx; +/* Generated */ while( ++i<=today ) +/* Generated */ { +/* Generated */ tmp = inHigh[i]; +/* Generated */ if( tmp > highest ) +/* Generated */ { +/* Generated */ highestIdx = i; +/* Generated */ highest = tmp; +/* Generated */ } +/* Generated */ } +/* Generated */ diff = (highest - lowest)/(-100.0); +/* Generated */ } +/* Generated */ else if( tmp >= highest ) +/* Generated */ { +/* Generated */ highestIdx = today; +/* Generated */ highest = tmp; +/* Generated */ diff = (highest - lowest)/(-100.0); +/* Generated */ } +/* Generated */ if( diff != 0.0 ) +/* Generated */ outReal[outIdx++] = (highest-inClose[today])/diff; +/* Generated */ else +/* Generated */ outReal[outIdx++] = 0.0; +/* Generated */ trailingIdx++; +/* Generated */ today++; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_WMA.c b/talib/ta_func/ta_WMA.c new file mode 100644 index 0000000..fecdc6d --- /dev/null +++ b/talib/ta_func/ta_WMA.c @@ -0,0 +1,434 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 112400 MF Template creation. + * 052603 MF Adapt code to compile with .NET Managed C++ + * + */ + +/**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +/* All code within this section is automatically + * generated by gen_code. Any modification will be lost + * next time gen_code is run. + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ #include "TA-Lib-Core.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode::InternalError) +/* Generated */ namespace TicTacTec { namespace TA { namespace Library { +/* Generated */ #elif defined( _JAVA ) +/* Generated */ #include "ta_defs.h" +/* Generated */ #include "ta_java_defs.h" +/* Generated */ #define TA_INTERNAL_ERROR(Id) (RetCode.InternalError) +/* Generated */ #else +/* Generated */ #include +/* Generated */ #include +/* Generated */ #include "ta_func.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_UTILITY_H +/* Generated */ #include "ta_utility.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #ifndef TA_MEMORY_H +/* Generated */ #include "ta_memory.h" +/* Generated */ #endif +/* Generated */ +/* Generated */ #define TA_PREFIX(x) TA_##x +/* Generated */ #define INPUT_TYPE double +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ int Core::WmaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public int wmaLookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #else +/* Generated */ TA_LIB_API int TA_WMA_Lookback( int optInTimePeriod ) /* From 2 to 100000 */ +/* Generated */ +/* Generated */ #endif +/**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ +{ + /* insert local variable here */ + +/**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return -1; +/* Generated */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ + + /* insert lookback code here. */ + return optInTimePeriod - 1; +} + +/**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +/* + * TA_WMA - Weighted Moving Average + * + * Input = double + * Output = double + * + * Optional Parameters + * ------------------- + * optInTimePeriod:(From 2 to 100000) + * Number of period + * + * + */ +/* Generated */ +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Wma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Wma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode wma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_LIB_API TA_RetCode TA_WMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const double inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ +{ + /* Insert local variables here. */ + int inIdx, outIdx, i, trailingIdx, divider; + double periodSum, periodSub, tempReal, trailingValue; + int lookbackTotal; + + #if defined( USE_SINGLE_PRECISION_INPUT ) + ARRAY_MEMMOVEMIX_VAR; + #endif + +/**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ +/* Generated */ /* Validate the requested output range. */ +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif /* !defined(_JAVA)*/ +/* Generated */ /* min/max are checked for optInTimePeriod. */ +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ +/* Generated */ #endif /* !defined(_JAVA) */ +/* Generated */ #endif /* TA_FUNC_NO_RANGE_CHECK */ +/* Generated */ +/**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ + + /* Insert TA function code here. */ + lookbackTotal = optInTimePeriod-1; + + /* Move up the start index if there is not + * enough initial data. + */ + if( startIdx < lookbackTotal ) + startIdx = lookbackTotal; + + /* Make sure there is still something to evaluate. */ + if( startIdx > endIdx ) + { + VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); + VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* To make the rest more efficient, handle exception + * case where the user is asking for a period of '1'. + * In that case outputs equals inputs for the requested + * range. + */ + if( optInTimePeriod == 1 ) + { + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + VALUE_HANDLE_DEREF(outNBElement) = endIdx-startIdx+1; + + #if defined( USE_SINGLE_PRECISION_INPUT ) + ARRAY_MEMMOVEMIX( outReal, 0, inReal, startIdx, (int)VALUE_HANDLE_DEREF(outNBElement) ); + #else + ARRAY_MEMMOVE ( outReal, 0, inReal, startIdx, (int)VALUE_HANDLE_DEREF(outNBElement) ); + #endif + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); + } + + /* Calculate the divider (always an integer value). + * By induction: 1+2+3+4+'n' = n(n+1)/2 + * '>>1' is usually faster than '/2' for unsigned. + */ + divider = (optInTimePeriod*(optInTimePeriod+1))>>1; + + /* The algo used here use a very basic property of + * multiplication/addition: (x*2) = x+x + * + * As an example, a 3 period weighted can be + * interpreted in two way: + * (x1*1)+(x2*2)+(x3*3) + * OR + * x1+x2+x2+x3+x3+x3 (this is the periodSum) + * + * When you move forward in the time serie + * you can quickly adjust the periodSum for the + * period by substracting: + * x1+x2+x3 (This is the periodSub) + * Making the new periodSum equals to: + * x2+x3+x3 + * + * You can then add the new price bar + * which is x4+x4+x4 giving: + * x2+x3+x3+x4+x4+x4 + * + * At this point one iteration is completed and you can + * see that we are back to the step 1 of this example. + * + * Why making it so un-intuitive? The number of memory + * access and floating point operations are kept to a + * minimum with this algo. + */ + outIdx = 0; + trailingIdx = startIdx - lookbackTotal; + + /* Evaluate the initial periodSum/periodSub and trailingValue. */ + periodSum = periodSub = (double)0.0; + inIdx=trailingIdx; + i = 1; + while( inIdx < startIdx ) + { + tempReal = inReal[inIdx++]; + periodSub += tempReal; + periodSum += tempReal*i; + i++; + } + trailingValue = 0.0; + + /* Tight loop for the requested range. */ + while( inIdx <= endIdx ) + { + /* Add the current price bar to the sum + * who are carried through the iterations. + */ + tempReal = inReal[inIdx++]; + periodSub += tempReal; + periodSub -= trailingValue; + periodSum += tempReal*optInTimePeriod; + + /* Save the trailing value for being substract at + * the next iteration. + * (must be saved here just in case outReal and + * inReal are the same buffer). + */ + trailingValue = inReal[trailingIdx++]; + + /* Calculate the WMA for this price bar. */ + outReal[outIdx++] = periodSum / divider; + + /* Prepare the periodSum for the next iteration. */ + periodSum -= periodSub; + } + + /* Set output limits. */ + VALUE_HANDLE_DEREF(outNBElement) = outIdx; + VALUE_HANDLE_DEREF(outBegIdx) = startIdx; + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +/**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ +/* Generated */ +/* Generated */ #define USE_SINGLE_PRECISION_INPUT +/* Generated */ #undef TA_LIB_PRO +/* Generated */ #if !defined( _MANAGED ) && !defined( _JAVA ) +/* Generated */ #undef TA_PREFIX +/* Generated */ #define TA_PREFIX(x) TA_S_##x +/* Generated */ #endif +/* Generated */ #undef INPUT_TYPE +/* Generated */ #define INPUT_TYPE float +/* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY ) +/* Generated */ enum class Core::RetCode Core::Wma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ SubArray^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ SubArray^ outReal ) +/* Generated */ #elif defined( _MANAGED ) +/* Generated */ enum class Core::RetCode Core::Wma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ cli::array^ inReal, +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ [Out]int% outBegIdx, +/* Generated */ [Out]int% outNBElement, +/* Generated */ cli::array^ outReal ) +/* Generated */ #elif defined( _JAVA ) +/* Generated */ public RetCode wma( int startIdx, +/* Generated */ int endIdx, +/* Generated */ float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ MInteger outBegIdx, +/* Generated */ MInteger outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #else +/* Generated */ TA_RetCode TA_S_WMA( int startIdx, +/* Generated */ int endIdx, +/* Generated */ const float inReal[], +/* Generated */ int optInTimePeriod, /* From 2 to 100000 */ +/* Generated */ int *outBegIdx, +/* Generated */ int *outNBElement, +/* Generated */ double outReal[] ) +/* Generated */ #endif +/* Generated */ { +/* Generated */ int inIdx, outIdx, i, trailingIdx, divider; +/* Generated */ double periodSum, periodSub, tempReal, trailingValue; +/* Generated */ int lookbackTotal; +/* Generated */ #if defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ ARRAY_MEMMOVEMIX_VAR; +/* Generated */ #endif +/* Generated */ #ifndef TA_FUNC_NO_RANGE_CHECK +/* Generated */ if( startIdx < 0 ) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_START_INDEX,OutOfRangeStartIndex); +/* Generated */ if( (endIdx < 0) || (endIdx < startIdx)) +/* Generated */ return ENUM_VALUE(RetCode,TA_OUT_OF_RANGE_END_INDEX,OutOfRangeEndIndex); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !inReal ) return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ if( (int)optInTimePeriod == TA_INTEGER_DEFAULT ) +/* Generated */ optInTimePeriod = 30; +/* Generated */ else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #if !defined(_JAVA) +/* Generated */ if( !outReal ) +/* Generated */ return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); +/* Generated */ #endif +/* Generated */ #endif +/* Generated */ lookbackTotal = optInTimePeriod-1; +/* Generated */ if( startIdx < lookbackTotal ) +/* Generated */ startIdx = lookbackTotal; +/* Generated */ if( startIdx > endIdx ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); +/* Generated */ VALUE_HANDLE_DEREF_TO_ZERO(outNBElement); +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ if( optInTimePeriod == 1 ) +/* Generated */ { +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = endIdx-startIdx+1; +/* Generated */ #if defined( USE_SINGLE_PRECISION_INPUT ) +/* Generated */ ARRAY_MEMMOVEMIX( outReal, 0, inReal, startIdx, (int)VALUE_HANDLE_DEREF(outNBElement) ); +/* Generated */ #else +/* Generated */ ARRAY_MEMMOVE ( outReal, 0, inReal, startIdx, (int)VALUE_HANDLE_DEREF(outNBElement) ); +/* Generated */ #endif +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ divider = (optInTimePeriod*(optInTimePeriod+1))>>1; +/* Generated */ outIdx = 0; +/* Generated */ trailingIdx = startIdx - lookbackTotal; +/* Generated */ periodSum = periodSub = (double)0.0; +/* Generated */ inIdx=trailingIdx; +/* Generated */ i = 1; +/* Generated */ while( inIdx < startIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[inIdx++]; +/* Generated */ periodSub += tempReal; +/* Generated */ periodSum += tempReal*i; +/* Generated */ i++; +/* Generated */ } +/* Generated */ trailingValue = 0.0; +/* Generated */ while( inIdx <= endIdx ) +/* Generated */ { +/* Generated */ tempReal = inReal[inIdx++]; +/* Generated */ periodSub += tempReal; +/* Generated */ periodSub -= trailingValue; +/* Generated */ periodSum += tempReal*optInTimePeriod; +/* Generated */ trailingValue = inReal[trailingIdx++]; +/* Generated */ outReal[outIdx++] = periodSum / divider; +/* Generated */ periodSum -= periodSub; +/* Generated */ } +/* Generated */ VALUE_HANDLE_DEREF(outNBElement) = outIdx; +/* Generated */ VALUE_HANDLE_DEREF(outBegIdx) = startIdx; +/* Generated */ return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +/* Generated */ } +/* Generated */ +/* Generated */ #if defined( _MANAGED ) +/* Generated */ }}} // Close namespace TicTacTec.TA.Lib +/* Generated */ #endif +/**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ + diff --git a/talib/ta_func/ta_utility.c b/talib/ta_func/ta_utility.c new file mode 100644 index 0000000..8186560 --- /dev/null +++ b/talib/ta_func/ta_utility.c @@ -0,0 +1,134 @@ +/* TA-LIB Copyright (c) 1999-2008, Mario Fortier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * - Neither name of author nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* List of contributors: + * + * Initial Name/description + * ------------------------------------------------------------------- + * MF Mario Fortier + * RM Robert Meier (talib@meierlim.com http://www.meierlim.com) + * + * Change history: + * + * MMDDYY BY Description + * ------------------------------------------------------------------- + * 052603 MF Adapt code to compile with .NET Managed C++ + * 123004 RM,MF Adapt code to work with Visual Studio 2005 + * + */ + +#if defined( _MANAGED ) + #using + #include "TA-Lib-Core.h" + #include "ta_memory.h" +namespace TicTacTec { namespace TA { namespace Library { +#else + #include "ta_utility.h" + #include "ta_func.h" + #include "ta_memory.h" +#endif + +#if defined( _MANAGED ) + enum class Core::RetCode Core::SetUnstablePeriod( enum class FuncUnstId id, + unsigned int unstablePeriod ) +#else +TA_RetCode TA_SetUnstablePeriod( TA_FuncUnstId id, + unsigned int unstablePeriod ) +#endif +{ + int i; + + if( id > ENUM_VALUE(FuncUnstId,TA_FUNC_UNST_ALL,FuncUnstAll) ) + return ENUM_VALUE(RetCode,TA_BAD_PARAM,BadParam); + + if( id == ENUM_VALUE(FuncUnstId,TA_FUNC_UNST_ALL,FuncUnstAll) ) + { + for( i=0; i < (int)ENUM_VALUE(FuncUnstId,TA_FUNC_UNST_ALL,FuncUnstAll); i++ ) + { + #if defined( _MANAGED ) + Globals->unstablePeriod[(int)i] = unstablePeriod; + #else + TA_Globals->unstablePeriod[i] = unstablePeriod; + #endif + } + } + else + { + #if defined( _MANAGED ) + Globals->unstablePeriod[(int)id] = unstablePeriod; + #else + TA_Globals->unstablePeriod[id] = unstablePeriod; + #endif + } + + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +#if defined( _MANAGED ) +unsigned int Core::GetUnstablePeriod( enum class FuncUnstId id ) +#else +unsigned int TA_GetUnstablePeriod( TA_FuncUnstId id ) +#endif +{ + if( id >= ENUM_VALUE(FuncUnstId,TA_FUNC_UNST_ALL,FuncUnstAll) ) + return 0; + + #if defined( _MANAGED ) + return Globals->unstablePeriod[(int)id]; + #else + return TA_Globals->unstablePeriod[id]; + #endif +} + +#if defined( _MANAGED ) + enum class Core::RetCode Core::SetCompatibility( enum class Compatibility value ) +#else +TA_RetCode TA_SetCompatibility( TA_Compatibility value ) +#endif +{ + TA_GLOBALS_COMPATIBILITY = value; + return ENUM_VALUE(RetCode,TA_SUCCESS,Success); +} + +#if defined( _MANAGED ) + enum class Core::Compatibility Core::GetCompatibility( void ) +#else +TA_Compatibility TA_GetCompatibility( void ) +#endif +{ + return TA_GLOBALS_COMPATIBILITY; +} + +#if defined( _MANAGED ) +}}} // Close namespace TicTacTec::TA::Lib +#endif diff --git a/talib/ta_func/ta_utility.h b/talib/ta_func/ta_utility.h new file mode 100644 index 0000000..726f3bd --- /dev/null +++ b/talib/ta_func/ta_utility.h @@ -0,0 +1,369 @@ +/* Provides common mathematical or analysis functions. + * + * These functions are all PRIVATE to ta-lib and should + * never be called directly by the user of the TA-LIB. + */ + +#ifndef TA_UTILITY_H +#define TA_UTILITY_H + +#if !defined( _MANAGED ) && !defined( _JAVA ) + #ifndef TA_FUNC_H + #include "ta_func.h" + #endif + + #ifndef TA_GLOBAL_H + #include "ta_global.h" + #endif +#endif + +#if defined( _MANAGED ) + #ifndef NULL + #define NULL 0 + #endif +#endif + +/* Calculate a Simple Moving Average. + * This is an internal version, parameter are assumed validated. + * (startIdx and endIdx cannot be -1). + */ +#if !defined( _MANAGED ) && !defined( _JAVA ) +TA_RetCode TA_INT_SMA( int startIdx, + int endIdx, + const double *inReal, + int optInTimePeriod, + int *outBegIdx, + int *outNBElement, + double *outReal ); + +TA_RetCode TA_S_INT_SMA( int startIdx, + int endIdx, + const float *inReal, + int optInTimePeriod, + int *outBegIdx, + int *outNBElement, + double *outReal ); +#endif + +/* Calculate an Exponential Moving Average. + * This is an internal version, parameter are assumed validated. + * (startIdx and endIdx cannot be -1). + */ +#if !defined( _MANAGED ) && !defined( _JAVA ) +TA_RetCode TA_INT_EMA( int startIdx, + int endIdx, + const double *inReal, + int optInTimePeriod, + double optInK_1, + int *outBegIdx, + int *outNBElement, + double *outReal ); + +TA_RetCode TA_S_INT_EMA( int startIdx, + int endIdx, + const float *inReal, + int optInTimePeriod, + double optInK_1, + int *outBegIdx, + int *outNBElement, + double *outReal ); +#endif + +/* Calculate a MACD + * This is an internal version, parameter are assumed validated. + * (startIdx and endIdx cannot be -1). + */ +#if !defined( _MANAGED ) && !defined( _JAVA ) +TA_RetCode TA_INT_MACD( int startIdx, + int endIdx, + const double inReal[], + int optInFastPeriod, /* 0 is fix 12 */ + int optInSlowPeriod, /* 0 is fix 26 */ + int optInSignalPeriod_2, + int *outBegIdx, + int *outNBElement, + double outRealMACD_0[], + double outRealMACDSignal_1[], + double outRealMACDHist_2[] ); + +TA_RetCode TA_S_INT_MACD( int startIdx, + int endIdx, + const float inReal[], + int optInFastPeriod, /* 0 is fix 12 */ + int optInSlowPeriod, /* 0 is fix 26 */ + int optInSignalPeriod_2, + int *outBegIdx, + int *outNBElement, + double outRealMACD_0[], + double outRealMACDSignal_1[], + double outRealMACDHist_2[] ); +#endif + +/* Internal Price Oscillator function. + * + * A buffer must be provided for intermediate processing + * 'tempBuffer' must be of at least (endIdx-startIdx+1) + */ +#if !defined( _MANAGED ) && !defined( _JAVA ) +TA_RetCode TA_INT_PO( int startIdx, + int endIdx, + const double *inReal, + int optInFastPeriod, + int optInSlowPeriod, + TA_MAType optInMethod_2, + int *outBegIdx, + int *outNBElement, + double *outReal, + double *tempBuffer, + int doPercentageOutput ); + +TA_RetCode TA_S_INT_PO( int startIdx, + int endIdx, + const float *inReal, + int optInFastPeriod, + int optInSlowPeriod, + TA_MAType optInMethod_2, + int *outBegIdx, + int *outNBElement, + double *outReal, + double *tempBuffer, + int doPercentageOutput ); +#endif + +/* Internal variance function. */ +#if !defined( _MANAGED ) && !defined( _JAVA ) +TA_RetCode TA_INT_VAR( int startIdx, + int endIdx, + const double *inReal, + int optInTimePeriod, + int *outBegIdx, + int *outNBElement, + double *outReal ); + +TA_RetCode TA_S_INT_VAR( int startIdx, + int endIdx, + const float *inReal, + int optInTimePeriod, + int *outBegIdx, + int *outNBElement, + double *outReal ); +#endif + +/* A function to calculate a standard deviation. + * + * This function allows speed optimization when the + * moving average series is already calculated. + */ +#if !defined( _MANAGED ) && !defined( _JAVA ) +void TA_INT_stddev_using_precalc_ma( const double *inReal, + const double *inMovAvg, + int inMovAvgBegIdx, + int inMovAvgNbElement, + int timePeriod, + double *output ); + +void TA_S_INT_stddev_using_precalc_ma( const float *inReal, + const double *inMovAvg, + int inMovAvgBegIdx, + int inMovAvgNbElement, + int timePeriod, + double *output ); +#endif + + /* Provides an equivalent to standard "math.h" functions. */ +#if defined( _MANAGED ) + #define std_floor Math::Floor + #define std_ceil Math::Ceiling + #define std_fabs Math::Abs + #define std_atan Math::Atan + #define std_cos Math::Cos + #define std_sin Math::Sin + #define std_sqrt Math::Sqrt + #define std_tanh Math::Tanh + #define std_tan Math::Tan + #define std_sinh Math::Sinh + #define std_log10 Math::Log10 + #define std_log Math::Log + #define std_exp Math::Exp + #define std_cosh Math::Cosh + #define std_asin Math::Asin + #define std_acos Math::Acos +#elif defined( _JAVA ) + #define std_floor Math.floor + #define std_ceil Math.ceil + #define std_fabs Math.abs + #define std_atan Math.atan + #define std_cos Math.cos + #define std_sin Math.sin + #define std_sqrt Math.sqrt + #define std_tanh Math.tanh + #define std_tan Math.tan + #define std_sinh Math.sinh + #define std_log10 Math.log10 + #define std_log Math.log + #define std_exp Math.exp + #define std_cosh Math.cosh + #define std_asin Math.asin + #define std_acos Math.acos +#else + #define std_floor floor + #define std_ceil ceil + #define std_fabs fabs + #define std_atan atan + #define std_cos cos + #define std_sin sin + #define std_sqrt sqrt + #define std_tanh tanh + #define std_tan tan + #define std_sinh sinh + #define std_log10 log10 + #define std_log log + #define std_exp exp + #define std_cosh cosh + #define std_asin asin + #define std_acos acos +#endif + +/* Rounding macro for doubles. Works only with positive numbers. */ +#define round_pos(x) (std_floor((x)+0.5)) + +/* Rounding macro for doubles. Works only with negative numbers. */ +#define round_neg(x) (std_ceil((x)-0.5)) + +/* Rounding with a precision of 2 digit after the dot */ +#define round_pos_2(x) ((std_floor((x*100.0)+0.5))/100.0) +#define round_neg_2(x) ((std_ceil((x*100.0)-0.5))/100.0) + +/* In the context of TA-Lib, floating point are often + * compared within an acceptable error range. + * + * As an example,a TA oscillator ranging from 0 to 100 can + * fairly be considered equal if their difference is less + * than 0.000001. + * + * Ranging around zero also allows to work around limit + * cases where floating point minimal step (EPSILON) causes + * unexpected cummulative effect (ending with "negative zero" + * being one example). + * + * FLT_EPSILON == 1.192092896e-07 for float type on intel with msvc. + * DBL_EPSILON == 2.2204460492503131e-016 for the double type. + * + * Warning: These macro are not intended as "general purpose" floating + * point comparison. TA_REAL_EQ is not even transitive. The "ep" parameter + * must be carefully choosen to work in the domain of the tested values. + * Do a search on Google for a more generalize algo. + */ +#define TA_EPSILON (0.00000000000001) +#define TA_REAL_EQ(x,v,ep) (((v-ep) (b)) ? (a) : (b)) +#endif + +/* Candlestick macros (used by candlestick functions, where the parameters are always called inClose, inOpen, etc. + * Don't use i++ or func(i) with these macros ! + */ + +#define TA_REALBODY(IDX) ( std_fabs( inClose[IDX] - inOpen[IDX] ) ) +#define TA_UPPERSHADOW(IDX) ( inHigh[IDX] - ( inClose[IDX] >= inOpen[IDX] ? inClose[IDX] : inOpen[IDX] ) ) +#define TA_LOWERSHADOW(IDX) ( ( inClose[IDX] >= inOpen[IDX] ? inOpen[IDX] : inClose[IDX] ) - inLow[IDX] ) +#define TA_HIGHLOWRANGE(IDX) ( inHigh[IDX] - inLow[IDX] ) +#define TA_CANDLECOLOR(IDX) ( inClose[IDX] >= inOpen[IDX] ? 1 : -1 ) +#ifdef TA_LIB_PRO +/* Section for code distributed with TA-Lib Pro only. */ +#endif + +#if defined( _MANAGED ) + #define TA_CANDLERANGETYPE(SET) (Globals->candleSettings[(int)CandleSettingType::SET]->rangeType) + #define TA_CANDLEAVGPERIOD(SET) (Globals->candleSettings[(int)CandleSettingType::SET]->avgPeriod) + #define TA_CANDLEFACTOR(SET) (Globals->candleSettings[(int)CandleSettingType::SET]->factor) +#elif defined( _JAVA ) + #define TA_CANDLERANGETYPE(SET) (this.candleSettings[CandleSettingType.SET.ordinal()].rangeType) + #define TA_CANDLEAVGPERIOD(SET) (this.candleSettings[CandleSettingType.SET.ordinal()].avgPeriod) + #define TA_CANDLEFACTOR(SET) (this.candleSettings[CandleSettingType.SET.ordinal()].factor) +#else + #define TA_CANDLERANGETYPE(SET) (TA_Globals->candleSettings[TA_##SET].rangeType) + #define TA_CANDLEAVGPERIOD(SET) (TA_Globals->candleSettings[TA_##SET].avgPeriod) + #define TA_CANDLEFACTOR(SET) (TA_Globals->candleSettings[TA_##SET].factor) +#endif + +#define TA_CANDLERANGE(SET,IDX) \ + ( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_RealBody,RealBody) ? TA_REALBODY(IDX) : \ + ( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_HighLow,HighLow) ? TA_HIGHLOWRANGE(IDX) : \ + ( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_Shadows,Shadows) ? TA_UPPERSHADOW(IDX) + TA_LOWERSHADOW(IDX) : \ + 0 ) ) ) +#define TA_CANDLEAVERAGE(SET,SUM,IDX) \ + ( TA_CANDLEFACTOR(SET) \ + * ( TA_CANDLEAVGPERIOD(SET) != 0.0? SUM / TA_CANDLEAVGPERIOD(SET) : TA_CANDLERANGE(SET,IDX) ) \ + / ( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_Shadows,Shadows) ? 2.0 : 1.0 ) \ + ) +#define TA_REALBODYGAPUP(IDX2,IDX1) ( min(inOpen[IDX2],inClose[IDX2]) > max(inOpen[IDX1],inClose[IDX1]) ) +#define TA_REALBODYGAPDOWN(IDX2,IDX1) ( max(inOpen[IDX2],inClose[IDX2]) < min(inOpen[IDX1],inClose[IDX1]) ) +#define TA_CANDLEGAPUP(IDX2,IDX1) ( inLow[IDX2] > inHigh[IDX1] ) +#define TA_CANDLEGAPDOWN(IDX2,IDX1) ( inHigh[IDX2] < inLow[IDX1] ) + +#ifdef TA_LIB_PRO +/* Section for code distributed with TA-Lib Pro only. */ +#endif + +#endif