Skip to content

sdcoffey/techan

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
March 6, 2021 09:20
March 30, 2018 14:53
September 22, 2020 09:02
July 17, 2021 09:37
March 30, 2018 11:58
March 3, 2021 09:16
November 17, 2021 08:09
September 12, 2020 08:10
September 12, 2020 08:10
April 12, 2018 10:06
April 12, 2018 10:06
December 20, 2019 07:47
April 12, 2018 10:06
April 12, 2018 10:06
December 3, 2019 21:43
sp
March 6, 2021 09:16
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
April 12, 2018 10:06
March 5, 2021 08:41
April 12, 2018 10:06
April 12, 2018 10:06

Techan

codecov

TechAn is a technical analysis library for Go! It provides a suite of tools and frameworks to analyze financial data and make trading decisions.

Features

  • Basic and advanced technical analysis indicators
  • Profit and trade analysis
  • Strategy building

Installation

$ go get github.com/sdcoffey/techan

Quickstart

series := techan.NewTimeSeries()

// fetch this from your preferred exchange
dataset := [][]string{
	// Timestamp, Open, Close, High, Low, volume
	{"1234567", "1", "2", "3", "5", "6"},
}

for _, datum := range dataset {
	start, _ := strconv.ParseInt(datum[0], 10, 64)
	period := techan.NewTimePeriod(time.Unix(start, 0), time.Hour*24)

	candle := techan.NewCandle(period)
	candle.OpenPrice = big.NewFromString(datum[1])
	candle.ClosePrice = big.NewFromString(datum[2])
	candle.MaxPrice = big.NewFromString(datum[3])
	candle.MinPrice = big.NewFromString(datum[4])

	series.AddCandle(candle)
}

closePrices := techan.NewClosePriceIndicator(series)
movingAverage := techan.NewEMAIndicator(closePrices, 10) // Create an exponential moving average with a window of 10

fmt.Println(movingAverage.Calculate(0).FormattedString(2))

Creating trading strategies

indicator := techan.NewClosePriceIndicator(series)

// record trades on this object
record := techan.NewTradingRecord()

entryConstant := techan.NewConstantIndicator(30)
exitConstant := techan.NewConstantIndicator(10)

// Is satisfied when the price ema moves above 30 and the current position is new
entryRule := techan.And(
	techan.NewCrossUpIndicatorRule(entryConstant, indicator),
	techan.PositionNewRule{})
	
// Is satisfied when the price ema moves below 10 and the current position is open
exitRule := techan.And(
	techan.NewCrossDownIndicatorRule(indicator, exitConstant),
	techan.PositionOpenRule{})

strategy := techan.RuleStrategy{
	UnstablePeriod: 10, // Period before which ShouldEnter and ShouldExit will always return false
	EntryRule:      entryRule,
	ExitRule:       exitRule,
}

strategy.ShouldEnter(0, record) // returns false

Enjoying this project?

Are you using techan in production? You can sponsor its development by buying me a coffee! ☕

ETH: 0x2D9d3A1c16F118A3a59d0e446d574e1F01F62949

Credits

Techan is heavily influenced by the great ta4j. Many of the ideas and frameworks in this library owe their genesis to the great work done over there.

License

Techan is released under the MIT license. See LICENSE for details.