├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── examples ├── atr.rs ├── rsi.rs └── sma.rs ├── src └── lib.rs └── wrapper.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - stable 4 | - beta 5 | - nightly 6 | matrix: 7 | allow_failures: 8 | - rust: nightly 9 | 10 | script: 11 | - wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz 12 | - tar xvzf ta-lib-0.4.0-src.tar.gz 13 | - rm ta-lib-0.4.0-src.tar.gz 14 | - cd ta-lib 15 | - ./configure 16 | - make 17 | - sudo make install 18 | - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ 19 | - cargo test 20 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ta-lib-wrapper" 3 | version = "0.2.0" 4 | authors = ["Carl Levasseur "] 5 | 6 | description = "Rust wrapper for TA-lib" 7 | 8 | repository = "https://github.com/CLevasseur/ta-lib-rust" 9 | 10 | # This points to a file under the package root (relative to this `Cargo.toml`). 11 | # The contents of this file are stored and indexed in the registry. 12 | # crates.io will render this file and place the result on the crate's page. 13 | readme = "README.md" 14 | 15 | # This is a list of up to five keywords that describe this crate. Keywords 16 | # are searchable on crates.io, and you may choose any words that would 17 | # help someone find this crate. 18 | keywords = ["ta-lib", "technical-analysis", "indicator", "trading", "financial-market"] 19 | 20 | # This is a list of up to five categories where this crate would fit. 21 | # Categories are a fixed list available at crates.io/category_slugs, and 22 | # they must match exactly. 23 | categories = ["api-bindings"] 24 | 25 | # If a project is using a nonstandard license, then this key may be specified in 26 | # lieu of the above key and must point to a file relative to this manifest 27 | # (similar to the readme key). 28 | license-file = "LICENSE" 29 | 30 | # Optional specification of badges to be displayed on crates.io. 31 | # 32 | # - The badges pertaining to build status that are currently available are 33 | # Appveyor, CircleCI, GitLab, and TravisCI. 34 | # - Available badges pertaining to code test coverage are Codecov and 35 | # Coveralls. 36 | # - There are also maintenance-related badges basesed on isitmaintained.com 37 | # which state the issue resolution time, percent of open issues, and future 38 | # maintenance intentions. 39 | # 40 | # If a `repository` key is required, this refers to a repository in 41 | # `user/repo` format. 42 | [badges] 43 | 44 | # Travis CI: `repository` in format "/" is required. 45 | # `branch` is optional; default is `master` 46 | travis-ci = { repository = "CLevasseur/ta-lib-rust", branch = "master" } 47 | 48 | # Maintenance: `status` is required Available options are `actively-developed`, 49 | # `passively-maintained`, `as-is`, `none`, `experimental`, `looking-for-maintainer` 50 | # and `deprecated`. 51 | maintenance = { status = "actively-developed" } 52 | 53 | [dependencies] 54 | 55 | [build-dependencies] 56 | bindgen = "0.51.1" 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Carl Levasseur 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ta-lib-rust 2 | [![Build Status](https://travis-ci.org/CLevasseur/ta-lib-rust.svg?branch=master)](https://travis-ci.org/CLevasseur/ta-lib-rust) 3 | 4 | TA-lib bindings for Rust 5 | 6 | TA-lib is a multi-platform library for market analysis. It includes 200 indicators such as ADX, MACD, RSI, Stochastic, Bollinger Bands, as well as Candlestick pattern recognition. 7 | 8 | https://www.ta-lib.org/ 9 | 10 | ## Installation 11 | 12 | Add the following dependency in your `Cargo.toml` file: 13 | 14 | ```toml 15 | [dependencies] 16 | ta-lib-wrapper = "0.2.0" 17 | ``` 18 | 19 | And this to your crate root 20 | 21 | ```rust 22 | extern crate ta_lib_wrapper; 23 | ``` 24 | 25 | ## Dependencies 26 | 27 | This wrapper requires that you have installed the TA-lib C library. 28 | You can download it at https://www.ta-lib.org/hdr_dw.html. 29 | The instructions to install the library can be found at https://www.ta-lib.org/d_api/d_api.html and are summarized below. 30 | 31 | ##### Linux 32 | 33 | ```bash 34 | wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz 35 | tar xvzf ta-lib-0.4.0-src.tar.gz 36 | rm ta-lib-0.4.0-src.tar.gz 37 | cd ta-lib 38 | ./configure 39 | make 40 | sudo make install 41 | ``` 42 | 43 | ##### macOS 44 | 45 | ```bash 46 | brew install ta-lib 47 | ``` 48 | 49 | ##### Windows 50 | 51 | Download [ta-lib-0.4.0-msvc.zip](http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-msvc.zip) 52 | and unzip to ``C:\ta-lib`` 53 | 54 | > This is a 32-bit release. If you want to use 64-bit Python, you will need 55 | > to build a 64-bit version of the library. 56 | > Some unofficial (and unsupported) instructions for building on 64-bit Windows 10, here for reference: 57 | > 1. Download and Unzip ``ta-lib-0.4.0-msvc.zip`` 58 | > 2. Move the Unzipped Folder ``ta-lib`` to ``C:\`` 59 | > 3. Download and Install Visual Studio Community 2015 60 | > * Remember to Select ``[Visual C++]`` Feature 61 | > 4. Build TA-Lib Library 62 | > * From Windows Start Menu, Start ``[VS2015 x64 Native Tools Command Prompt]`` 63 | > * Move to ``C:\ta-lib\c\make\cdr\win32\msvc`` 64 | > * Build the Library ``nmake`` 65 | 66 | ## Documentation 67 | 68 | The `examples` folder shows how to compute some common indicators using this library. 69 | The full list of functions provided by these bindings can be obtained by building your project and open the file `target/*/build/ta-lib-wrapper-*/out/bindings.rs` 70 | 71 | ## Supported Indicators 72 | 73 | All indicators provided by TA-lib are available: 74 | 75 | ``` 76 | AD Chaikin A/D Line 77 | ADOSC Chaikin A/D Oscillator 78 | ADX Average Directional Movement Index 79 | ADXR Average Directional Movement Index Rating 80 | APO Absolute Price Oscillator 81 | AROON Aroon 82 | AROONOSC Aroon Oscillator 83 | ATR Average True Range 84 | AVGPRICE Average Price 85 | BBANDS Bollinger Bands 86 | BETA Beta 87 | BOP Balance Of Power 88 | CCI Commodity Channel Index 89 | CDL2CROWS Two Crows 90 | CDL3BLACKCROWS Three Black Crows 91 | CDL3INSIDE Three Inside Up/Down 92 | CDL3LINESTRIKE Three-Line Strike 93 | CDL3OUTSIDE Three Outside Up/Down 94 | CDL3STARSINSOUTH Three Stars In The South 95 | CDL3WHITESOLDIERS Three Advancing White Soldiers 96 | CDLABANDONEDBABY Abandoned Baby 97 | CDLADVANCEBLOCK Advance Block 98 | CDLBELTHOLD Belt-hold 99 | CDLBREAKAWAY Breakaway 100 | CDLCLOSINGMARUBOZU Closing Marubozu 101 | CDLCONCEALBABYSWALL Concealing Baby Swallow 102 | CDLCOUNTERATTACK Counterattack 103 | CDLDARKCLOUDCOVER Dark Cloud Cover 104 | CDLDOJI Doji 105 | CDLDOJISTAR Doji Star 106 | CDLDRAGONFLYDOJI Dragonfly Doji 107 | CDLENGULFING Engulfing Pattern 108 | CDLEVENINGDOJISTAR Evening Doji Star 109 | CDLEVENINGSTAR Evening Star 110 | CDLGAPSIDESIDEWHITE Up/Down-gap side-by-side white lines 111 | CDLGRAVESTONEDOJI Gravestone Doji 112 | CDLHAMMER Hammer 113 | CDLHANGINGMAN Hanging Man 114 | CDLHARAMI Harami Pattern 115 | CDLHARAMICROSS Harami Cross Pattern 116 | CDLHIGHWAVE High-Wave Candle 117 | CDLHIKKAKE Hikkake Pattern 118 | CDLHIKKAKEMOD Modified Hikkake Pattern 119 | CDLHOMINGPIGEON Homing Pigeon 120 | CDLIDENTICAL3CROWS Identical Three Crows 121 | CDLINNECK In-Neck Pattern 122 | CDLINVERTEDHAMMER Inverted Hammer 123 | CDLKICKING Kicking 124 | CDLKICKINGBYLENGTH Kicking - bull/bear determined by the longer marubozu 125 | CDLLADDERBOTTOM Ladder Bottom 126 | CDLLONGLEGGEDDOJI Long Legged Doji 127 | CDLLONGLINE Long Line Candle 128 | CDLMARUBOZU Marubozu 129 | CDLMATCHINGLOW Matching Low 130 | CDLMATHOLD Mat Hold 131 | CDLMORNINGDOJISTAR Morning Doji Star 132 | CDLMORNINGSTAR Morning Star 133 | CDLONNECK On-Neck Pattern 134 | CDLPIERCING Piercing Pattern 135 | CDLRICKSHAWMAN Rickshaw Man 136 | CDLRISEFALL3METHODS Rising/Falling Three Methods 137 | CDLSEPARATINGLINES Separating Lines 138 | CDLSHOOTINGSTAR Shooting Star 139 | CDLSHORTLINE Short Line Candle 140 | CDLSPINNINGTOP Spinning Top 141 | CDLSTALLEDPATTERN Stalled Pattern 142 | CDLSTICKSANDWICH Stick Sandwich 143 | CDLTAKURI Takuri (Dragonfly Doji with very long lower shadow) 144 | CDLTASUKIGAP Tasuki Gap 145 | CDLTHRUSTING Thrusting Pattern 146 | CDLTRISTAR Tristar Pattern 147 | CDLUNIQUE3RIVER Unique 3 River 148 | CDLUPSIDEGAP2CROWS Upside Gap Two Crows 149 | CDLXSIDEGAP3METHODS Upside/Downside Gap Three Methods 150 | CMO Chande Momentum Oscillator 151 | CORREL Pearson's Correlation Coefficient (r) 152 | DEMA Double Exponential Moving Average 153 | DX Directional Movement Index 154 | EMA Exponential Moving Average 155 | HT_DCPERIOD Hilbert Transform - Dominant Cycle Period 156 | HT_DCPHASE Hilbert Transform - Dominant Cycle Phase 157 | HT_PHASOR Hilbert Transform - Phasor Components 158 | HT_SINE Hilbert Transform - SineWave 159 | HT_TRENDLINE Hilbert Transform - Instantaneous Trendline 160 | HT_TRENDMODE Hilbert Transform - Trend vs Cycle Mode 161 | KAMA Kaufman Adaptive Moving Average 162 | LINEARREG Linear Regression 163 | LINEARREG_ANGLE Linear Regression Angle 164 | LINEARREG_INTERCEPT Linear Regression Intercept 165 | LINEARREG_SLOPE Linear Regression Slope 166 | MA All Moving Average 167 | MACD Moving Average Convergence/Divergence 168 | MACDEXT MACD with controllable MA type 169 | MACDFIX Moving Average Convergence/Divergence Fix 12/26 170 | MAMA MESA Adaptive Moving Average 171 | MAX Highest value over a specified period 172 | MAXINDEX Index of highest value over a specified period 173 | MEDPRICE Median Price 174 | MFI Money Flow Index 175 | MIDPOINT MidPoint over period 176 | MIDPRICE Midpoint Price over period 177 | MIN Lowest value over a specified period 178 | MININDEX Index of lowest value over a specified period 179 | MINMAX Lowest and highest values over a specified period 180 | MINMAXINDEX Indexes of lowest and highest values over a specified period 181 | MINUS_DI Minus Directional Indicator 182 | MINUS_DM Minus Directional Movement 183 | MOM Momentum 184 | NATR Normalized Average True Range 185 | OBV On Balance Volume 186 | PLUS_DI Plus Directional Indicator 187 | PLUS_DM Plus Directional Movement 188 | PPO Percentage Price Oscillator 189 | ROC Rate of change : ((price/prevPrice)-1)*100 190 | ROCP Rate of change Percentage: (price-prevPrice)/prevPrice 191 | ROCR Rate of change ratio: (price/prevPrice) 192 | ROCR100 Rate of change ratio 100 scale: (price/prevPrice)*100 193 | RSI Relative Strength Index 194 | SAR Parabolic SAR 195 | SAREXT Parabolic SAR - Extended 196 | SMA Simple Moving Average 197 | STDDEV Standard Deviation 198 | STOCH Stochastic 199 | STOCHF Stochastic Fast 200 | STOCHRSI Stochastic Relative Strength Index 201 | SUM Summation 202 | T3 Triple Exponential Moving Average (T3) 203 | TEMA Triple Exponential Moving Average 204 | TRANGE True Range 205 | TRIMA Triangular Moving Average 206 | TRIX 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA 207 | TSF Time Series Forecast 208 | TYPPRICE Typical Price 209 | ULTOSC Ultimate Oscillator 210 | VAR Variance 211 | WCLPRICE Weighted Close Price 212 | WILLR Williams' %R 213 | WMA Weighted Moving Average 214 | ``` 215 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | extern crate bindgen; 2 | 3 | use std::env; 4 | use std::path::PathBuf; 5 | 6 | fn main() { 7 | // Tell cargo to tell rustc to link the system ta_lib 8 | // shared library. 9 | println!("cargo:rustc-link-lib=ta_lib"); 10 | 11 | // The bindgen::Builder is the main entry point 12 | // to bindgen, and lets you build up options for 13 | // the resulting bindings. 14 | let bindings = bindgen::Builder::default() 15 | // The input header we would like to generate 16 | // bindings for. 17 | .header("wrapper.h") 18 | // Generate rustified enums 19 | .rustified_enum(".*") 20 | // Finish the builder and generate the bindings. 21 | .generate() 22 | // Unwrap the Result and panic on failure. 23 | .expect("Unable to generate bindings"); 24 | 25 | // Write the bindings to the $OUT_DIR/bindings.rs file. 26 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); 27 | bindings 28 | .write_to_file(out_path.join("bindings.rs")) 29 | .expect("Couldn't write bindings!"); 30 | } 31 | -------------------------------------------------------------------------------- /examples/atr.rs: -------------------------------------------------------------------------------- 1 | extern crate ta_lib_wrapper; 2 | use ta_lib_wrapper::{TA_Integer, TA_Real, TA_ATR, TA_RetCode}; 3 | 4 | 5 | /// Compute ATR(period) 6 | /// This function returns a tuple containing the list of ATR values and the index of the first 7 | /// candle to have an associated ATR value 8 | fn atr(period: u32, high: &Vec, low: &Vec, 9 | close: &Vec) -> (Vec, TA_Integer) 10 | { 11 | let mut out: Vec = Vec::with_capacity(close.len()); 12 | let mut out_begin: TA_Integer = 0; 13 | let mut out_size: TA_Integer = 0; 14 | 15 | unsafe { 16 | let ret_code = TA_ATR( 17 | 0, // index of the first close to use 18 | close.len() as i32 - 1, // index of the last close to use 19 | high.as_ptr(), // pointer to the first element of the high vector 20 | low.as_ptr(), // pointer to the first element of the low vector 21 | close.as_ptr(), // pointer to the first element of the close vector 22 | period as i32, // period of the atr 23 | &mut out_begin, // set to index of the first close to have an atr value 24 | &mut out_size, // set to number of atr values computed 25 | out.as_mut_ptr() // pointer to the first element of the output vector 26 | ); 27 | match ret_code { 28 | // Indicator was computed correctly, since the vector was filled by TA-lib C library, 29 | // Rust doesn't know what is the new length of the vector, so we set it manually 30 | // to the number of values returned by the TA_ATR call 31 | TA_RetCode::TA_SUCCESS => out.set_len(out_size as usize), 32 | // An error occured 33 | _ => panic!("Could not compute indicator, err: {:?}", ret_code) 34 | } 35 | } 36 | 37 | (out, out_begin) 38 | } 39 | 40 | fn main() { 41 | let high: Vec = vec![ 42 | 1.087130, 1.087120, 1.087220, 1.087230, 1.087180, 1.087160, 1.087210, 1.087150, 1.087200, 43 | 1.087230, 1.087070, 1.087000, 1.086630, 1.086650, 1.086680, 1.086690, 1.086690, 1.086690, 44 | 1.086690, 1.086650 45 | ]; 46 | let low: Vec = vec![ 47 | 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110, 48 | 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650, 49 | 1.086670, 1.086630 50 | ]; 51 | let close: Vec = vec![ 52 | 1.087130, 1.087120, 1.087220, 1.087230, 1.087110, 1.087120, 1.087100, 1.087120, 1.087130, 53 | 1.087080, 1.087000, 1.086630, 1.086630, 1.086650, 1.086640, 1.086690, 1.086650, 1.086690, 54 | 1.086670, 1.086640 55 | ]; 56 | 57 | let (atr_values, begin) = atr(7, &high, &low, &close); 58 | 59 | // print values 60 | for (index, value) in atr_values.iter().enumerate() { 61 | println!("index {} = {}", begin + index as i32 + 1, value); 62 | } 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/rsi.rs: -------------------------------------------------------------------------------- 1 | extern crate ta_lib_wrapper; 2 | use ta_lib_wrapper::{TA_Integer, TA_Real, TA_RSI, TA_RetCode}; 3 | 4 | 5 | /// Compute RSI(period) on `close_prices` 6 | /// This function returns a tuple containing the list of rsi values and the index of the first 7 | /// close to have an associated rsi value 8 | fn rsi(period: u32, close_prices: &Vec) -> (Vec, TA_Integer) { 9 | let mut out: Vec = Vec::with_capacity(close_prices.len()); 10 | let mut out_begin: TA_Integer = 0; 11 | let mut out_size: TA_Integer = 0; 12 | 13 | unsafe { 14 | let ret_code = TA_RSI( 15 | 0, // index of the first close to use 16 | close_prices.len() as i32 - 1, // index of the last close to use 17 | close_prices.as_ptr(), // pointer to the first element of the vector 18 | period as i32, // period of the rsi 19 | &mut out_begin, // set to index of the first close to have an rsi value 20 | &mut out_size, // set to number of sma values computed 21 | out.as_mut_ptr() // pointer to the first element of the output vector 22 | ); 23 | match ret_code { 24 | // Indicator was computed correctly, since the vector was filled by TA-lib C library, 25 | // Rust doesn't know what is the new length of the vector, so we set it manually 26 | // to the number of values returned by the TA_RSI call 27 | TA_RetCode::TA_SUCCESS => out.set_len(out_size as usize), 28 | // An error occured 29 | _ => panic!("Could not compute indicator, err: {:?}", ret_code) 30 | } 31 | } 32 | 33 | (out, out_begin) 34 | } 35 | 36 | fn main() { 37 | let close_prices: Vec = vec![ 38 | 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110, 39 | 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650, 40 | 1.086670, 1.086630 41 | ]; 42 | 43 | let (rsi_values, begin) = rsi(7, &close_prices); 44 | 45 | // print values 46 | for (index, value) in rsi_values.iter().enumerate() { 47 | println!("Close index {} = {}", begin + index as i32 + 1, value); 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /examples/sma.rs: -------------------------------------------------------------------------------- 1 | extern crate ta_lib_wrapper; 2 | use ta_lib_wrapper::{TA_Integer, TA_Real, TA_MA, TA_MAType, TA_RetCode}; 3 | 4 | 5 | /// Compute SMA(period) on `close_prices` 6 | /// This function returns a tuple containing the list of sma values and the index of the first 7 | /// close to have an associated sma value 8 | fn sma(period: u32, close_prices: &Vec) -> (Vec, TA_Integer) { 9 | let mut out: Vec = Vec::with_capacity(close_prices.len()); 10 | let mut out_begin: TA_Integer = 0; 11 | let mut out_size: TA_Integer = 0; 12 | 13 | unsafe { 14 | let ret_code = TA_MA( 15 | 0, // index of the first close to use 16 | close_prices.len() as i32 - 1, // index of the last close to use 17 | close_prices.as_ptr(), // pointer to the first element of the vector 18 | period as i32, // period of the sma 19 | TA_MAType::TA_MAType_SMA, // type of the MA, here forced to sma 20 | &mut out_begin, // set to index of the first close to have an sma value 21 | &mut out_size, // set to number of sma values computed 22 | out.as_mut_ptr() // pointer to the first element of the output vector 23 | ); 24 | match ret_code { 25 | // Indicator was computed correctly, since the vector was filled by TA-lib C library, 26 | // Rust doesn't know what is the new length of the vector, so we set it manually 27 | // to the number of values returned by the TA_MA call 28 | TA_RetCode::TA_SUCCESS => out.set_len(out_size as usize), 29 | // An error occured 30 | _ => panic!("Could not compute indicator, err: {:?}", ret_code) 31 | } 32 | } 33 | 34 | (out, out_begin) 35 | } 36 | 37 | fn main() { 38 | let close_prices: Vec = vec![ 39 | 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110, 40 | 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650, 41 | 1.086670, 1.086630 42 | ]; 43 | 44 | // compute sma, since we use a period of 10, the first 10 closes won't have 45 | // an sma value because there is not enough data, so begin will be set to 46 | // the index 29 47 | let (sma_values, begin) = sma(10, &close_prices); 48 | 49 | // print values 50 | for (index, value) in sma_values.iter().enumerate() { 51 | println!("Close index {} = {}", begin + index as i32 + 1, value); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_upper_case_globals)] 2 | #![allow(non_camel_case_types)] 3 | #![allow(non_snake_case)] 4 | 5 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 6 | -------------------------------------------------------------------------------- /wrapper.h: -------------------------------------------------------------------------------- 1 | #include "ta-lib/ta_abstract.h" 2 | #include "ta-lib/ta_common.h" 3 | #include "ta-lib/ta_defs.h" 4 | #include "ta-lib/ta_func.h" 5 | #include "ta-lib/ta_libc.h" 6 | --------------------------------------------------------------------------------