Module: Coinbot::OrderBook::SMA
- Defined in:
- lib/coinbot/order_book/sma.rb
Class Method Summary collapse
-
.calculate(opts = {}) ⇒ Object
- Supported Method Parameters
-
Coinbot::OrderBook::SMA.calculate( ).
-
.help ⇒ Object
Display Usage for this Module.
Class Method Details
.calculate(opts = {}) ⇒ Object
- Supported Method Parameters
-
Coinbot::OrderBook::SMA.calculate( )
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/coinbot/order_book/sma.rb', line 12 public_class_method def self.calculate(opts = {}) candle_tot = opts[:candle_tot].to_i candle_key = opts[:candle_key] candles = opts[:candles] last_value = opts[:last_value].to_f this_product = opts[:this_product] quote_increment = this_product[:quote_increment] fiat_smallest_decimal = quote_increment.to_s.split('.')[-1].length base_currency = this_product[:base_currency].downcase.to_sym if candles if candles.length >= candle_tot && candle_tot.positive? bc_overrides = Coinbot::OrderBook.base_currency_overrides fiat_smallest_decimal = 8 if bc_overrides.include?( base_currency ) begin_candle = candle_tot * -1 case candle_key when :macd_history # This is only used to calculate EMA 9 for the MACD signal sma_sum = candles[begin_candle..-2].map do |in_scope| in_scope[candle_key].last[:macd].to_f end.sum else sma_sum = candles[begin_candle..-2].map do |in_scope| in_scope[candle_key].to_f end.sum end sma_sum += last_value simple_moving_average = format( "%0.#{fiat_smallest_decimal}f", sma_sum / candle_tot ) else simple_moving_average = '--' end else simple_moving_average = '--' end simple_moving_average rescue StandardError => e raise e end |
.help ⇒ Object
Display Usage for this Module
63 64 65 66 67 |
# File 'lib/coinbot/order_book/sma.rb', line 63 public_class_method def self.help puts "USAGE: golden_cross_indicator_hash = #{self}.status() " end |