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 BigInput ¶
BigInput represents the averages for a period that are inputted into the RSI algorithm.
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 (*RSI) Calculate ¶
Calculate produces the next RSI result given the next input.
Example ¶
// Create a logger. logger := log.New(os.Stdout, "", 0) // Gather some data. // // For production systems, it'd be best to gather test data asynchronously. avgGains, avgLosses = avgGains, avgLosses // Determine the number of periods for the initial inputs. Defaults to 14. periods := rsi.DefaultPeriods // Average the gains and losses over the given period. avgGain := avg(avgGains[0:periods]) avgLoss := avg(avgLosses[0:periods]) initialInput := rsi.Input{ AverageGain: avgGain, AverageLoss: avgLoss, } // Create the RSI data structure and get the first result. // // If the first argument, the initial periods is 0, the default value, 14, will be used. r, result := rsi.New(uint(periods), initialInput) logger.Printf("Period index: %d\nAverage gain: %.2f\nAverage loss: %.2f\nRSI: %.2f", periods-1, avgGain, avgLoss, result) // Use the remaining data to generate the RSI for each period. for i := periods; i < len(avgGains); i++ { avgGain = avgGains[i] avgLoss = avgLosses[i] result = r.Calculate(rsi.Input{ AverageGain: avgGain, AverageLoss: avgLoss, }) } logger.Printf("Period index: %d\nAverage gain: %.2f\nAverage loss: %.2f\nRSI: %.2f", len(avgGains)-1, avgGain, avgLoss, result)
Output: Period index: 13 Average gain: -0.11 Average loss: -0.11 RSI: 50.37 Period index: 99 Average gain: 0.35 Average loss: 0.00 RSI: 271.62
Click to show internal directories.
Click to hide internal directories.