Skip to content

Latest commit

ย 

History

325 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Go Reference License Go CI Codecov GHCR Version GitHub Stars

cinar%2Findicator | Trendshift

Indicator Go

Indicator is a Golang module that provides an extensive set of technical analysis indicators, strategies, and a framework for backtesting.

An extensive technical analysis library for algorithmic trading - 80+ indicators and backtesting framework.

Major improvements in v2:

  • Enhanced Code Quality: A complete rewrite was undertaken to achieve and maintain at least 90% code coverage.
  • Improved Testability: Each indicator and strategy have dedicated test data in CSV format for easier validation.
  • Streamlined Data Handling: The library was rewritten to operate on data streams (Go channels) for both inputs and outputs. If you prefer using slices, helper functions like helper.SliceToChan and helper.ChanToSlice are available. Alternatively, you can still use the v1 version.
  • Configurable Indicators and Strategies: All indicators and strategies were designed to be fully configurable with no preset values.
  • Generics Support: The library leverages Golang generics to support various numeric data formats.

There is also a TypeScript version of this module at Indicator TS.

โš ๏ธ Risk Disclosure & Legal Disclaimer

  1. Strict Educational, Research, and Informational Purpose Notice: This repository, software library, documentation, and all associated tools, mathematical models, indicator calculations, example strategies, and backtesting utilities are provided strictly and solely for educational, academic, and research purposes. Nothing contained herein constitutes, or is intended to constitute, investment, financial, tax, legal, or trading advice. No communication or output from this software shall be construed as a recommendation, endorsement, solicitation, or offer to buy or sell any security, commodity, currency, digital asset, or other financial instrument.

  2. Non-Advisory and Non-Fiduciary Status: The Indicator Authors, maintainers, contributors, and copyright holders are not registered investment advisers (RIAs), registered broker-dealers, commodity trading advisors (CTAs), commodity pool operators (CPOs), financial planners, or tax advisors with the U.S. Securities and Exchange Commission (SEC), the U.S. Commodity Futures Trading Commission (CFTC), the Financial Industry Regulatory Authority (FINRA), or any other regulatory agency or authority in any jurisdiction. The maintainers do not act in any fiduciary capacity, and no fiduciary, advisory, or professional-client relationship is established through the use of, contribution to, or access to this software.

  3. Risk Disclosure Regarding Substantial Trading Losses and Leverage: Trading and investing in equities, options, futures, foreign exchange (Forex), commodities, and cryptocurrencies carries substantial risk of loss and is not suitable for all individuals or investors. Prices of financial instruments fluctuate significantly and unpredictably. The use of leverage, margin, or derivative contracts can rapidly amplify losses as well as gains, potentially resulting in the complete loss of all invested capital or losses exceeding initial deposits. You should carefully consider whether trading is appropriate for you in light of your personal financial condition, experience level, and risk tolerance, and you should consult with qualified, licensed financial advisors before making any investment or trading decisions.

  4. CFTC-Style Hypothetical and Backtested Performance Disclosure (CFTC Rule 4.41): Hypothetical, simulated, or backtested performance results have inherent and significant limitations. Unlike an actual performance record, simulated results do not represent actual trading. Because trades have not actually been executed, results may over- or under-compensate for the impact, if any, of certain market factors, including but not limited to lack of liquidity, order execution delays, market impact, exchange fees, slippage, and spread. Furthermore, hypothetical and simulated trading programs are designed with the benefit of hindsight and retrospective knowledge of historical price movements. No representation or warranty is being made that any account, strategy, or portfolio will or is likely to achieve profits, avoid losses, or experience outcomes similar to those illustrated in any backtest, example, or simulation.

  5. "AS IS" Software Liability Limitation & Disclaimers: This software is provided on an "AS IS" and "AS AVAILABLE" basis, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, ACCURACY, COMPLETENESS, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, MAINTAINERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, FINANCIAL LOSSES, TRADING LOSSES, LOSS OF CAPITAL, LOSS OF PROFITS, LOSS OF DATA, SYSTEM FAILURES, INACCURATE CALCULATIONS, OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

๐Ÿ‘† Indicators Provided

The following list of indicators are currently supported by this package:

๐Ÿ“ˆ Trend Indicators

๐Ÿš€ Momentum Indicators

๐ŸŽข Volatility Indicators

๐Ÿ“ข Volume Indicators

๐Ÿ’ฐ Asset Valuation

๐Ÿ’ก Example Strategies (Educational Demonstrations)

The following concrete strategies are provided in the examples/ directory purely as illustrative demonstrations on how developers can consume the core indicator mathematics and generic backtesting framework. They are intended strictly for educational and research purposes:

โš– Base Strategies

๐Ÿ“ˆ Trend Strategy Examples

๐Ÿš€ Momentum Strategy Examples

๐ŸŽข Volatility Strategy Examples

๐Ÿ“ข Volume Strategy Examples

๐Ÿงช Compound Strategy Examples

Compound strategies demonstrate merging multiple indicator signals into unified actions using various logical combinations.

๐ŸŽ Decorator Strategy Examples

Decorator strategies offer an illustrative way to alter or filter the recommendations of underlying strategies.

๐Ÿ—ƒ Repositories

Repository serves as a centralized storage and retrieval location for asset snapshots.

The following repository implementations are provided.

The Sync function facilitates the synchronization of assets between designated source and target repositories by employing multi-worker concurrency for enhanced efficiency. This function serves the purpose of procuring the most recent snapshots from remote repositories and seamlessly transferring them to local repositories, such as file system repositories.

The indicator-sync command line tool also offers the capability of synchronizing data between the Tiingo Repository and the File System Repository. To illustrate its usage, consider the following example command:

$ indicator-sync \
    -source-name tiingo \
    -source-config $TIINGO_KEY \
    -target-name filesystem \
    -target-config /home/user/assets \
    -days 30

This command effectively retrieves the most recent snapshots for assets residing within the /home/user/assets directory from the Tiingo Repository. In the event that the local asset file is devoid of content, it automatically extends its reach to synchronize 30 days' worth of snapshots, ensuring a comprehensive and up-to-date repository.

โณ Backtesting

The Backtest functionality, using the Outcome, evaluates the hypothetical performance of specified strategies applied to a defined set of historical asset data. It generates comprehensive visual representations for each strategy-asset pairing.

import (
	"github.com/cinar/indicator/v2/asset"
	"github.com/cinar/indicator/v2/backtest"
	"github.com/cinar/indicator/v2/examples/trend"
)

report := backtest.NewHTMLReport(outputDir)
bt := backtest.NewBacktest(repository, report)
bt.Names = append(bt.Names, "brk-b")
bt.Strategies = append(bt.Strategies, trend.NewApoStrategy())

err = bt.Run()
if err != nil {
	t.Fatal(err)
}

The indicator-backtest command line tool empowers users to conduct comprehensive backtesting of assets residing within a specified repository. It does not run any strategy by default โ€” you must explicitly name the strategies to backtest with the -strategies flag, culminating in the generation of detailed reports within a designated output directory.

$ indicator-backtest \
    -repository-name filesystem \
    -repository-config /home/user/assets \
    -report-config /home/user/reports \
    -strategies apo,macd,rsi \
    -workers 1

Run indicator-backtest -list-strategies to print the full list of strategy names that are available to pass to -strategies.

๐Ÿณ Docker

The easiest way to get started is using our Docker image. It handles everything - syncing market data from Tiingo and generating backtest reports - in a single command.

Quick Start

# Get your free Tiingo API key at: https://www.tiingo.com/

# Run backtest for specific assets
docker run -it --rm \
  -v $(pwd)/output:/app/output \
  ghcr.io/cinar/indicator:latest \
  --api-key YOUR_TIINGO_API_KEY \
  --days 365 \
  --assets aapl msft googl \
  --strategies apo,macd,rsi

# View results (macOS)
open output/index.html

# View results (Linux)
xdg-open output/index.html

Options

Flag Description Default
--api-key Tiingo API key (required) -
--days Days of historical data to fetch 365
--last Days to backtest 365
--assets Space-separated ticker symbols (default: all) all
--strategies Comma-separated strategy names to backtest (required) -
--output Output directory for reports /app/output

Run docker run --rm --entrypoint ./indicator-backtest ghcr.io/cinar/indicator:latest -list-strategies to see the available strategy names.

Examples

# Backtest all available assets for 1 year
docker run -it --rm \
  -v $(pwd)/reports:/app/output \
  ghcr.io/cinar/indicator:latest \
  --api-key YOUR_TIINGO_API_KEY \
  --strategies apo,macd,rsi

# Backtest specific stocks for last 6 months, test last 30 days
docker run -it --rm \
  -v $(pwd)/reports:/app/output \
  ghcr.io/cinar/indicator:latest \
  --api-key YOUR_TIINGO_API_KEY \
  --days 180 \
  --last 30 \
  --assets aapl msft googl amzn \
  --strategies apo,macd,rsi

# Custom output directory
docker run -it --rm \
  -v /path/to/my/reports:/app/output \
  ghcr.io/cinar/indicator:latest \
  --api-key YOUR_TIINGO_API_KEY \
  --strategies apo,macd,rsi \
  --output /app/output

Build Locally

docker build -t indicator .
docker run -it --rm -v $(pwd)/output:/app/output indicator --api-key YOUR_KEY

Usage

Install package.

go get github.com/cinar/indicator/v2

Import indicator.

import (
    "github.com/cinar/indicator/v2"
)

๐ŸŒ Ecosystem

Indicator Go is part of a broader ecosystem of technical analysis tools:

  • Indicator TS - TypeScript/JavaScript implementation of the same indicators and strategies

๐Ÿ’– Our Sponsors

Indicator is a community-supported project. The following companies, organizations, and individuals help make our work possible. Become a sponsor and help us continue to grow!

Our Sponsors

Contributing to the Project

Anyone can contribute to Indicator library. Please make sure to read our Contributor Covenant Code of Conduct guide first. Follow the How to Contribute to Indicator to contribute. Signining a Contributor Agreement is also required to contribute to the project.

License

The v2.x.x and above are dual-licensed under GNU AGPLv3 License and a commercial license. For free use and modifications of the code, you can use the AGPLv3 license. If you require commercial license with different terms, please contact the maintainers.

Copyright (c) 2021-2026 The Indicator Authors.    
The source code is provided under GNU AGPLv3 License.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

The version v1.x.x is provided under MIT License.

Copyright (c) 2021-2026 The Indicator Authors.
The source code is provided under MIT License.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Trademarks

  • TD Sequentialยฎ is a registered trademark of DeMark Analytics, LLC. This library is an independent open-source mathematical implementation and is not affiliated with, sponsored by, or endorsed by DeMark Analytics, LLC.
  • Bollinger Bandsยฎ is a registered trademark of John Bollinger.
  • ConnorsRSIยฎ is a registered trademark of Connors Group, Inc.
  • All other product names, logos, and brands mentioned herein are trademarks or registered trademarks of their respective owners. Mention of third-party products, services, or trademarks is for nominative identification and educational purposes only and does not imply affiliation or endorsement.

About

High-performance technical analysis indicators and backtesting framework in Go. Zero dependencies. โœจ See how! ๐Ÿ‘€

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1.7k stars

Watchers

23 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages