/
sharePricePlot2.R
120 lines (102 loc) · 4.75 KB
/
sharePricePlot2.R
1
2
3
4
5
6
7
8
9
10
11
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
sharePricePlot2 <- function(data){
data <- na.exclude(data)
data <- transform(data, date = as.numeric(as.Date(date)) * 86400000)
a <- rCharts::Highcharts$new()
a$yAxis(list(
list(title = list(text = "Share Price"),max = max(data$close)*1.05,opposite = TRUE,height = 300,
labels = list(
style = list(
fontWeight = "bold")
)
),
list(title = list(text = "MACD"),max = max(data$MACD)*1.05,min = min(data$MACD)*0.95,opposite = FALSE,
top = 325,offset = 0,height = 75,
labels = list(
style = list(
fontWeight = "bold")
)
),
list(title = list(text = "CHAI"),max = max(data$Chai)*1.05,min = min(data$Chai)*0.95,
opposite = TRUE, plotBands = list(color = "black",from = 100, to = 110),
top = 425,offset = 0,height = 75,
labels = list(
style = list(
fontWeight = "bold")
)
),
list(title = list(text = "Elder"),opposite = FALSE,
top = 525,offset = 0,height = 75,
labels = list(
style = list(
fontWeight = "bold")
)
)
)
)
a$xAxis(type = "datetime")
a$series(type = "line",name = "Share Price",
data = toJSONArray2(data[,c("date","close")],json = F,names = F),
color = "orange"
)
a$series(type = "line",name = "MA",
data = toJSONArray2(data[,c("date","MA")],json = F,names = F)
)
a$series(type = "line",name = "EMA",
data = toJSONArray2(data[,c("date","EMA")],json = F,names = F)
)
a$series(type = "line",name = "BollUp",
data = toJSONArray2(data[,c("date","up")],json = F,names = F),
color = "red"
)
a$series(type = "line",name = "BollDn",
data = toJSONArray2(data[,c("date","dn")],json = F,names = F),
color = "red"
)
a$series(type = "line",name = "Bollavg",
data = toJSONArray2(data[,c("date","mavg")],json = F,names = F),
color = "red"
)
a$series(type = "line",name = "MACD",
data = toJSONArray2(data[,c("date","MACD")],json = F,names = F),
yAxis = 1
)
a$series(type = "line",name = "SIGNAL",
data = toJSONArray2(data[,c("date","SIGNAL")],json = F,names = F),
yAxis = 1
)
a$series(type = "line",name = "CHAI",
data = toJSONArray2(data[,c("date","Chai")],json = F,names = F),
yAxis = 2
)
a$series(type = "line",name = "CHAI SMA",
data = toJSONArray2(data[,c("date","chaiSMA")],json = F,names = F),
yAxis = 2
)
a$series(type = "line",name = "Elder Bear",
data = toJSONArray2(data[,c("date","Bear")],json = F,names = F),
yAxis = 3
)
a$series(type = "line",name = "ElderBull",
data = toJSONArray2(data[,c("date","Bull")],json = F,names = F),
yAxis = 3
)
a$tooltip(crosshairs = list(T,F),
shared=TRUE,
formatter = "#! function() {
var d = new Date(this.x);
d = d.toLocaleDateString();
d = '<strong>' + d + '</strong>';
$.each(this.points,function(){
d += '<br>' + this.series.name + ': ' + '<strong>' + Highcharts.numberFormat(this.y,2,'.') + '</strong>';
})
return (d);
}!#"
)
a$legend(align = "right",verticalAlign = "center",
layout = "vertical",itemMarginTop = 10,x = 10,
floating = FALSE,backgroundColor = "white",
labelFormatter="#! function () {return this.name;}!#")
a$plotOptions(series = list(pointPadding = 0,groupPadding = 0.2,marker = list(enabled=FALSE)))
a$chart(zoomType = 'x',width = 1000, height = 650,plotBorderWidth = 0.5,plotBorderColor="black")
a
}