Skip to content

Commit

Permalink
use highchart style build MA
Browse files Browse the repository at this point in the history
  • Loading branch information
hpyhacking committed Oct 26, 2014
1 parent 299df61 commit a24f34d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
53 changes: 24 additions & 29 deletions app/assets/javascripts/component_ui/candlestick.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RANGE_DEFAULT =
@initTooltip = ->
chart = @$node.highcharts()
tooltips = []
for i in [0..3]
for i in [0..1]
if chart.series[i].points.length > 0
tooltips.push chart.series[i].points[chart.series[i].points.length - 1]
chart.tooltip.refresh tooltips
Expand Down Expand Up @@ -175,21 +175,22 @@ RANGE_DEFAULT =
gridLineColor: '#222'
gridLineDashStyle: 'ShortDot'
top: "0%"
height: "60%"
height: "70%"
lineColor: '#fff'
}
{
labels:
enabled: false
top: "60%"
top: "70%"
gridLineColor: '#000'
height: "20%"
height: "15%"
}
{
labels:
enabled: false
top: "80%"
top: "85%"
gridLineColor: '#000'
height: "20%"
height: "15%"
}
]

Expand Down Expand Up @@ -225,35 +226,29 @@ RANGE_DEFAULT =
showInLegend: false
}
{
name: 'MA5'
type: 'spline'
data: data['ma5']
color: '#7c9aaa'
}
{
name: 'MA10'
type: 'spline'
data: data['ma10']
color: '#be8f53'
}
{
name: 'MA15'
type: 'spline'
data: data['ma15']
data: data['close']
visible: false
id: 'close'
showInLegend: false
}
{
name: 'MA30'
type: 'spline'
data: data['ma30']
visible: false
name: 'MA5',
linkedTo: 'close',
showInLegend: true,
type: 'trendline',
algorithm: 'MA',
periods: 5
color: '#7c9aaa'
}
{
type: 'spline'
data: data['close']
visible: false
id: 'close'
showInLegend: false
name: 'MA10'
linkedTo: 'close',
showInLegend: true,
type: 'trendline',
algorithm: 'MA',
periods: 10
color: '#be8f53'
}
{
name: 'EMA7',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
return SMA(xData, yData, periods);
},

MA: function (xData, yData, periods) {

return MA(xData, yData, periods);
},


/* Function using the global EMA function.
*
Expand Down Expand Up @@ -271,6 +276,26 @@
return lineData;
}

function MA (xData, yData, periods) {
var maLine = [],
periodArr = [],
length = yData.length;

for (var i = 0; i < length; i++) {
periodArr.push(yData[i]);

if (i >= periods) {
maLine.push([xData[i] , arrayAvg(periodArr)]);
periodArr.shift();
}
else {
maLine.push([xData[i] , null]);
}
}

return maLine;
}


/* Function based on the idea of an exponential moving average.
*
Expand All @@ -283,7 +308,6 @@
* @return an array containing the EMA.
**/
function EMA (xData, yData, periods) {

var t,
y = false,
n = periods,
Expand Down Expand Up @@ -384,4 +408,3 @@
}

}(Highcharts));

1 change: 0 additions & 1 deletion app/assets/javascripts/market.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#= require ./lib/pusher_connection

#= require highstock
#= require highsotck_ex
#= require_tree ./highcharts/

#= require_tree ./helpers
Expand Down

0 comments on commit a24f34d

Please sign in to comment.