Indicators

Commodity Channel Index


Description

The Commodity Channel Index​ (CCI) is a momentum-based oscillator used to help determine when an investment vehicle is reaching a condition of being overbought or oversold.

Developed by Donald Lambert, this technical indicator assesses price trend direction and strength, allowing traders to determine if they want to enter or exit a trade, refrain from taking a trade, or add to an existing position. In this way, the indicator can be used to provide trade signals when it acts in a certain way.

For more information, please visit Investopedia.


Params & Instance Methods

#initialize
@param series [Array] An array of arrays containing high, low, close information, e.g. [[high, low, close], [high, low, close]]
@param period [Integer] The number of periods to use in the calculation - default is 20

#call
@return [Float] The current Commodity Channel Index value

#valid?
@return [Boolean] Whether or not the object is valid

Example

require 'ruby-technical-analysis'

series = [[15.125, 14.936, 14.936], [15.052, 14.6267, 14.752], [14.8173, 14.5557, 14.5857],
          [14.69, 14.46, 14.6], [14.7967, 14.5483, 14.6983], [14.7940, 13.9347, 13.946],
          [14.093, 13.8223, 13.9827], [14.7, 14.02, 14.45], [14.5255, 14.2652, 14.3452]]
period = 5

commodity_channel_index = 
  RubyTechnicalAnalysis::CommodityChannelIndex.new(
    series: series,
    period: period
  )

p commodity_channel_index.valid? # true

p commodity_channel_index.call.truncate(3) # 18.089