forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTechnicalIndicators.cs
273 lines (219 loc) · 8.07 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
265
266
#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
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
using System.Collections.Generic;
#endregion
using System;
using Syncfusion.SfChart.iOS;
using System.Collections.ObjectModel;
#if __UNIFIED__
using Foundation;
using UIKit;
using CoreGraphics;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using nint = System.Int32;
using nuint = System.Int32;
#endif
namespace SampleBrowser
{
public class TechnicalIndicators : SampleView
{
SFChart chart;
SFSMAIndicator indicator;
ObservableCollection<SFTechnicalIndicator> indicatorCollection;
UIPickerView indicatorTypePicker;
UIButton doneButton;
UIButton indicatorTypeTextButton;
public TechnicalIndicators()
{
indicatorTypePicker = new UIPickerView();
indicatorTypeTextButton = new UIButton();
doneButton = new UIButton();
indicator = new SFSMAIndicator();
indicator.SeriesName = new NSString("Hi-Low");
indicator.XBindingPath = "XValue";
indicator.High = "High";
indicator.Low = "Low";
indicator.Open = "Open";
indicator.Close = "Close";
SFNumericalAxis axis = new SFNumericalAxis();
axis.OpposedPosition = true;
axis.ShowMajorGridLines = false;
NSNumberFormatter axisFormatter = new NSNumberFormatter();
axisFormatter.PositivePrefix = "$";
axis.LabelStyle.LabelFormatter = axisFormatter;
indicator.YAxis = axis;
indicatorCollection = new ObservableCollection<SFTechnicalIndicator>();
indicatorCollection.Add(indicator);
chart = new SFChart();
chart.Title.Text = new NSString("StockDetails");
chart.Title.TextAlignment = UITextAlignment.Center;
SFDateTimeAxis datetime = new SFDateTimeAxis();
datetime.MaximumLabels = 6;
datetime.LabelsIntersectAction = SFChartAxisLabelsIntersectAction.Hide;
chart.PrimaryAxis = datetime;
datetime.Title.Text = new NSString("Date");
chart.SecondaryAxis = new SFNumericalAxis();
NSNumberFormatter secondaryAxisFormatter = new NSNumberFormatter();
secondaryAxisFormatter.PositivePrefix = "$";
chart.SecondaryAxis.LabelStyle.LabelFormatter = secondaryAxisFormatter;
SFChartTrackballBehavior behavior = new SFChartTrackballBehavior();
chart.AddChartBehavior(behavior);
chart.TechnicalIndicators.Add(indicator);
ChartViewModel dataModel = new ChartViewModel();
SFOHLCSeries series = new SFOHLCSeries();
series.ItemsSource = dataModel.TechnicalIndicatorData;
series.XBindingPath = "XValue";
series.High = "High";
series.Low = "Low";
series.Open = "Open";
series.Close = "Close";
series.EnableTooltip = true;
series.LineWidth = 1;
series.SeriesName = new NSString("Hi-Low");
series.ColorModel.Palette = SFChartColorPalette.Natural;
chart.Series.Add(series);
this.AddSubview(chart);
indicatorTypeTextButton.SetTitle("SMA indicator", UIControlState.Normal);
indicatorTypeTextButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
indicatorTypeTextButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
indicatorTypeTextButton.TouchUpInside += delegate
{
indicatorTypePicker.Hidden = false;
doneButton.Hidden = false;
this.BecomeFirstResponder();
};
indicatorTypeTextButton.BackgroundColor = UIColor.Clear;
indicatorTypeTextButton.Layer.BorderWidth = 2.0f;
indicatorTypeTextButton.Layer.BorderColor = UIColor.FromRGB(240.0f / 255.0f, 240.0f / 255.0f, 240.0f / 255.0f).CGColor;
indicatorTypeTextButton.Layer.CornerRadius = 8.0f;
this.AddSubview(indicatorTypeTextButton);
indicatorTypePicker.ShowSelectionIndicator = true;
indicatorTypePicker.Hidden = true;
indicatorTypePicker.Model = new StatusPickerViewModel(chart, indicatorTypeTextButton, indicator, indicatorCollection);
indicatorTypePicker.BackgroundColor = UIColor.FromRGB(240f / 255.0f, 240f / 255.0f, 240f / 255.0f);
indicatorTypePicker.SelectedRowInComponent(0);
this.AddSubview(indicatorTypePicker);
doneButton.SetTitle("Done" + "\t", UIControlState.Normal);
doneButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
doneButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
doneButton.TouchUpInside += delegate
{
indicatorTypePicker.Hidden = true;
doneButton.Hidden = true;
this.BecomeFirstResponder();
};
doneButton.BackgroundColor = UIColor.FromRGB(240f / 255.0f, 240f / 255.0f, 240f / 255.0f);
doneButton.Hidden = true;
this.AddSubview(doneButton);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
chart.Frame = new CGRect(this.Bounds.X, this.Bounds.Y + 40,
this.Bounds.Width, this.Bounds.Height - 40);
indicatorTypeTextButton.Frame = new CGRect(10, Bounds.Y, Frame.Size.Width - 20, 40);
if (Utility.IsIPad)
{
doneButton.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 253, Frame.Size.Width, 35);
indicatorTypePicker.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 260, Frame.Size.Width, 260);
}
else
{
doneButton.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 143, Frame.Size.Width, 35);
indicatorTypePicker.Frame = new CGRect(0, Bounds.Y + Frame.Size.Height - 150, Frame.Size.Width, 150);
}
}
}
public class StatusPickerViewModel : UIPickerViewModel
{
UIButton indicatorTypeTextButton;
SFChart chart;
SFTechnicalIndicator indicator;
ObservableCollection<SFTechnicalIndicator> indicatorCollection;
public StatusPickerViewModel(SFChart chart1, UIButton indicatorButton, SFTechnicalIndicator indicator1, ObservableCollection<SFTechnicalIndicator> collection)
{
indicatorTypeTextButton = indicatorButton;
chart = chart1;
indicator = indicator1;
indicatorCollection = collection;
}
private readonly IList<string> colors = new List<string>
{
"AD Indicator",
"ATR Indicator",
"BB Indicator",
"EMA Indicator",
"MACD Indicator",
"Momentum Indicator",
"RSI Indicator",
"SMA Indicator",
"Stochastic Indicator",
"TMA Indicator"
};
public override nint GetComponentCount(UIPickerView pickerView)
{
return 1;
}
public override nint GetRowsInComponent(UIPickerView pickerView, nint component)
{
return (nint)colors.Count;
}
public override string GetTitle(UIPickerView pickerView, nint row, nint component)
{
return colors[(int)row];
}
public override void Selected(UIPickerView pickerView, nint row, nint component)
{
indicatorTypeTextButton.SetTitle(colors[(int)row], UIControlState.Normal);
indicatorCollection.Clear();
chart.TechnicalIndicators.RemoveAt(0);
if (row == 0)
indicator = new SFADIndicator();
else if (row == 1)
indicator = new SFATRIndicator();
else if (row == 2)
indicator = new SFBBIndicator();
else if (row == 3)
indicator = new SFEMAIndicator();
else if (row == 4)
indicator = new SFMACDIndicator();
else if (row == 5)
indicator = new SFMomentumIndicator();
else if (row == 6)
indicator = new SFRSIIndicator();
else if (row == 7)
indicator = new SFSMAIndicator();
else if (row == 8)
indicator = new SFStochasticIndicator();
else if (row == 9)
indicator = new SFTMAIndicator();
indicator.SeriesName = new NSString("Hi-Low");
indicator.XBindingPath = "XValue";
indicator.High = "High";
indicator.Low = "Low";
indicator.Open = "Open";
indicator.Close = "Close";
SFNumericalAxis axis = new SFNumericalAxis();
axis.OpposedPosition = true;
axis.ShowMajorGridLines = false;
NSNumberFormatter axisFormatter = new NSNumberFormatter();
axisFormatter.PositivePrefix = "$";
axis.LabelStyle.LabelFormatter = axisFormatter;
indicator.YAxis = axis;
indicatorCollection = new ObservableCollection<SFTechnicalIndicator>();
indicatorCollection.Add(indicator);
chart.TechnicalIndicators.Add(indicator);
}
}
}