Skip to content

Commit

Permalink
remove old MA algorithm and format indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
hpyhacking committed Oct 26, 2014
1 parent a24f34d commit bd7d020
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
23 changes: 0 additions & 23 deletions app/assets/javascripts/component_data/market.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,19 @@
[_, _, _, _, pre_close, _] = pre
cur_close >= pre_close # {true: up, false: down}

@computeMA = (old, sum, unit) ->
# time, open, high, low, close, volume
[_, _, _, _, old_close, _] = old
[sum / unit, sum - old_close]

@handleData = (data, minutes) ->
ma = [[], [], [], []]
ma_sum = [0, 0, 0, 0]
ma_def = [4, 9, 14, 29]
[volume, candlestick, close_price] = [[], [], []]

for cur, i in data
[time, open, high, low, close, vol] = cur
time = time * 1000 # fixed unix timestamp for highsotck
trend = if i >= 1 then @checkTrend(data[i-1], cur) else true

# compute MA
#===========================================
ma_sum[k] = s + close for s, k in ma_sum

for x, j in ma_def
continue if i < x
unit = x + 1
old = data[i-x]
sum = ma_sum[j]

[ma_val, new_sum] = @computeMA(old, sum, unit)
ma[j].push [time, ma_val]
ma_sum[j] = new_sum

close_price.push [time, close]
candlestick.push [time, open, high, low, close]
volume.push {x: time, y: vol, color: if trend then 'rgba(255, 0, 0, 0.5)' else 'rgba(0, 255, 0, 0.5)'}

result = candlestick: candlestick, volume: volume, orig: data, minutes: minutes, close: close_price
result["ma#{x + 1}"] = ma[q] for x, q in ma_def

@trigger 'market::candlestick::response', result

Expand Down
17 changes: 15 additions & 2 deletions app/assets/javascripts/component_ui/candlestick.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ RANGE_DEFAULT =
useHTML: true
shared: true
headerFormat: "<div class='chart-ticker'><span class='tooltip-title'>{point.key}</span><br />"
footerFormat: '</div>'
footerFormat: '<ul></div>'
positioner: -> {x: 0, y: 0}

plotOptions:
Expand All @@ -139,8 +139,21 @@ RANGE_DEFAULT =
tooltip:
pointFormat:
"""
<div class='tooltip-ticker'><span class=t-title>#{gon.i18n.chart.volume}</span><span class=t-value>{point.y}</span></div><br/>
<div class='tooltip-ticker'><span class=t-title>#{gon.i18n.chart.volume}</span><span class=t-value>{point.y}</span></div><ul class='list-inline'>
"""
trendline:
tooltip:
pointFormat:
"""
<li><i class='fa fa-circle' style='color: {series.color};'></i><span>{series.name}: <b>{point.y}</b></span></li>
"""
histogram:
tooltip:
pointFormat:
"""
<li><i class='fa fa-circle' style='color: {series.color};'></i><span>{series.name}: <b>{point.y}</b></span></li>
"""

scrollbar:
buttonArrowColor: '#333'
barBackgroundColor: '#202020'
Expand Down

0 comments on commit bd7d020

Please sign in to comment.