├── .svnignore ├── CREDITS ├── .gitignore ├── ta-lib ├── src │ ├── tools │ │ ├── Makefile.am │ │ ├── gen_code │ │ │ ├── mcpp.exe │ │ │ └── Makefile.am │ │ └── ta_regtest │ │ │ ├── ReadMe.txt │ │ │ ├── Makefile.am │ │ │ └── ta_test_func.h │ ├── Makefile.am │ ├── ta_abstract │ │ ├── templates │ │ │ ├── Makefile.am.template │ │ │ ├── excel_glue.c.template │ │ │ ├── ta_java_defs.h.template │ │ │ ├── ta_func.swg.template │ │ │ ├── ta_frame.h.template │ │ │ ├── ta_func_api.c.template │ │ │ ├── ta_func.h.template │ │ │ ├── ta_frame.c.template │ │ │ ├── ta_group_idx.c.template │ │ │ ├── CoreAnnotated.java.template │ │ │ └── ta_x.c.template │ │ ├── Makefile.am │ │ └── tables │ │ │ ├── table_g.c │ │ │ ├── table_i.c │ │ │ ├── table_j.c │ │ │ ├── table_q.c │ │ │ ├── table_x.c │ │ │ ├── table_y.c │ │ │ ├── table_z.c │ │ │ └── table_f.c │ └── ta_common │ │ ├── Makefile.am │ │ ├── ta_retcode.csv │ │ ├── ta_magic_nb.h │ │ └── ta_version.c ├── Makefile.am ├── include │ ├── Makefile.am │ └── ta_libc.h ├── autogen.sh ├── ta-lib.dpkg.in ├── ta-lib-config.in ├── ta-lib.spec.in ├── CHANGELOG.TXT └── configure.in ├── tests ├── inc │ └── func.php ├── trader_ad_02.phpt ├── trader_ini_02.phpt ├── trader_ht_sine_01.phpt ├── trader_ht_phasor_01.phpt ├── trader_t3_bug62698.phpt ├── trader_t3_01.phpt ├── trader_add_01.phpt ├── trader_ad_01.phpt └── trader_ini_01.phpt ├── LICENSE └── functions ├── trader_php_func.h.tpl ├── trader_php_arginfo.h.tpl ├── trader_php_fe.h.tpl ├── function.tpl ├── trader_ceil.c ├── trader_ln.c ├── trader_exp.c ├── trader_floor.c ├── trader_log10.c ├── trader_cos.c ├── trader_sin.c ├── trader_sqrt.c ├── trader_tan.c ├── trader_acos.c ├── trader_asin.c ├── trader_atan.c ├── trader_cosh.c ├── trader_sinh.c ├── trader_tanh.c ├── trader_ht_dcphase.c ├── trader_ht_dcperiod.c ├── trader_ht_trendline.c ├── trader_ht_trendmode.c ├── trader_ht_sine.c ├── trader_mom.c ├── trader_sum.c ├── trader_sma.c ├── trader_tsf.c ├── trader_cmo.c ├── trader_ema.c ├── trader_medprice.c ├── trader_rsi.c ├── trader_wma.c ├── trader_ht_phasor.c ├── trader_kama.c ├── trader_min.c ├── trader_trima.c ├── trader_add.c ├── trader_dema.c ├── trader_div.c ├── trader_max.c ├── trader_obv.c ├── trader_tema.c ├── trader_midpoint.c └── trader_roc.c /.svnignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | ta -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | *.lo 3 | *.la 4 | -------------------------------------------------------------------------------- /ta-lib/src/tools/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 1.4 2 | SUBDIRS = gen_code ta_regtest 3 | -------------------------------------------------------------------------------- /ta-lib/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 1.4 2 | SUBDIRS = src src/tools 3 | bin_SCRIPTS = ta-lib-config 4 | -------------------------------------------------------------------------------- /ta-lib/src/tools/gen_code/mcpp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-math-trader/master/ta-lib/src/tools/gen_code/mcpp.exe -------------------------------------------------------------------------------- /tests/inc/func.php: -------------------------------------------------------------------------------- 1 | &2 8 | exit 1 9 | fi 10 | 11 | while test $# -gt 0; do 12 | case $1 in 13 | --version) 14 | echo @VERSION@ 15 | ;; 16 | --cflags) 17 | echo -I@includedir@/ta-lib @DEFS@ 18 | ;; 19 | --libs) 20 | echo -L@libdir@ @LIBS@ 21 | ;; 22 | *) 23 | echo "${usage}" 1>&2 24 | exit 1 25 | ;; 26 | esac 27 | shift 28 | done 29 | -------------------------------------------------------------------------------- /ta-lib/ta-lib.spec.in: -------------------------------------------------------------------------------- 1 | Summary: Technical Analysis Library 2 | Name: ta-lib 3 | Version: @VERSION@ 4 | Release: 1 5 | License: BSD 6 | Group: Development/Libraries 7 | 8 | %description 9 | TA-Lib provides common functions for the technical analysis of stock/future/commodity market data. 10 | 11 | %build 12 | ./autogen.sh 13 | CFLAGS="-g0 -O2 -pipe" ./configure --prefix=/usr 14 | make 15 | 16 | %install 17 | rm -rf $RPM_BUILD_ROOT 18 | make DESTDIR=$RPM_BUILD_ROOT install 19 | 20 | %post -p /sbin/ldconfig 21 | %postun -p /sbin/ldconfig 22 | 23 | %files 24 | %defattr(-,root,root) 25 | /usr 26 | -------------------------------------------------------------------------------- /tests/trader_ht_sine_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | trader_ht_sine() basic test 3 | --SKIPIF-- 4 | 19 | --EXPECT-- 20 | array(2) { 21 | [0]=> 22 | array(2) { 23 | [63]=> 24 | float(0.456) 25 | [64]=> 26 | float(0.833) 27 | } 28 | [1]=> 29 | array(2) { 30 | [63]=> 31 | float(0.952) 32 | [64]=> 33 | float(0.98) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ta-lib/src/ta_common/ta_retcode.csv: -------------------------------------------------------------------------------- 1 | 0,TA_SUCCESS,No error 2 | 1,TA_LIB_NOT_INITIALIZE,TA_Initialize was not sucessfully called 3 | 2,TA_BAD_PARAM,A parameter is out of range 4 | 3,TA_ALLOC_ERR,Possibly out-of-memory 5 | 4,TA_GROUP_NOT_FOUND,No Info 6 | 5,TA_FUNC_NOT_FOUND,No Info 7 | 6,TA_INVALID_HANDLE,No Info 8 | 7,TA_INVALID_PARAM_HOLDER,No Info 9 | 8,TA_INVALID_PARAM_HOLDER_TYPE,No Info 10 | 9,TA_INVALID_PARAM_FUNCTION,No Info 11 | 10,TA_INPUT_NOT_ALL_INITIALIZE,No Info 12 | 11,TA_OUTPUT_NOT_ALL_INITIALIZE,No Info 13 | 12,TA_OUT_OF_RANGE_START_INDEX,No Info 14 | 13,TA_OUT_OF_RANGE_END_INDEX,No Info 15 | 14,TA_INVALID_LIST_TYPE,No Info 16 | 15,TA_BAD_OBJECT,No Info 17 | 16,TA_NOT_SUPPORTED,No Info 18 | 5000,TA_INTERNAL_ERROR,No Info 19 | -------------------------------------------------------------------------------- /tests/trader_ht_phasor_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | trader_ht_phasor() basic test 3 | --SKIPIF-- 4 | 19 | --EXPECT-- 20 | array(2) { 21 | [0]=> 22 | array(3) { 23 | [32]=> 24 | float(2.805) 25 | [33]=> 26 | float(3.219) 27 | [34]=> 28 | float(1.613) 29 | } 30 | [1]=> 31 | array(3) { 32 | [32]=> 33 | float(4.668) 34 | [33]=> 35 | float(-0.935) 36 | [34]=> 37 | float(-3.103) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/trader_t3_bug62698.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | trader_t3() to high time period 3 | --SKIPIF-- 4 | 17 | float(60.819) 18 | [7]=> 19 | float(60.188) 20 | [8]=> 21 | float(59.681) 22 | [9]=> 23 | float(59.418) 24 | [10]=> 25 | float(59.161) 26 | [11]=> 27 | float(58.943) 28 | [12]=> 29 | float(58.748) 30 | [13]=> 31 | float(58.551) 32 | [14]=> 33 | float(58.44) 34 | [15]=> 35 | float(58.835) 36 | [16]=> 37 | float(59.162) 38 | [17]=> 39 | float(60.115) 40 | [18]=> 41 | float(60.991) 42 | [19]=> 43 | float(61.713) 44 | [20]=> 45 | float(62.092) 46 | [21]=> 47 | float(62.663) 48 | [22]=> 49 | float(63.17) 50 | [23]=> 51 | float(64.182) 52 | [24]=> 53 | float(65.102) 54 | [25]=> 55 | float(65.746) 56 | [26]=> 57 | float(65.75) 58 | [27]=> 59 | float(65.031) 60 | [28]=> 61 | float(64.269) 62 | [29]=> 63 | float(63.605) 64 | } -------------------------------------------------------------------------------- /ta-lib/src/tools/ta_regtest/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | # ta_regrest is used for testing and should 3 | # not be installed. 4 | noinst_PROGRAMS = ta_regtest 5 | 6 | ta_regtest_SOURCES = ta_regtest.c \ 7 | test_data.c \ 8 | test_util.c \ 9 | test_abstract.c \ 10 | ta_test_func/test_adx.c \ 11 | ta_test_func/test_mom.c \ 12 | ta_test_func/test_sar.c \ 13 | ta_test_func/test_rsi.c \ 14 | ta_test_func/test_candlestick.c \ 15 | ta_test_func/test_per_ema.c \ 16 | ta_test_func/test_per_hlc.c \ 17 | ta_test_func/test_stoch.c \ 18 | ta_test_func/test_macd.c \ 19 | ta_test_func/test_minmax.c \ 20 | ta_test_func/test_per_hlcv.c \ 21 | ta_test_func/test_1in_1out.c \ 22 | ta_test_func/test_1in_2out.c \ 23 | ta_test_func/test_per_ohlc.c \ 24 | ta_test_func/test_stddev.c \ 25 | ta_test_func/test_bbands.c \ 26 | ta_test_func/test_ma.c \ 27 | ta_test_func/test_po.c \ 28 | ta_test_func/test_per_hl.c \ 29 | ta_test_func/test_trange.c \ 30 | test_internals.c 31 | 32 | ta_regtest_CPPFLAGS = -I../../ta_func \ 33 | -I../../ta_common/trio \ 34 | -I../../ta_common/mt \ 35 | -I../../ta_common \ 36 | -I../../ta_abstract 37 | ta_regtest_LDFLAGS = -L../.. -lta_lib \ 38 | -lm 39 | -------------------------------------------------------------------------------- /ta-lib/src/tools/ta_regtest/ta_test_func.h: -------------------------------------------------------------------------------- 1 | #ifndef TA_TEST_FUNC_H 2 | #define TA_TEST_FUNC_H 3 | 4 | ErrorNumber test_candlestick ( TA_History *history ); 5 | ErrorNumber test_func_adx ( TA_History *history ); 6 | ErrorNumber test_func_ma ( TA_History *history ); 7 | ErrorNumber test_func_trange ( TA_History *history ); 8 | ErrorNumber test_func_rsi ( TA_History *history ); 9 | ErrorNumber test_func_po ( TA_History *history ); 10 | ErrorNumber test_func_macd ( TA_History *history ); 11 | ErrorNumber test_func_stddev ( TA_History *history ); 12 | ErrorNumber test_func_bbands ( TA_History *history ); 13 | ErrorNumber test_func_mom_roc ( TA_History *history ); 14 | ErrorNumber test_func_stoch ( TA_History *history ); 15 | ErrorNumber test_func_minmax ( TA_History *history ); 16 | ErrorNumber test_func_per_ema ( TA_History *history ); 17 | ErrorNumber test_func_per_hl ( TA_History *history ); 18 | ErrorNumber test_func_per_hlc ( TA_History *history ); 19 | ErrorNumber test_func_per_hlcv( TA_History *history ); 20 | ErrorNumber test_func_per_ohlc( TA_History *history ); 21 | ErrorNumber test_func_per ( TA_History *history ); 22 | ErrorNumber test_func_sar ( TA_History *history ); 23 | ErrorNumber test_func_1in_1out( TA_History *history ); 24 | ErrorNumber test_func_1in_2out( TA_History *history ); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tests/trader_add_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | trader_add() basic test 3 | --SKIPIF-- 4 | 17 | float(123.71) 18 | [1]=> 19 | float(122.74) 20 | [2]=> 21 | float(122.38) 22 | [3]=> 23 | float(119.4) 24 | [4]=> 25 | float(118.64) 26 | [5]=> 27 | float(121.61) 28 | [6]=> 29 | float(117.97) 30 | [7]=> 31 | float(117.02) 32 | [8]=> 33 | float(116.55) 34 | [9]=> 35 | float(117.52) 36 | [10]=> 37 | float(116.58) 38 | [11]=> 39 | float(116.51) 40 | [12]=> 41 | float(116.38) 42 | [13]=> 43 | float(116.08) 44 | [14]=> 45 | float(115.88) 46 | [15]=> 47 | float(118.44) 48 | [16]=> 49 | float(117.83) 50 | [17]=> 51 | float(120.63) 52 | [18]=> 53 | float(121.96) 54 | [19]=> 55 | float(123.6) 56 | [20]=> 57 | float(122.53) 58 | [21]=> 59 | float(125.99) 60 | [22]=> 61 | float(126.85) 62 | [23]=> 63 | float(129.73) 64 | [24]=> 65 | float(130.41) 66 | [25]=> 67 | float(131.68) 68 | [26]=> 69 | float(128.44) 70 | [27]=> 71 | float(125.28) 72 | [28]=> 73 | float(124.29) 74 | [29]=> 75 | float(123.95) 76 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013, Anatoliy Belsky 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_LTLIBRARIES = libta_abstract.la libta_abstract_gc.la 3 | 4 | libta_abstract_la_SOURCES = ta_group_idx.c \ 5 | ta_def_ui.c \ 6 | ta_abstract.c \ 7 | ta_func_api.c \ 8 | frames/ta_frame.c \ 9 | tables/table_a.c \ 10 | tables/table_b.c \ 11 | tables/table_c.c \ 12 | tables/table_d.c \ 13 | tables/table_e.c \ 14 | tables/table_f.c \ 15 | tables/table_g.c \ 16 | tables/table_h.c \ 17 | tables/table_i.c \ 18 | tables/table_j.c \ 19 | tables/table_k.c \ 20 | tables/table_l.c \ 21 | tables/table_m.c \ 22 | tables/table_n.c \ 23 | tables/table_o.c \ 24 | tables/table_p.c \ 25 | tables/table_q.c \ 26 | tables/table_r.c \ 27 | tables/table_s.c \ 28 | tables/table_t.c \ 29 | tables/table_u.c \ 30 | tables/table_v.c \ 31 | tables/table_w.c \ 32 | tables/table_x.c \ 33 | tables/table_y.c \ 34 | tables/table_z.c 35 | 36 | libta_abstract_gc_la_SOURCES = $(libta_abstract_la_SOURCES) 37 | 38 | libta_abstract_la_LDFLAGS = -version-info $(TALIB_LIBRARY_VERSION) 39 | libta_abstract_gc_la_LDFLAGS = $(libta_abstract_la_LDFLAGS) 40 | 41 | libta_abstract_la_CPPFLAGS = -I../ta_common/ -Iframes/ 42 | 43 | # The 'gc' version is a minimal version used to just to compile gen_code 44 | libta_abstract_gc_la_CPPFLAGS = -DTA_GEN_CODE $(libta_abstract_la_CPPFLAGS) 45 | 46 | libta_abstractdir=$(includedir)/ta-lib/ 47 | libta_abstract_HEADERS = ../../include/ta_defs.h \ 48 | ../../include/ta_libc.h \ 49 | ../../include/ta_abstract.h 50 | -------------------------------------------------------------------------------- /ta-lib/src/ta_common/ta_magic_nb.h: -------------------------------------------------------------------------------- 1 | #ifndef TA_MAGIC_NB_H 2 | #define TA_MAGIC_NB_H 3 | 4 | /* Many allocated structures contains a magic number. 5 | * 6 | * These numbers are used solely to make sure that when a pointer is 7 | * provided, it is really pointing on the expected type of data. 8 | * It helps also for the detection of memory corruption. 9 | * This mechanism is simple, but add a non-negligeable level of 10 | * reliability at a very low cost (speed/memory wise). 11 | */ 12 | #define TA_FUNC_DEF_MAGIC_NB 0xA201B201 13 | #define TA_PARAM_HOLDER_PRIV_MAGIC_NB 0xA202B202 14 | #define TA_LIBC_PRIV_MAGIC_NB 0xA203B203 15 | #define TA_UDBASE_MAGIC_NB 0xA204B204 16 | #define TA_CATEGORY_TABLE_MAGIC_NB 0xA205B205 17 | #define TA_SYMBOL_TABLE_MAGIC_NB 0xA206B206 18 | #define TA_WEBPAGE_MAGIC_NB 0xA207B207 19 | #define TA_STREAM_MAGIC_NB 0xA208B208 20 | #define TA_STREAM_ACCESS_MAGIC_NB 0xA209B209 21 | #define TA_YAHOO_IDX_MAGIC_NB 0xA20AB20A 22 | #define TA_STRING_TABLE_GROUP_MAGIC_NB 0xA20BB20B 23 | #define TA_STRING_TABLE_FUNC_MAGIC_NB 0xA20CB20C 24 | #define TA_MARKET_PAGE_MAGIC_NB 0xA20DB20D 25 | #define TA_TRADELOGPRIV_MAGIC_NB 0xA20EB20E 26 | #define TA_PMPRIV_MAGIC_NB 0xA20FB20F 27 | #define TA_PMREPORT_MAGIC_NB 0xA210B210 28 | #define TA_TRADEREPORT_MAGIC_NB 0xA211B211 29 | #define TA_HISTORY_MAGIC_NB 0xA212B212 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /tests/trader_ad_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | trader_ad() basic test 3 | --SKIPIF-- 4 | 17 | float(4774.134) 18 | [1]=> 19 | float(-4854.572) 20 | [2]=> 21 | float(-12033.93) 22 | [3]=> 23 | float(-18263.911) 24 | [4]=> 25 | float(-20983.124) 26 | [5]=> 27 | float(-39952.595) 28 | [6]=> 29 | float(-48761.487) 30 | [7]=> 31 | float(-52761.344) 32 | [8]=> 33 | float(-47293.262) 34 | [9]=> 35 | float(-48537.697) 36 | [10]=> 37 | float(-47198.262) 38 | [11]=> 39 | float(-49555.402) 40 | [12]=> 41 | float(-49847.973) 42 | [13]=> 43 | float(-49309.973) 44 | [14]=> 45 | float(-47345.558) 46 | [15]=> 47 | float(-50863.058) 48 | [16]=> 49 | float(-48770.302) 50 | [17]=> 51 | float(-32430.773) 52 | [18]=> 53 | float(-25121.247) 54 | [19]=> 55 | float(-27136.972) 56 | [20]=> 57 | float(-18021.277) 58 | [21]=> 59 | float(-20165.277) 60 | [22]=> 61 | float(-17971.394) 62 | [23]=> 63 | float(-33071.293) 64 | [24]=> 65 | float(-36977.478) 66 | [25]=> 67 | float(-46736.666) 68 | [26]=> 69 | float(-55496.349) 70 | [27]=> 71 | float(-58778.033) 72 | [28]=> 73 | float(-63909.98) 74 | [29]=> 75 | float(-56552.876) 76 | } -------------------------------------------------------------------------------- /functions/trader_php_func.h.tpl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Anatoliy Belsky 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #ifndef TA_PHP_FUNC_H 32 | #define TA_PHP_FUNC_H 33 | 34 | HEADER_CONTENT 35 | 36 | #endif /* TA_PHP_FUNC_H */ 37 | 38 | -------------------------------------------------------------------------------- /functions/trader_php_arginfo.h.tpl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Anatoliy Belsky 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #ifndef TA_PHP_ARGINFO_H 32 | #define TA_PHP_ARGINFO_H 33 | 34 | HEADER_CONTENT 35 | 36 | #endif /* TA_PHP_ARGINFO_H */ 37 | 38 | -------------------------------------------------------------------------------- /functions/trader_php_fe.h.tpl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Anatoliy Belsky 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #ifndef TA_PHP_FE_H 32 | #define TA_PHP_FE_H 33 | const zend_function_entry ta_functions[] = { 34 | HEADER_CONTENT 35 | PHP_FE_END 36 | }; 37 | 38 | #endif /* TA_PHP_FE_H */ 39 | 40 | -------------------------------------------------------------------------------- /ta-lib/configure.in: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_COPYRIGHT([(c) TicTacTec 2005, 2006]) 6 | AC_INIT([ta-lib], [0.4.0], [http://sourceforge.net/tracker/?group_id=8903&atid=108903]) 7 | AC_CONFIG_SRCDIR([src/ta_func/ta_AD.c]) 8 | AC_CONFIG_HEADER([include/ta_config.h]) 9 | AM_INIT_AUTOMAKE([ta-lib], [0.4.0]) 10 | 11 | # Checks for programs. 12 | AC_PROG_CC 13 | AC_PROG_LIBTOOL 14 | 15 | # Checks for libraries. 16 | AC_CHECK_LIB([dl], [dlopen]) 17 | AC_CHECK_LIB([pthread], [pthread_create]) 18 | 19 | # Checks for header files. 20 | AC_HEADER_STDC 21 | AC_CHECK_HEADERS([float.h inttypes.h limits.h locale.h stddef.h stdint.h stdlib.h string.h unistd.h wchar.h wctype.h]) 22 | 23 | # Checks for typedefs, structures, and compiler characteristics. 24 | AC_C_CONST 25 | AC_TYPE_SIZE_T 26 | AC_STRUCT_TM 27 | AC_C_VOLATILE 28 | AC_CHECK_TYPES([ptrdiff_t]) 29 | 30 | # Checks for library functions. 31 | AC_TYPE_SIGNAL 32 | AC_FUNC_STRCOLL 33 | AC_FUNC_STRFTIME 34 | AC_FUNC_STRTOD 35 | AC_FUNC_VPRINTF 36 | AC_CHECK_FUNCS([floor isascii localeconv mblen memmove memset modf pow sqrt strcasecmp strchr strerror strncasecmp strrchr strstr strtol strtoul]) 37 | 38 | # Versioning: 39 | # Only change this if library is no longer 40 | # ABI compatible with previous version 41 | # (e.g. function declaration changed) 42 | TALIB_LIBRARY_VERSION=0:0:0 43 | 44 | AC_SUBST(TALIB_LIBRARY_VERSION) 45 | 46 | AC_CONFIG_FILES([Makefile src/Makefile src/ta_abstract/Makefile src/ta_common/Makefile src/ta_func/Makefile src/tools/Makefile src/tools/gen_code/Makefile src/tools/ta_regtest/Makefile ta-lib-config ta-lib.spec ta-lib.dpkg]) 47 | AC_OUTPUT 48 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/templates/excel_glue.c.template: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* DO NOT MODIFY this file. 35 | * This file is automatically generated by gen_code. 36 | * 37 | * If you are not re-building the excel library (which is most 38 | * likely the case), just ignore this file. 39 | */ 40 | 41 | %%%GENCODE%%% 42 | 43 | /*************** 44 | * End of File * 45 | ***************/ 46 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/templates/ta_java_defs.h.template: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* DO NOT MODIFY this file. 35 | * This file is automatically generated by gen_code. 36 | * 37 | * If you are not re-generating the java code (which is most 38 | * likely the case), just ignore this file. 39 | */ 40 | 41 | %%%GENCODE%%% 42 | 43 | /*************** 44 | * End of File * 45 | ***************/ 46 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/templates/ta_func.swg.template: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* DO NOT MODIFY this file. 35 | * This file is automatically generated by gen_code. 36 | * 37 | * If you are not re-building an interface with SWIG (which is most 38 | * likely the case), just ignore this file. 39 | */ 40 | 41 | %%%GENCODE%%% 42 | 43 | /*************** 44 | * End of File * 45 | ***************/ 46 | -------------------------------------------------------------------------------- /ta-lib/include/ta_libc.h: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | #ifndef TA_LIBC_H 34 | #define TA_LIBC_H 35 | 36 | /* Includes all headers needed for using the ta-lib 'C' library. */ 37 | 38 | #ifndef TA_COMMON_H 39 | #include "ta_common.h" 40 | #endif 41 | 42 | #ifndef TA_FUNC_H 43 | #include "ta_func.h" 44 | #endif 45 | 46 | #ifndef TA_ABSTRACT_H 47 | #include "ta_abstract.h" 48 | #endif 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /tests/trader_ini_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | trader.real_round_mode basic test 3 | --SKIPIF-- 4 | 48 | #include "ta_def_ui.h" 49 | #include "ta_abstract.h" 50 | 51 | %%%GENCODE%%% 52 | 53 | 54 | /***************/ 55 | /* End of File */ 56 | /***************/ 57 | -------------------------------------------------------------------------------- /ta-lib/src/ta_common/ta_version.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | #include 36 | 37 | /* Version number controlled manually. 38 | * 39 | * Should be modified only by TA-Lib.org 40 | */ 41 | #define MAJOR "0" 42 | #define MINOR "4" 43 | #define BUILD "0" 44 | 45 | /* Nothing to modify below this line. */ 46 | 47 | #define TA_VERSION_STRING(maj,min,build,date,time) maj"."min"."build" ("date" "time")" 48 | 49 | const char *TA_GetVersionString( void ) 50 | { 51 | return TA_VERSION_STRING(MAJOR,MINOR,BUILD,__DATE__,__TIME__); 52 | } 53 | 54 | const char *TA_GetVersionMajor( void ) 55 | { 56 | return MAJOR; 57 | } 58 | 59 | const char *TA_GetVersionMinor( void ) 60 | { 61 | return MINOR; 62 | } 63 | 64 | const char *TA_GetVersionBuild( void ) 65 | { 66 | return BUILD; 67 | } 68 | 69 | const char *TA_GetVersionDate( void ) 70 | { 71 | return __DATE__; 72 | } 73 | 74 | const char *TA_GetVersionTime( void ) 75 | { 76 | return __TIME__; 77 | } 78 | -------------------------------------------------------------------------------- /functions/function.tpl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array MY_FUNC_NAME_LOWER(MY_FUNC_DOC_PARAMS) 40 | MY_FUNC_DESC */ 41 | PHP_FUNCTION(MY_FUNC_NAME_LOWER) 42 | { 43 | int optimalOutAlloc, lookback; 44 | MY_IN_PHP_ARRAY_DEFS 45 | MY_FUNC_ARRAY_PARA_DEFS 46 | MY_FUNC_INT_PARA_DEFS 47 | MY_IN_PHP_LONG_DEFS 48 | MY_IN_PHP_DOUBLE_DEFS 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | MY_ZEND_FAST_ZPP 52 | #else 53 | if (zend_parse_parameters(ZEND_NUM_ARGS(), MY_ZEND_PARAMS_STR, MY_ZEND_PARAM_LIST) == FAILURE) { 54 | RETURN_FALSE; 55 | } 56 | #endif 57 | 58 | MY_FUNC_CHECK_MA_TYPES 59 | MY_FUNC_SET_BOUNDABLE 60 | 61 | MY_FUNC_SET_MIN_END_IDX 62 | MY_FUNC_SET_START_IDX 63 | 64 | MY_FUNC_OPTIMAL_OUT_ALLOC 65 | if (optimalOutAlloc > 0) { 66 | MY_FUNC_ARRAY_PARA_ALLOCS 67 | 68 | TRADER_G(last_error) = MY_FUNC_NAME(MY_FUNC_PARAMS); 69 | if (TRADER_G(last_error) != TA_SUCCESS) { 70 | MY_FUNC_ARRAY_PARA_DEALLOCS2 71 | 72 | RETURN_FALSE; 73 | } 74 | 75 | MY_PHP_MAKE_RETURN 76 | 77 | MY_FUNC_ARRAY_PARA_DEALLOCS1 78 | } else { 79 | /* The current input args combination would cause TA-Lib to produce 80 | zero output, don't bother making any allocs or calls. */ 81 | TRADER_G(last_error) = TA_BAD_PARAM; 82 | RETURN_FALSE; 83 | } 84 | } 85 | /* }}} */ 86 | 87 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/templates/CoreAnnotated.java.template: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* DO NOT MODIFY this file. 35 | * This file is automatically generated by gen_code. 36 | * 37 | * If you are not re-generating the java code (which is most 38 | * likely the case), just ignore this file. 39 | */ 40 | 41 | package com.tictactec.ta.lib; 42 | 43 | import com.tictactec.ta.lib.MAType; 44 | import com.tictactec.ta.lib.MInteger; 45 | import com.tictactec.ta.lib.RetCode; 46 | import com.tictactec.ta.lib.Core; 47 | import com.tictactec.ta.lib.meta.annotation.FuncFlags; 48 | import com.tictactec.ta.lib.meta.annotation.FuncInfo; 49 | import com.tictactec.ta.lib.meta.annotation.InputFlags; 50 | import com.tictactec.ta.lib.meta.annotation.InputParameterInfo; 51 | import com.tictactec.ta.lib.meta.annotation.InputParameterType; 52 | import com.tictactec.ta.lib.meta.annotation.IntegerList; 53 | import com.tictactec.ta.lib.meta.annotation.IntegerRange; 54 | import com.tictactec.ta.lib.meta.annotation.OptInputParameterInfo; 55 | import com.tictactec.ta.lib.meta.annotation.OptInputParameterType; 56 | import com.tictactec.ta.lib.meta.annotation.OutputFlags; 57 | import com.tictactec.ta.lib.meta.annotation.OutputParameterInfo; 58 | import com.tictactec.ta.lib.meta.annotation.OutputParameterType; 59 | import com.tictactec.ta.lib.meta.annotation.RealRange; 60 | 61 | public class CoreAnnotated extends Core { 62 | 63 | %%%GENCODE%%% 64 | 65 | } 66 | 67 | /*************** 68 | * End of File * 69 | ***************/ 70 | -------------------------------------------------------------------------------- /functions/trader_ceil.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ceil(array real) 40 | Vector Ceil */ 41 | PHP_FUNCTION(trader_ceil) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_CEIL_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_CEIL(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_ln.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ln(array real) 40 | Vector Log Natural */ 41 | PHP_FUNCTION(trader_ln) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_LN_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_LN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_exp.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_exp(array real) 40 | Vector Arithmetic Exp */ 41 | PHP_FUNCTION(trader_exp) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_EXP_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_EXP(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_floor.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_floor(array real) 40 | Vector Floor */ 41 | PHP_FUNCTION(trader_floor) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_FLOOR_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_FLOOR(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_log10.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_log10(array real) 40 | Vector Log10 */ 41 | PHP_FUNCTION(trader_log10) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_LOG10_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_LOG10(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_cos.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_cos(array real) 40 | Vector Trigonometric Cos */ 41 | PHP_FUNCTION(trader_cos) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_COS_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_COS(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_sin.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_sin(array real) 40 | Vector Trigonometric Sin */ 41 | PHP_FUNCTION(trader_sin) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_SIN_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_SIN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_sqrt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_sqrt(array real) 40 | Vector Square Root */ 41 | PHP_FUNCTION(trader_sqrt) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_SQRT_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_SQRT(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_tan.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_tan(array real) 40 | Vector Trigonometric Tan */ 41 | PHP_FUNCTION(trader_tan) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_TAN_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_TAN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_acos.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_acos(array real) 40 | Vector Trigonometric ACos */ 41 | PHP_FUNCTION(trader_acos) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_ACOS_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_ACOS(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_asin.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_asin(array real) 40 | Vector Trigonometric ASin */ 41 | PHP_FUNCTION(trader_asin) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_ASIN_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_ASIN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_atan.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_atan(array real) 40 | Vector Trigonometric ATan */ 41 | PHP_FUNCTION(trader_atan) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_ATAN_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_ATAN(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_cosh.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_cosh(array real) 40 | Vector Trigonometric Cosh */ 41 | PHP_FUNCTION(trader_cosh) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_COSH_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_COSH(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_sinh.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_sinh(array real) 40 | Vector Trigonometric Sinh */ 41 | PHP_FUNCTION(trader_sinh) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_SINH_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_SINH(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_tanh.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_tanh(array real) 40 | Vector Trigonometric Tanh */ 41 | PHP_FUNCTION(trader_tanh) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_TANH_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_TANH(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_ht_dcphase.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ht_dcphase(array real) 40 | Hilbert Transform - Dominant Cycle Phase */ 41 | PHP_FUNCTION(trader_ht_dcphase) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_HT_DCPHASE_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_HT_DCPHASE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_ht_dcperiod.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ht_dcperiod(array real) 40 | Hilbert Transform - Dominant Cycle Period */ 41 | PHP_FUNCTION(trader_ht_dcperiod) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_HT_DCPERIOD_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_HT_DCPERIOD(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_ht_trendline.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ht_trendline(array real) 40 | Hilbert Transform - Instantaneous Trendline */ 41 | PHP_FUNCTION(trader_ht_trendline) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_HT_TRENDLINE_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_HT_TRENDLINE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outReal); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outReal); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outReal); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /functions/trader_ht_trendmode.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ht_trendmode(array real) 40 | Hilbert Transform - Trend vs Cycle Mode */ 41 | PHP_FUNCTION(trader_ht_trendmode) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0, *outInteger = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_HT_TRENDMODE_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outInteger = emalloc(sizeof(double)*optimalOutAlloc); 71 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 72 | 73 | TRADER_G(last_error) = TA_HT_TRENDMODE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outInteger); 74 | if (TRADER_G(last_error) != TA_SUCCESS) { 75 | efree(inReal); 76 | efree(outInteger); 77 | 78 | RETURN_FALSE; 79 | } 80 | 81 | TRADER_DBL_ARR_TO_ZRET1(outInteger, return_value, endIdx, outBegIdx, outNBElement) 82 | 83 | efree(inReal); 84 | efree(outInteger); 85 | } else { 86 | /* The current input args combination would cause TA-Lib to produce 87 | zero output, don't bother making any allocs or calls. */ 88 | TRADER_G(last_error) = TA_BAD_PARAM; 89 | RETURN_FALSE; 90 | } 91 | } 92 | /* }}} */ 93 | 94 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_g.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'G' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableG[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableGSize = 65 | ((sizeof(TA_DEF_TableG)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_i.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'I' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableI[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableISize = 65 | ((sizeof(TA_DEF_TableI)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_j.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'J' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableJ[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableJSize = 65 | ((sizeof(TA_DEF_TableJ)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_q.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'Q' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableQ[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableQSize = 65 | ((sizeof(TA_DEF_TableQ)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_x.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'X' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableX[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableXSize = 65 | ((sizeof(TA_DEF_TableX)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_y.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'Y' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableY[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableYSize = 65 | ((sizeof(TA_DEF_TableY)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_z.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'Z' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* None */ 52 | 53 | /**************************************************************************** 54 | * Step 2 - Add your TA function to the table. 55 | * Keep in alphabetical order. Must be NULL terminated. 56 | ****************************************************************************/ 57 | const TA_FuncDef *TA_DEF_TableZ[] = 58 | { 59 | NULL 60 | }; 61 | 62 | 63 | /* Do not modify the following line. */ 64 | const unsigned int TA_DEF_TableZSize = 65 | ((sizeof(TA_DEF_TableZ)/sizeof(TA_FuncDef *))-1); 66 | 67 | 68 | /**************************************************************************** 69 | * Step 3 - Make sure "gen_code" is executed for generating all other 70 | * source files derived from this one. 71 | * You can then re-compile the library as usual and you are done! 72 | ****************************************************************************/ 73 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/templates/ta_x.c.template: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /* List of contributors: 35 | * 36 | * Initial Name/description 37 | * ------------------------------------------------------------------- 38 | * MF Mario Fortier (Replace when you are the original author) 39 | * 40 | * Change history: 41 | * 42 | * MMDDYY BY Description 43 | * ------------------------------------------------------------------- 44 | * XXXXXX MF Initial Version 45 | */ 46 | 47 | /**** START GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ 48 | %%%GENCODE%%% 49 | /**** END GENCODE SECTION 1 - DO NOT DELETE THIS LINE ****/ 50 | { 51 | /* insert local variable here */ 52 | 53 | /**** START GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ 54 | %%%GENCODE%%% 55 | /**** END GENCODE SECTION 2 - DO NOT DELETE THIS LINE ****/ 56 | 57 | /* insert lookback code here. */ 58 | 59 | return 0; 60 | } 61 | 62 | /**** START GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ 63 | %%%GENCODE%%% 64 | /**** END GENCODE SECTION 3 - DO NOT DELETE THIS LINE ****/ 65 | { 66 | /* insert local variable here */ 67 | 68 | /**** START GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ 69 | %%%GENCODE%%% 70 | /**** END GENCODE SECTION 4 - DO NOT DELETE THIS LINE ****/ 71 | 72 | /* Insert TA function code here. */ 73 | 74 | /* Default return values */ 75 | VALUE_HANDLE_DEREF_TO_ZERO(outBegIdx); 76 | VALUE_HANDLE_DEREF_TO_ZERO(outNbElement); 77 | 78 | return ENUM_VALUE(RetCode,TA_SUCCESS,Success); 79 | } 80 | 81 | /**** START GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ 82 | %%%GENCODE%%% 83 | /**** END GENCODE SECTION 5 - DO NOT DELETE THIS LINE ****/ 84 | 85 | -------------------------------------------------------------------------------- /functions/trader_ht_sine.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ht_sine(array real) 40 | Hilbert Transform - SineWave */ 41 | PHP_FUNCTION(trader_ht_sine) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outSine, *outLeadSine; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_HT_SINE_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outSine = emalloc(sizeof(double)*optimalOutAlloc); 71 | outLeadSine = emalloc(sizeof(double)*optimalOutAlloc); 72 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 73 | 74 | TRADER_G(last_error) = TA_HT_SINE(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outSine, outLeadSine); 75 | if (TRADER_G(last_error) != TA_SUCCESS) { 76 | efree(inReal); 77 | efree(outSine); 78 | efree(outLeadSine); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET2(outSine, outLeadSine, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outSine); 87 | efree(outLeadSine); 88 | } else { 89 | /* The current input args combination would cause TA-Lib to produce 90 | zero output, don't bother making any allocs or calls. */ 91 | TRADER_G(last_error) = TA_BAD_PARAM; 92 | RETURN_FALSE; 93 | } 94 | } 95 | /* }}} */ 96 | 97 | -------------------------------------------------------------------------------- /functions/trader_mom.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_mom(array real [, int timePeriod]) 40 | Momentum */ 41 | PHP_FUNCTION(trader_mom) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 1; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_MOM_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_MOM(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_sum.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_sum(array real [, int timePeriod]) 40 | Summation */ 41 | PHP_FUNCTION(trader_sum) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_SUM_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_SUM(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_sma.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_sma(array real [, int timePeriod]) 40 | Simple Moving Average */ 41 | PHP_FUNCTION(trader_sma) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_SMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_SMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_tsf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_tsf(array real [, int timePeriod]) 40 | Time Series Forecast */ 41 | PHP_FUNCTION(trader_tsf) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_TSF_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_TSF(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_cmo.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_cmo(array real [, int timePeriod]) 40 | Chande Momentum Oscillator */ 41 | PHP_FUNCTION(trader_cmo) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_CMO_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_CMO(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_ema.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ema(array real [, int timePeriod]) 40 | Exponential Moving Average */ 41 | PHP_FUNCTION(trader_ema) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_EMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_EMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_medprice.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_medprice(array high, array low) 40 | Median Price */ 41 | PHP_FUNCTION(trader_medprice) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinHigh, *zinLow; 45 | double *inHigh, *inLow, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(2, 2) 52 | Z_PARAM_ARRAY(zinHigh) 53 | Z_PARAM_ARRAY(zinLow) 54 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 55 | #else 56 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinHigh, &zinLow) == FAILURE) { 57 | RETURN_FALSE; 58 | } 59 | #endif 60 | 61 | 62 | 63 | 64 | TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinHigh)), 65 | zend_hash_num_elements(Z_ARRVAL_P(zinLow))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_MEDPRICE_Lookback(); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinHigh, inHigh) 74 | TRADER_DBL_ZARR_TO_ARR(zinLow, inLow) 75 | 76 | TRADER_G(last_error) = TA_MEDPRICE(startIdx, endIdx, inHigh, inLow, &outBegIdx, &outNBElement, outReal); 77 | if (TRADER_G(last_error) != TA_SUCCESS) { 78 | efree(inHigh); 79 | efree(inLow); 80 | efree(outReal); 81 | 82 | RETURN_FALSE; 83 | } 84 | 85 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 86 | 87 | efree(inHigh); 88 | efree(inLow); 89 | efree(outReal); 90 | } else { 91 | /* The current input args combination would cause TA-Lib to produce 92 | zero output, don't bother making any allocs or calls. */ 93 | TRADER_G(last_error) = TA_BAD_PARAM; 94 | RETURN_FALSE; 95 | } 96 | } 97 | /* }}} */ 98 | 99 | -------------------------------------------------------------------------------- /functions/trader_rsi.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_rsi(array real [, int timePeriod]) 40 | Relative Strength Index */ 41 | PHP_FUNCTION(trader_rsi) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_RSI_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_RSI(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_wma.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_wma(array real [, int timePeriod]) 40 | Weighted Moving Average */ 41 | PHP_FUNCTION(trader_wma) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_WMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_WMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_ht_phasor.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_ht_phasor(array real) 40 | Hilbert Transform - Phasor Components */ 41 | PHP_FUNCTION(trader_ht_phasor) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outInPhase, *outQuadrature; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 1) 52 | Z_PARAM_ARRAY(zinReal) 53 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 54 | #else 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zinReal) == FAILURE) { 56 | RETURN_FALSE; 57 | } 58 | #endif 59 | 60 | 61 | 62 | 63 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 64 | endIdx--; /* it's <= in the ta-lib */ 65 | 66 | 67 | lookback = TA_HT_PHASOR_Lookback(); 68 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 69 | if (optimalOutAlloc > 0) { 70 | outInPhase = emalloc(sizeof(double)*optimalOutAlloc); 71 | outQuadrature = emalloc(sizeof(double)*optimalOutAlloc); 72 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 73 | 74 | TRADER_G(last_error) = TA_HT_PHASOR(startIdx, endIdx, inReal, &outBegIdx, &outNBElement, outInPhase, outQuadrature); 75 | if (TRADER_G(last_error) != TA_SUCCESS) { 76 | efree(inReal); 77 | efree(outInPhase); 78 | efree(outQuadrature); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET2(outInPhase, outQuadrature, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outInPhase); 87 | efree(outQuadrature); 88 | } else { 89 | /* The current input args combination would cause TA-Lib to produce 90 | zero output, don't bother making any allocs or calls. */ 91 | TRADER_G(last_error) = TA_BAD_PARAM; 92 | RETURN_FALSE; 93 | } 94 | } 95 | /* }}} */ 96 | 97 | -------------------------------------------------------------------------------- /functions/trader_kama.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_kama(array real [, int timePeriod]) 40 | Kaufman Adaptive Moving Average */ 41 | PHP_FUNCTION(trader_kama) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_KAMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_KAMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_min.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_min(array real [, int timePeriod]) 40 | Lowest value over a specified period */ 41 | PHP_FUNCTION(trader_min) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_MIN_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_MIN(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_trima.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_trima(array real [, int timePeriod]) 40 | Triangular Moving Average */ 41 | PHP_FUNCTION(trader_trima) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_TRIMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_TRIMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_add(array real0, array real1) 40 | Vector Arithmetic Add */ 41 | PHP_FUNCTION(trader_add) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal0, *zinReal1; 45 | double *inReal0, *inReal1, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(2, 2) 52 | Z_PARAM_ARRAY(zinReal0) 53 | Z_PARAM_ARRAY(zinReal1) 54 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 55 | #else 56 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal0, &zinReal1) == FAILURE) { 57 | RETURN_FALSE; 58 | } 59 | #endif 60 | 61 | 62 | 63 | 64 | TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), 65 | zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_ADD_Lookback(); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) 74 | TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) 75 | 76 | TRADER_G(last_error) = TA_ADD(startIdx, endIdx, inReal0, inReal1, &outBegIdx, &outNBElement, outReal); 77 | if (TRADER_G(last_error) != TA_SUCCESS) { 78 | efree(inReal0); 79 | efree(inReal1); 80 | efree(outReal); 81 | 82 | RETURN_FALSE; 83 | } 84 | 85 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 86 | 87 | efree(inReal0); 88 | efree(inReal1); 89 | efree(outReal); 90 | } else { 91 | /* The current input args combination would cause TA-Lib to produce 92 | zero output, don't bother making any allocs or calls. */ 93 | TRADER_G(last_error) = TA_BAD_PARAM; 94 | RETURN_FALSE; 95 | } 96 | } 97 | /* }}} */ 98 | 99 | -------------------------------------------------------------------------------- /functions/trader_dema.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_dema(array real [, int timePeriod]) 40 | Double Exponential Moving Average */ 41 | PHP_FUNCTION(trader_dema) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_DEMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_DEMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_div.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_div(array real0, array real1) 40 | Vector Arithmetic Div */ 41 | PHP_FUNCTION(trader_div) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal0, *zinReal1; 45 | double *inReal0, *inReal1, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(2, 2) 52 | Z_PARAM_ARRAY(zinReal0) 53 | Z_PARAM_ARRAY(zinReal1) 54 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 55 | #else 56 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal0, &zinReal1) == FAILURE) { 57 | RETURN_FALSE; 58 | } 59 | #endif 60 | 61 | 62 | 63 | 64 | TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal0)), 65 | zend_hash_num_elements(Z_ARRVAL_P(zinReal1))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_DIV_Lookback(); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal0, inReal0) 74 | TRADER_DBL_ZARR_TO_ARR(zinReal1, inReal1) 75 | 76 | TRADER_G(last_error) = TA_DIV(startIdx, endIdx, inReal0, inReal1, &outBegIdx, &outNBElement, outReal); 77 | if (TRADER_G(last_error) != TA_SUCCESS) { 78 | efree(inReal0); 79 | efree(inReal1); 80 | efree(outReal); 81 | 82 | RETURN_FALSE; 83 | } 84 | 85 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 86 | 87 | efree(inReal0); 88 | efree(inReal1); 89 | efree(outReal); 90 | } else { 91 | /* The current input args combination would cause TA-Lib to produce 92 | zero output, don't bother making any allocs or calls. */ 93 | TRADER_G(last_error) = TA_BAD_PARAM; 94 | RETURN_FALSE; 95 | } 96 | } 97 | /* }}} */ 98 | 99 | -------------------------------------------------------------------------------- /functions/trader_max.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_max(array real [, int timePeriod]) 40 | Highest value over a specified period */ 41 | PHP_FUNCTION(trader_max) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_MAX_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_MAX(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_obv.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_obv(array real, array volume) 40 | On Balance Volume */ 41 | PHP_FUNCTION(trader_obv) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal, *zinVolume; 45 | double *inReal, *inVolume, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(2, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_ARRAY(zinVolume) 54 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 55 | #else 56 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "aa", &zinReal, &zinVolume) == FAILURE) { 57 | RETURN_FALSE; 58 | } 59 | #endif 60 | 61 | 62 | 63 | 64 | TRADER_SET_MIN_INT2(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal)), 65 | zend_hash_num_elements(Z_ARRVAL_P(zinVolume))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_OBV_Lookback(); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | TRADER_DBL_ZARR_TO_ARR(zinVolume, inVolume) 75 | 76 | TRADER_G(last_error) = TA_OBV(startIdx, endIdx, inReal, inVolume, &outBegIdx, &outNBElement, outReal); 77 | if (TRADER_G(last_error) != TA_SUCCESS) { 78 | efree(inReal); 79 | efree(inVolume); 80 | efree(outReal); 81 | 82 | RETURN_FALSE; 83 | } 84 | 85 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 86 | 87 | efree(inReal); 88 | efree(inVolume); 89 | efree(outReal); 90 | } else { 91 | /* The current input args combination would cause TA-Lib to produce 92 | zero output, don't bother making any allocs or calls. */ 93 | TRADER_G(last_error) = TA_BAD_PARAM; 94 | RETURN_FALSE; 95 | } 96 | } 97 | /* }}} */ 98 | 99 | -------------------------------------------------------------------------------- /functions/trader_tema.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_tema(array real [, int timePeriod]) 40 | Triple Exponential Moving Average */ 41 | PHP_FUNCTION(trader_tema) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_TEMA_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_TEMA(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /ta-lib/src/ta_abstract/tables/table_f.c: -------------------------------------------------------------------------------- 1 | /* TA-LIB Copyright (c) 1999-2007, Mario Fortier 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * - Neither name of author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this 18 | * software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | /********************************************************************* 35 | * This file contains only TA functions starting with the letter 'F' * 36 | *********************************************************************/ 37 | #include 38 | #include "ta_abstract.h" 39 | #include "ta_def_ui.h" 40 | 41 | /* Follow the 3 steps defined below for adding a new TA Function to this 42 | * file. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Step 1 - Define here the interface to your TA functions with 47 | * the macro DEF_FUNCTION. 48 | * 49 | ****************************************************************************/ 50 | 51 | /* Floor BEGIN */ 52 | DEF_MATH_UNARY_OPERATOR( FLOOR, "Vector Floor", "Floor" ) 53 | /* Floor END */ 54 | 55 | 56 | /**************************************************************************** 57 | * Step 2 - Add your TA function to the table. 58 | * Keep in alphabetical order. Must be NULL terminated. 59 | ****************************************************************************/ 60 | const TA_FuncDef *TA_DEF_TableF[] = 61 | { 62 | ADD_TO_TABLE(FLOOR), 63 | NULL 64 | }; 65 | 66 | 67 | /* Do not modify the following line. */ 68 | const unsigned int TA_DEF_TableFSize = 69 | ((sizeof(TA_DEF_TableF)/sizeof(TA_FuncDef *))-1); 70 | 71 | 72 | /**************************************************************************** 73 | * Step 3 - Make sure "gen_code" is executed for generating all other 74 | * source files derived from this one. 75 | * You can then re-compile the library as usual and you are done! 76 | ****************************************************************************/ 77 | -------------------------------------------------------------------------------- /functions/trader_midpoint.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_midpoint(array real [, int timePeriod]) 40 | MidPoint over period */ 41 | PHP_FUNCTION(trader_midpoint) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 2; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(2, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_MIDPOINT_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_MIDPOINT(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | -------------------------------------------------------------------------------- /functions/trader_roc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2018, Anatol Belski 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* $Id$ */ 30 | 31 | #include "php.h" 32 | #include "php_trader.h" 33 | 34 | #include 35 | #include 36 | 37 | ZEND_EXTERN_MODULE_GLOBALS(trader) 38 | 39 | /* {{{ proto array trader_roc(array real [, int timePeriod]) 40 | Rate of change : ((price/prevPrice)-1)*100 */ 41 | PHP_FUNCTION(trader_roc) 42 | { 43 | int optimalOutAlloc, lookback; 44 | zval *zinReal; 45 | double *inReal, *outReal; 46 | int startIdx = 0, endIdx = 0, outBegIdx = 0, outNBElement = 0; 47 | zend_long optInTimePeriod = 1; 48 | 49 | 50 | #if PHP_MAJOR_VERSION >= 7 51 | ZEND_PARSE_PARAMETERS_START(1, 2) 52 | Z_PARAM_ARRAY(zinReal) 53 | Z_PARAM_OPTIONAL 54 | Z_PARAM_LONG(optInTimePeriod) 55 | ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); 56 | #else 57 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|l", &zinReal, &optInTimePeriod) == FAILURE) { 58 | RETURN_FALSE; 59 | } 60 | #endif 61 | 62 | 63 | TRADER_LONG_SET_BOUNDABLE(1, 100000, optInTimePeriod); 64 | 65 | TRADER_SET_MIN_INT1(endIdx, zend_hash_num_elements(Z_ARRVAL_P(zinReal))) 66 | endIdx--; /* it's <= in the ta-lib */ 67 | 68 | 69 | lookback = TA_ROC_Lookback((int)optInTimePeriod); 70 | optimalOutAlloc = (lookback > endIdx) ? 0 : (endIdx - lookback + 1); 71 | if (optimalOutAlloc > 0) { 72 | outReal = emalloc(sizeof(double)*optimalOutAlloc); 73 | TRADER_DBL_ZARR_TO_ARR(zinReal, inReal) 74 | 75 | TRADER_G(last_error) = TA_ROC(startIdx, endIdx, inReal, (int)optInTimePeriod, &outBegIdx, &outNBElement, outReal); 76 | if (TRADER_G(last_error) != TA_SUCCESS) { 77 | efree(inReal); 78 | efree(outReal); 79 | 80 | RETURN_FALSE; 81 | } 82 | 83 | TRADER_DBL_ARR_TO_ZRET1(outReal, return_value, endIdx, outBegIdx, outNBElement) 84 | 85 | efree(inReal); 86 | efree(outReal); 87 | } else { 88 | /* The current input args combination would cause TA-Lib to produce 89 | zero output, don't bother making any allocs or calls. */ 90 | TRADER_G(last_error) = TA_BAD_PARAM; 91 | RETURN_FALSE; 92 | } 93 | } 94 | /* }}} */ 95 | 96 | --------------------------------------------------------------------------------