Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultPeriods = 14
DefaultPeriods is the default number of periods for the averages for the RSI algorithm.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BigRSI ¶
type BigRSI struct {
// contains filtered or unexported fields
}
BigRSI represents the state of a Relative Strength Index (RSI) algorithm.
type RSI ¶
type RSI struct {
// contains filtered or unexported fields
}
RSI represents the state of a Relative Strength Index (RSI) algorithm.
func New ¶
New creates a new RSI data structure and returns the initial result.
The length of the initial input slice should be 1 + `periods`. Where `periods` is the length of the lookback period.
func (*RSI) Calculate ¶
Calculate produces the next RSI result given the next input.
Example ¶
// Create a logger. logger := log.New(os.Stdout, "", 0) // Create the RSI data structure and get the first result. // // The slice argument should be the number of periods const initialLength = rsi.DefaultPeriods + 1 r, result := rsi.New(prices[:initialLength]) logger.Printf("Period index: %d\nFirst RSI result: %.8f", rsi.DefaultPeriods, result) // Use the remaining data to generate the RSI for each period. for _, next := range prices[initialLength:] { result = r.Calculate(next) } logger.Printf("Period index: %d\nLast RSI result: %.8f", len(prices)-1, result)
Output: Period index: 14 First RSI result: 72.36421725 Period index: 166 Last RSI result: 37.34374224
Click to show internal directories.
Click to hide internal directories.