HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
2
anychart.onDocumentReady(function () {
3
anychart.data.loadCsvFile('https://cdn.anychart.com/csv-data/csco-daily.csv', function (data) {
4
var dataTable = anychart.data.table()
5
dataTable.addData(data)
6
var mapping = dataTable.mapAs({'open': 1, 'high': 2, 'low': 3, 'close': 4, 'value': 4})
7
8
var chart = anychart.stock()
9
chart.scroller().enabled(false)
10
11
var candlesPlot = chart.plot(0)
12
candlesPlot.yGrid(true).xGrid(true)
13
candlesPlot.yAxis(0).labels().position('inside')
14
candlesPlot.yAxis(0).ticks().enabled(false)
15
candlesPlot.yAxis(0).orientation('right')
16
17
var candlesLegend = candlesPlot.legend()
18
candlesLegend.title(false)
19
candlesLegend.fontSize(10)
20
21
// Simple Moving Average
22
candlesPlot.sma(mapping, 5).series()
23
candlesPlot.sma(mapping, 10).series()
24
candlesPlot.sma(mapping, 20).series()
25
26
// Exponential Moving Average
27
// candlesPlot.ema(mapping, 5).series()
28
// candlesPlot.ema(mapping, 10).series()
29
// candlesPlot.ema(mapping, 20).series()
30
31
// Bollinger Bands indicator
32
// candlesPlot.bbands(mapping)
33
34
var candleSeries = candlesPlot.candlestick(mapping)
35
candleSeries.name('CSCO')
36
candleSeries.legendItem().iconType('rising-falling')
37
candleSeries.risingStroke("#24C780")
38
candleSeries.risingFill("#24C780")
39
candleSeries.fallingStroke("#FF694E")
40
candleSeries.fallingFill("#FF694E")
41
42
candleSeries.maxLabels()
43
.enabled(true)
44
.position('center-top ')
45
.format("{%high}")
46
.fontWeight('bold')
47
.fontColor('#6da632')
48
49
candleSeries.minLabels()
50
.enabled(true)
51
.position('center-bottom')
52
.format("{%low}")
53
.fontWeight('bold')
54
.fontColor('#d81e05')
55
56
// Volume
57
var volumeMapping = dataTable.mapAs({
58
'value': 5,
59
'type': 'average'
60
})
61
var volumePlot = chart.plot(1)
62
volumePlot.height('20%')
63
var volSeries =volumePlot.column(volumeMapping).name('Volume')
64
volSeries.risingStroke("#24C780")
65
volSeries.risingFill("#24C780")
66
volSeries.fallingStroke("#FF694E")
67
volSeries.fallingFill("#FF694E")
68
volumePlot.xAxis().enabled(false)
69
volumePlot.yAxis().enabled(false)
70
71
volumePlot.crosshair().yLabel().format('{%Value}{scale: (1000000)|(mln), decimalsCount: 0}')
72
var volumeLegend = volumePlot.legend()
73
volumeLegend.title(false)
74
volumeLegend.fontSize(10)
75
volumeLegend.title(false)
76
77
// MACD
78
var macdPlot = chart.plot(2)
79
macdPlot.height('20%')
80
macdPlot.xAxis().enabled(false)
81
macdPlot.yAxis().enabled(false)
82
83
var macdLegend = macdPlot.legend()
84
macdLegend.fontSize(10)
85
macdLegend.title(false)
86
var macd = macdPlot.macd(mapping, 12, 20, 9)
87
macd.macdSeries().stroke('#0094FF')
88
89
/*
90
// RSI
91
var rsiPlot = chart.plot(2)
92
rsiPlot.height('20%')
93
rsiPlot.xAxis().enabled(false)
94
rsiPlot.yAxis(0).labels().position('inside')
95
rsiPlot.yAxis(0).ticks().enabled(false)
96
rsiPlot.yAxis(0).orientation('right')
97
var rsiLegend = rsiPlot.legend()
98
rsiLegend.fontSize(10)
99
rsiLegend.title(false)
100
var rsi7 = rsiPlot.rsi(mapping, 7).series()
101
var rsi14 = rsiPlot.rsi(mapping, 14).series()
102
var rsi21 = rsiPlot.rsi(mapping, 21).series()
103
*/
104
105
var grouping = chart.grouping()
106
grouping.maxVisiblePoints(50)
107
108
// set chart selected date/time range
109
chart.selectRange('2008-10-25', '2009-07-01')
110
chart.container('container')
111
chart.draw()
112
})
113
})