Skip to content

A lightweight technical indicator package

License

Notifications You must be signed in to change notification settings

jellydator/tango

Repository files navigation

Tango - (Trading Analysis & Go)

Go Reference Build Status Go Report Card

Features

  • Simple API
  • Built-in parameters validation
  • Includes thorough documentation
  • A wide variety of Oscillators and Overlays.

Installation

go get github.com/jellydator/tango

Usage

All of the tools must be created using New* function. It performs parameters validation and returns an object that is capable of working with data slices.

The main calculations are done using Calc method. The return types varies based on the tool.

A simple use case could look like this:

func main() {
  sma, err := tango.NewSMA(3)
  if err != nil {
    // handle the error.
  }

  dataPoints := []decimal.Decimal{
    decimal.NewFromInt(2),
    decimal.NewFromInt(3),
    decimal.NewFromInt(4),
  }

  // the value is 3
  value, err := sma.Calc(dataPoints)
  if err != nil {
    // handle the error.
  }
}

For the calculation to be successful, the Calc method should receive only the information that it requires. In some scenarios, it might not be known how many data points is needed, for this, a Count method may be used.

func CalculateMA(ma tango.MA, values []decimal.Decimal) (decimal.Decimal, error) {
  requiredValues := ma.Count()

  if len(values) < requiredValues {
    return decimal.Zero, errors.New("invalid count of values")
  }

  return ma.Calc(values[:requiredValues])
}

Oscillators

Overlays