etfdiction/app/models/etf.rb
# Chapter 6A
# TODO: Add 5 day sma condition too
Chapter 6A
TODO: Add 5 day sma condition too
Chapter 6A TODO : Add 5 day sma condition too
def a200_multiple_day_up_down?
    records_close = EtfPrice.where(name: name).where("date <= '#{Date.today}'").order(date: :desc).limit(5).pluck(:close)
    count = 0
    count += 1 if records_close[0] < records_close[1]
    count += 1 if records_close[1] < records_close[2]
    count += 1 if records_close[2] < records_close[3]
    count += 1 if records_close[3] < records_close[4]
    if market_opened?
      current_price = realtime_from_yahoo[:current]
      count += 1 if current_price < records_close[0]
      return true if count >= 4
    else
      return true if count >= 3
    end
    false
  end
def a200_multiple_day_up_down? records_close = EtfPrice . where ( name : name ) . where ( "date <= '#{Date.today}'" ) . order ( date : :desc ) . limit ( 5 ) . pluck ( :close ) count = 0 count += 1 if records_close [ 0 ] < records_close [ 1 ] count += 1 if records_close [ 1 ] < records_close [ 2 ] count += 1 if records_close [ 2 ] < records_close [ 3 ] count += 1 if records_close [ 3 ] < records_close [ 4 ] if market_opened? current_price = realtime_from_yahoo [ :current ] count += 1 if current_price < records_close [ 0 ] return true if count >= 4 else return true if count >= 3 end false end
Chapter 6A
TODO: Add 5 day sma condition too
Chapter 6A TODO : Add 5 day sma condition too