|
I waded through all the detritus that the AI powered search engines tossed at me, and managed to narrow things down with:
Quote: C# search for date gridview from date picker
https://stackoverflow.com/questions/62045173/filter-datagridview-from-datepicker
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Probably the most relevant part of that link is the following very important advice when searching for time values.
"Because, no matter how hard I tried, I could not remove the time from the datetime value . . . I decided to use a greater than date and less than date."
Although it is still incorrect.
That is exclusive on both ends. One needs to to exclusive on one end and inclusive on the other.
|
|
|
|
|
1 namespace ATAS.Indicators.Technical;
2
3 using ATAS.Indicators.Drawing;
4 using OFT.Localization;
5 using OFT.Rendering.Context;
6 using OFT.Rendering.Settings;
7 using OFT.Rendering.Tools;
8 using System;
9 using System.ComponentModel;
10 using System.ComponentModel.DataAnnotations;
11 using System.Drawing;
12 using System.Runtime.Intrinsics.X86;
13 using Color = System.Drawing.Color;
14
15 [DisplayName("Candle X")]
16 public class CandleStatist : Indicator
17 {
18 #region Nested types
19
20 public enum LabelLocations
21 {
22 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.AboveCandle))]
23 Top,
24
25 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.BelowCandle))]
26 Bottom,
27
28 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ByCandleDirection))]
29 CandleDirection
30 }
31
32 #endregion
33
34 #region Fields
35
36 private readonly PenSettings _bgPen = new() { Color = DefaultColors.Gray.Convert() };
37 private readonly BrushSettings _bgBrush = new();
38 private readonly RenderStringFormat _format = new()
39
40
41 {
42 Alignment = StringAlignment.Center,
43 LineAlignment = StringAlignment.Center,
44 };
45 private int _backGroundTransparency = 8;
46
47
48
49 const int X = 100;
50 public double uhv;
51 private double av;
52 public double r;
53 public double ar;
54 public double uwrb;
55 public double wrb;
56 public double u3;
57 public double m3;
58 public double l20d;
59
60
61 #endregion
62
63 #region Properties
64
65 #region Settings
66
67 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.LabelLocation), GroupName = nameof(Strings.Settings))]
68 public LabelLocations LabelLocation { get; set; } = LabelLocations.Top;
69
70 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ShowVolume), GroupName = nameof(Strings.Settings))]
71 public bool ShowVolume { get; set; } = true;
72
73 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ShowDelta), GroupName = nameof(Strings.Settings))]
74 public bool ShowDelta { get; set; } = true;
75
76 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.ClustersMode), GroupName = nameof(Strings.Settings))]
77 public bool ClusterModeOnly { get; set; }
78
79 #endregion
80
81 #region Visualization
82
83 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Volume), GroupName = nameof(Strings.Visualization))]
84 public Color VolumeColor { get; set; } = DefaultColors.White;
85
86 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.PositiveDelta), GroupName = nameof(Strings.Visualization))]
87 public Color PositiveDeltaColor { get; set; } = Color.Green;
88
89 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.NegativeDelta), GroupName = nameof(Strings.Visualization))]
90 public Color NegativeDeltaColor { get; set; } = Color.Red;
91
92 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.BackGround), GroupName = nameof(Strings.Visualization))]
93 public Color BackGroundColor
94 {
95 get => _bgPen.Color.Convert();
96 set
97 {
98 _bgPen.Color = value.Convert();
99 _bgBrush.StartColor = GetColorTransparency(value, BackGroundTransparency).Convert();
100 }
101 }
102
103 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.HideBackGround), GroupName = nameof(Strings.Visualization))]
104 public bool HideBackGround { get; set; } = true;
105
106 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Font), GroupName = nameof(Strings.Visualization))]
107 public FontSetting FontSetting { get; set; } = new("Times New Roman", 6);
108
109 [Range(0, int.MaxValue)]
110 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Offset), GroupName = nameof(Strings.Visualization))]
111 public int Offset { get; set; } = 10;
112
113 [Range(1, 10)]
114 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.BorderWidth), GroupName = nameof(Strings.Visualization))]
115 public int BorderWidth
116 {
117 get => _bgPen.Width;
118 set => _bgPen.Width = value;
119 }
120
121 [Range(0, 10)]
122 [Display(ResourceType = typeof(Strings), Name = nameof(Strings.Transparency), GroupName = nameof(Strings.Visualization))]
123 public int BackGroundTransparency
124 {
125 get => _backGroundTransparency;
126 set
127 {
128 _backGroundTransparency = value;
129 _bgBrush.StartColor = GetColorTransparency(BackGroundColor, BackGroundTransparency).Convert();
130 }
131 }
132
133 #endregion
134
135 #endregion
136
137 #region ctor
138
139 public CandleStatist() : base(true)
140 {
141 DenyToChangePanel = true;
142 DataSeries[0].IsHidden = true;
143 ((ValueDataSeries)DataSeries[0]).ShowZeroValue = false;
144
145 EnableCustomDrawing = true;
146 SubscribeToDrawingEvents(DrawingLayouts.Final);
147
148 _bgPen.Color = BackGroundColor.Convert();
149 _bgBrush.StartColor = GetColorTransparency(BackGroundColor, _backGroundTransparency).Convert();
150 }
151
152 #endregion
153
154 #region Protected methods
155
156 protected override void OnCalculate(int bar, decimal value)
157 {
158 }
159
160 protected override void OnRender(RenderContext context, DrawingLayouts layout)
161 {
162 if (ChartInfo == null)
163 return;
164
165 if (ClusterModeOnly && ChartInfo.ChartVisualMode != ChartVisualModes.Clusters)
166 return;
167
168 DrawLabels(context);
169 }
170
171 #endregion
172
173 #region Private methods
174
175 public readonly SMA _sma = new SMA() { Period = X };
176 public readonly HighestX _highestX = new HighestX() ;
177 public readonly LowestX _lowestX = new LowestX();
178
179 private void DrawLabels(RenderContext context)
180 {
181 if (!(ShowDelta || ShowVolume))
182 return;
183
184 for (int bar = FirstVisibleBarNumber; bar <= LastVisibleBarNumber; bar++)
185 {
186 var candle = GetCandle(bar);
187
188
189 var av = _sma.Calculate(X, (candle.Volume));
190 var uhv = ((candle.Volume) > (2 * av));
191 var r = (candle.High - candle.Low);
192 var ar = _sma.Calculate(X, (candle.High - candle.Low));
193
194
195 var uwrb = (r > (2m * ar));
196 var wrb = (r > (1.33m * ar)) && (r < (2m * ar));
197 var u3 = (candle.Close > (candle.High - (r / 3)));
198 var m3 = (candle.Close > (candle.High - (r / 3))) && (candle.Close > (candle.Low + (r / 3)));
199
200 var prevCandle = GetCandle(bar-1);
201 var l20d = (candle.Low) < prevCandle.(_lowestX.Calculate(20, candle.Low));
202
203
204
205
206 var delta = candle.Delta;
207 var volumeStr = ChartInfo.TryGetMinimizedVolumeString(candle.Volume);
208 var deltaStr = ChartInfo.TryGetMinimizedVolumeString(delta);
209
210 var shiftBetweenStr = (int)(FontSetting.RenderObject.Size / 100 * 20);
211 var shift = 2;
212
213 var volumeSize = new Size();
214 var deltaSize = new Size();
215
216 if (ShowVolume)
217 volumeSize = context.MeasureString(volumeStr, FontSetting.RenderObject);
218
219 if (ShowDelta)
220 deltaSize = context.MeasureString(deltaStr, FontSetting.RenderObject);
221
222 var h = volumeSize.Height + deltaSize.Height + shift * 2 + shiftBetweenStr;
223 var y = (int)GetStartY(candle, h);
224 var w = Math.Max(volumeSize.Width, deltaSize.Width) + shift * 2;
225 w = GetTrueWidth(w);
226 var x = ChartInfo.GetXByBar(bar) + (int)((ChartInfo.PriceChartContainer.BarsWidth - w) / 2);
227
228 var rectangle = new Rectangle(x, y, w, h);
229
230 if (!HideBackGround)
231 context.DrawFillRectangle(_bgPen.RenderObject, _bgBrush.RenderObject.StartColor, rectangle);
232
233 if (ShowVolume)
234 {
235 y += shift;
236 var rec = new Rectangle(x, y, w, volumeSize.Height);
237 context.DrawString(volumeStr, FontSetting.RenderObject, VolumeColor, rec, _format);
238 }
239
240 if (ShowDelta)
241 {
242 y += volumeSize.Height > 0 ? volumeSize.Height + shiftBetweenStr : shift;
243 var rec = new Rectangle(x, y, w, deltaSize.Height);
244 var color = delta < 0 ? NegativeDeltaColor : PositiveDeltaColor;
245 context.DrawString(deltaStr, FontSetting.RenderObject, color, rec, _format);
246 }
247 }
248 }
249
250 private string GetTrueString(decimal value)
251 {
252 var absValue = Math.Abs(value);
253
254 if ((int)absValue < absValue)
255 return value.ToString().TrimEnd('0');
256
257 return value.ToString();
258 }
259
260 private int GetTrueWidth(int width)
261 {
262 return Math.Min(width, (int)ChartInfo.PriceChartContainer.BarsWidth);
263 }
264
265 private decimal GetStartY(IndicatorCandle candle, int height)
266 {
267 var topHeight = ChartInfo.GetYByPrice(candle.High) - Offset - height;
268 var bottomHeight = ChartInfo.GetYByPrice(candle.Low) + Offset + ChartInfo.PriceChartContainer.PriceRowHeight;
269
270 return LabelLocation switch
271 {
272 LabelLocations.Top => topHeight,
273 LabelLocations.Bottom => bottomHeight,
274 LabelLocations.CandleDirection => candle.Open > candle.Close
275 ? bottomHeight
276 : topHeight,
277 _ => 0,
278 };
279 }
280
281 private Color GetColorTransparency(Color color, int tr = 5)
282 {
283 var colorA = Math.Max(color.A - (tr * 25), 0);
284
285 return Color.FromArgb((byte)colorA, color.R, color.G, color.B);
286 }
287
288 #endregion
289 }
modified 25-Nov-23 3:57am.
|
|
|
|
|
What is the exact error message?
|
|
|
|
|
cs1001 identifier expected its in line 201
|
|
|
|
|
I cannot see anything obvious in lines 200/201 or 280/281 that would cause this. Are you sure there are no other messages?
|
|
|
|
|
var prevCandle = GetCandle(bar-1);
var l20d = (candle.Low) < prevCandle.(_lowestX.Calculate(20, candle.Low));
this is giving me cs1001: identifier expected. im not getting where to correct that @ start of parenthisis of prevCandle.(
|
|
|
|
|
On line 201 you have the following:
var l20d = (candle.Low) < prevCandle.(_lowestX.Calculate(20, candle.Low));
^
but the period character after prevCandle implies a reference to a Property or Method. But the following expression in parentheses is neither.
|
|
|
|
|
im a beginner, im trying edit it according to my condition,, can there be any solution
//@version=5
indicator("VK", "Stop vol", overlay=true, max_bars_back = 500, max_boxes_count = 1000, max_lines_count = 250, max_labels_count = 500)
X = input(10)
av = (ta.sma(volume, X))
uhv = (volume > (2 * av))
r = high -low
ar = ta.sma(r,X)
uwrb = (r>(2*ar))
wrb = (r>(1.33*ar)) and (r<(2*ar))
u3 = close > (high-(r/3))
m3 = (close < (high - (r/3))) and (close > (low + (r/3)))
l20d = low < ta.lowest(low,20)[1]
sos = (close < close[1]) and ((volume > ta.highest(volume,3)[1] and l20d) or uhv) and (uwrb or wrb) and (m3 or u3)
plotshape(sos, style=shape.xcross, location = location.belowbar ,color= #2ebd85 ,text= 'sv' ,textcolor= #2ebd85 , size = size.auto)
this is compelte Tradingv iew code, im trying get l20d line
|
|
|
|
|
Sorry I have no idea what that code is supposed to represent.
|
|
|
|
|
l20d = low < ta.lowest(low,20)[1]
how to get this is c# that would be sufficient
|
|
|
|
|
That is a valid expression in C#. But that does not mean it will work. You need to understand what each variable represents and what the resulting values are expected to be.
|
|
|
|
|
thank you for the help , it is nice to have a platform like this.
|
|
|
|
|
im trying convert this Trading view code to C#
l20d = low < ta.lowest(low,20)[1]
|
|
|
|
|
I have a lines of data being written to a serial port. This data is in the following form
50 100 150 200 250 300 300 136 55 110 175 225 268 364 398 193
I am trying to make a C# application which would continously update 16 text boxes with these 16 values which are seperated by a tab. My current code just writes some garbage to the first textbox then the application closes. WHy?
void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
string dataLine = serialPort1.ReadLine();
if (dataLine == null || dataLine.Trim().Length == 0)
{
return;
}
string[] dataValues = dataLine.Split('\t');
textBox2.Text = dataValues[0];
textBox3.Text = dataValues[1];
textBox4.Text = dataValues[2];
textBox5.Text = dataValues[3];
textBox6.Text = dataValues[4];
textBox7.Text = dataValues[5];
textBox8.Text = dataValues[6];
textBox9.Text = dataValues[7];
textBox10.Text = dataValues[8];
textBox11.Text = dataValues[9];
textBox12.Text = dataValues[10];
textBox13.Text = dataValues[11];
textBox14.Text = dataValues[12];
textBox15.Text = dataValues[13];
textBox16.Text = dataValues[14];
textBox17.Text = dataValues[15];
}
private void button3_Click(object sender, EventArgs e)
{
try
{
if (serialPort1.IsOpen)
{
serialPort1.DataReceived += DataReceivedHandler;
}
else
{
MessageBox.Show("Error : Port needs to be open or wrong port selected!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
And didn't you DEBUG your code?
|
|
|
|
|
Mismatched baud rate? Start bit?
And you receive garbage, so it is likely you do not have 15 tab characters decoded - so dataValues[x] will throw an exception once x is larger than the array length.
But as mentioned you already have a tool that will tell you that in seconds: the debugger.
|
|
|
|
|
You're expecting a certain length, but aren't checking how much you're actually reading; just that it is longer than "nothing".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Kshitij Bali wrote: then the application closes. WHy?
Besides what the other responses said...
You need a try/catch in DataReceivedHandler.
I suspect that would tell you why the application is exiting.
|
|
|
|
|
hi guys, so I changed my code and the problem in that particular place is solved but reemerging elsewhere. So I have two buttons now. One button (button1) is used to open and close the port, second (button3) is used to start filling up text boxes from the serial port. What is happening is that when I open the port and click start it starts filling the text boxes fine. but when I click stop (button3) the command to clear the text boxes is not getting executed. Also subsequently when I close the port (button1) and reopen it (button1 again) then click button 3 again to start filling the text boxes again, the same error repeats (index is out of bounds of the array) . Below is my new code.
private bool isFirstLine = true;
void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
try
{
string dataLine = serialPort1.ReadLine();
if (dataLine == null || dataLine.Trim().Length == 0)
{
return;
}
if (isFirstLine)
{
isFirstLine = false;
return;
}
string[] dataValues = dataLine.Split('\t');
this.Invoke((MethodInvoker)delegate
{
textBox2.Text = dataValues[0];
textBox3.Text = dataValues[1];
textBox4.Text = dataValues[2];
textBox5.Text = dataValues[3];
textBox6.Text = dataValues[4];
textBox7.Text = dataValues[5];
textBox8.Text = dataValues[6];
textBox9.Text = dataValues[7];
textBox10.Text = dataValues[8];
textBox11.Text = dataValues[9];
textBox12.Text = dataValues[10];
textBox13.Text = dataValues[11];
textBox14.Text = dataValues[12];
textBox15.Text = dataValues[13];
textBox16.Text = dataValues[14];
textBox17.Text = dataValues[15];
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ClearTextBoxes()
{
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
textBox14.Text = "";
textBox15.Text = "";
textBox16.Text = "";
textBox17.Text = "";
}
private bool isReadingData = false;
private void button3_Click(object sender, EventArgs e)
{
try
{
if (serialPort1.IsOpen)
{
if (!isReadingData)
{
serialPort1.WriteLine("1");
serialPort1.DataReceived += DataReceivedHandler;
isReadingData = true;
button3.Text = "STOP";
button1.Enabled = false;
button1.Visible = false;
}
else
{
serialPort1.WriteLine("0");
serialPort1.DataReceived -= DataReceivedHandler;
isReadingData = false;
button3.Text = "START";
button1.Enabled = true;
button1.Visible = true;
ClearTextBoxes();
}
}
else
{
MessageBox.Show("Error : Port needs to be open or wrong port selected!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button1_Click(object sender, EventArgs e)
{
if(serialPort1.IsOpen)
{
PortClosing();
button1.Text = "Open";
ClearTextBoxes();
button3.Visible = false;
}
else
{
PortOpening();
button1.Text = "Close";
button3.Visible = true;
}
}
modified 21-Nov-23 2:41am.
|
|
|
|
|
As suggested, you need to learn how to debug the code by using the debugger.
That will allow you to step through the lines.
Kshitij Bali wrote: index is out of bounds of the array
I think this was already suggested....
This is accessing an array 'dataValues[15]'
The error occurs when the array is NOT that big.
You are assuming it is that size. It isn't. So you need to check. As suggested the results are probably coming in pieces and not all at once. Or only some is coming.
|
|
|
|
|
I'm trying to populate a combobox with a column in a SQLite database table. Im using an Absolute path in my connection string but Im getting an Error that the table doesn't exist. Ive read through other posts and still cant resolve the problem. Here is my code.
public Form1()
{
InitializeComponent();
if (File.Exists(@"R:\TEOP\Tracker\Tracker.db"))
{
SQLiteConnection conn;
conn = new SQLiteConnection("Data Source=R:\\TEOP\\Tracker\\Tracker.db,version=3;");
conn.Open();
SQLiteCommand cmd;
cmd = conn.CreateCommand();
cmd.CommandText = @"SELECT IncidentName FROM Incident;";
var dr = cmd.ExecuteReader();
while (dr.Read())
{
IncidentCombo.Items.Add(dr["IncidentName"]);
}
}
}
Ive checked permissions and path. My query works in the database browser.
|
|
|
|
|
In problem posts like this, always copy'n'paste the exact error message.
If the message indeed says your table doesn't exist, it has nothing to do with the connection string. It's telling you don't have a table called 'Incident' in your database. Check the spelling of the table name in your query and carefully compare to the table name in the database.
|
|
|
|
|
NOTE: DISCLAIMER: I have no experience with SQLite! This is just a shot in the dark from an ignorant non-expert:
I tried to look up examples of SQL use, and saw them use a semicolon rather than a comma before 'version=3;'
I also saw that opening a non-existing database will created one by the given name.
So, if the entire string 'R:\\TEOP\\Tracker\\Tracker.db,version=3' is take as a database name, then you are opening a new, empty database, which obviously doesn't have an 'Incident' table.
(I must admit that I am surprised if a database can be named R:\\TEOP\\Tracker\\Tracker.db,version=3, so this may be a completely wrong track to follow!)
|
|
|
|
|
Thank you that was the problem ....A typing error replacing the "," with a ";" was the problem. Syntax is a killer at times!....lol
|
|
|
|
|