forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTechnicalIndicators.cs
264 lines (252 loc) · 11.4 KB
/
TechnicalIndicators.cs
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#region Copyright Syncfusion Inc. 2001-2021.
// Copyright Syncfusion Inc. 2001-2021. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Com.Syncfusion.Charts;
using Android.Graphics;
namespace SampleBrowser
{
public class TechnicalIndicators : SamplePage
{
SfChart chart;
List<String> adapter;
public override View GetSampleContent(Context context)
{
chart = new SfChart(context);
chart.SetPadding(0, 10, 0, 0);
chart.Behaviors.Add(new ChartTrackballBehavior());
DateTimeAxis dateTimeAxis = new DateTimeAxis();
dateTimeAxis.LabelStyle.LabelFormat = "MM/yyyy";
chart.PrimaryAxis = dateTimeAxis;
NumericalAxis numericalAxis = new NumericalAxis();
chart.SecondaryAxis = numericalAxis;
HiLoOpenCloseSeries candleSeries = new HiLoOpenCloseSeries();
candleSeries.ItemsSource = MainPage.GetTechnicalIndicatorData();
candleSeries.XBindingPath = "XValue";
candleSeries.Open = "Open";
candleSeries.Close = "Close";
candleSeries.High = "High";
candleSeries.Low = "Low";
candleSeries.EnableAnimation = true;
candleSeries.Name = "Series";
chart.Series.Add(candleSeries);
SimpleMovingAverageIndicator sMA = new SimpleMovingAverageIndicator();
sMA.SeriesName = "Series";
sMA.XBindingPath = "XValue";
sMA.Open = "Open";
sMA.Close = "Close";
sMA.High = "High";
sMA.Low = "Low";
sMA.EnableAnimation = true;
chart.TechnicalIndicators.Add(sMA);
TextView labelDisplayMode = new TextView(context);
labelDisplayMode.TextSize = 20;
labelDisplayMode.Text = "Technical Indicator type";
Spinner selectLabelMode = new Spinner(context,SpinnerMode.Dialog);
adapter = new List<String>() {"Simple Moving Average Indicator", "Average True Indicator", "Exponential Moving Averge Indicator", "Momentum Indicator",
"Accumulation Distribution Indicator", "RSI Indicator", "Triangular Moving Average Indicator",
"MACD Indicator", "Stochastic Indicator", "Bollinger Band Indicator" };
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
(context, Android.Resource.Layout.SimpleSpinnerItem, adapter);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleDropDownItem1Line);
selectLabelMode.Adapter = dataAdapter;
selectLabelMode.ItemSelected += SelectLabelMode_ItemSelected;
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.SetPadding(20, 0, 20, 30);
linearLayout.SetBackgroundColor(Color.Rgb(236, 235, 242));
linearLayout.LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent,
LinearLayout.LayoutParams.WrapContent);
linearLayout.Orientation = Orientation.Vertical;
linearLayout.SetBackgroundColor(Color.White);
linearLayout.AddView(selectLabelMode);
linearLayout.AddView(chart);
return linearLayout;
}
private void SelectLabelMode_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
String selectedItem = adapter[e.Position];
if (selectedItem.Equals("Accumulation Distribution Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
AccumulationDistributionIndicator accumulationDistribution = new AccumulationDistributionIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
accumulationDistribution.YAxis = numericalAxis;
accumulationDistribution.SeriesName = "Series";
accumulationDistribution.XBindingPath = "XValue";
accumulationDistribution.Open = "Open";
accumulationDistribution.Close = "Close";
accumulationDistribution.High = "High";
accumulationDistribution.Low = "Low";
chart.TechnicalIndicators.Add(accumulationDistribution);
}
else if (selectedItem.Equals("Average True Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
AverageTrueIndicator aTR = new AverageTrueIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
aTR.YAxis = numericalAxis;
aTR.Period = 14;
aTR.SeriesName = "Series";
aTR.XBindingPath = "XValue";
aTR.Open = "Open";
aTR.Close = "Close";
aTR.High = "High";
aTR.Low = "Low";
chart.TechnicalIndicators.Add(aTR);
}
else if (selectedItem.Equals("Exponential Moving Averge Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
ExponentialMovingAverageIndicator eMA = new ExponentialMovingAverageIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
eMA.YAxis = numericalAxis;
eMA.Period = 14;
eMA.SeriesName = "Series";
eMA.XBindingPath = "XValue";
eMA.Open = "Open";
eMA.Close = "Close";
eMA.High = "High";
eMA.Low = "Low";
chart.TechnicalIndicators.Add(eMA);
}
else if (selectedItem.Equals("Momentum Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
MomentumIndicator momentum = new MomentumIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
momentum.YAxis = numericalAxis;
momentum.SeriesName = "Series";
momentum.XBindingPath = "XValue";
momentum.Open = "Open";
momentum.Close = "Close";
momentum.High = "High";
momentum.Low = "Low";
momentum.Period = 14;
chart.TechnicalIndicators.Add(momentum);
}
else if (selectedItem.Equals("Simple Moving Average Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
SimpleMovingAverageIndicator sMA = new SimpleMovingAverageIndicator();
sMA.SeriesName = "Series";
sMA.XBindingPath = "XValue";
sMA.Open = "Open";
sMA.Close = "Close";
sMA.High = "High";
sMA.Low = "Low";
sMA.Period = 14;
chart.TechnicalIndicators.Add(sMA);
}
else if (selectedItem.Equals("RSI Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
RSIIndicator rSI = new RSIIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
rSI.YAxis = numericalAxis;
rSI.Period = 14;
rSI.SeriesName = "Series";
rSI.XBindingPath = "XValue";
rSI.Open = "Open";
rSI.Close = "Close";
rSI.High = "High";
rSI.Low = "Low";
chart.TechnicalIndicators.Add(rSI);
}
else if (selectedItem.Equals("Triangular Moving Average Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
TriangularMovingAverageIndicator tMA = new TriangularMovingAverageIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
tMA.YAxis = numericalAxis;
tMA.Period = 14;
tMA.SeriesName = "Series";
tMA.XBindingPath = "XValue";
tMA.Open = "Open";
tMA.Close = "Close";
tMA.High = "High";
tMA.Low = "Low";
chart.TechnicalIndicators.Add(tMA);
}
else if (selectedItem.Equals("MACD Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
MACDIndicator mACD = new MACDIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
mACD.YAxis = numericalAxis;
mACD.SeriesName = "Series";
mACD.XBindingPath = "XValue";
mACD.Open = "Open";
mACD.Close = "Close";
mACD.High = "High";
mACD.Low = "Low";
mACD.ShortPeriod = 2;
mACD.LongPeriod = 10;
mACD.Trigger = 14;
chart.TechnicalIndicators.Add(mACD);
}
else if (selectedItem.Equals("Stochastic Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
StochasticIndicator stochastic = new StochasticIndicator();
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
stochastic.YAxis = numericalAxis;
stochastic.SeriesName = "Series";
stochastic.XBindingPath = "XValue";
stochastic.Open = "Open";
stochastic.Close = "Close";
stochastic.High = "High";
stochastic.Low = "Low";
stochastic.Period = 14;
stochastic.KPeriod = 5;
stochastic.DPeriod = 6;
chart.TechnicalIndicators.Add(stochastic);
}
else if (selectedItem.Equals("Bollinger Band Indicator"))
{
chart.TechnicalIndicators.RemoveAt(0);
BollingerBandIndicator bB = new BollingerBandIndicator();
bB.Period = 14;
NumericalAxis numericalAxis = new NumericalAxis();
numericalAxis.OpposedPosition = true;
numericalAxis.ShowMajorGridLines = false;
//bB.YAxis = numericalAxis;
bB.SeriesName = "Series";
bB.XBindingPath = "XValue";
bB.Open = "Open";
bB.Close = "Close";
bB.High = "High";
bB.Low = "Low";
chart.TechnicalIndicators.Add(bB);
}
}
}
}