|
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
|
|
|
|
|
Nice catch. I missed that one.
|
|
|
|
|
Just seen this example of C# 12 on Reddit:
public double GPA => grades switch
{
[] => 4.0,
[var grade] => grade,
[.. var all] => all.Average()
}; Seems innocuous enough, but there is a subtle problem: if the array contains more than one element, the property will allocate a copy of the entire array simply to pass to the Average method.
SharpLab[^]:
public double GPA
{
get
{
double[] array = <grades>P;
if (array != null)
{
int num = array.Length;
if (num != 0)
{
if (num == 1)
{
return array[0];
}
double[] subArray = RuntimeHelpers.GetSubArray(array, new Range(new Index(0), new Index(0, true)));
return Enumerable.Average(subArray);
}
return 4.0;
}
<PrivateImplementationDetails>.ThrowSwitchExpressionException(array);
double result = default(double);
return result;
}
} NB: The RuntimeHelpers.GetSubArray method[^] has no check to see if it's returning the entire array; it always creates a copy.
It's simple enough to fix:
public double GPA => grades switch
{
[] => 4.0,
[var grade] => grade,
[..] all => all.Average()
}; SharpLab[^]
public double GPA
{
get
{
double[] array = <grades>P;
if (array != null)
{
int num = array.Length;
if (num != 0)
{
if (num == 1)
{
return array[0];
}
return Enumerable.Average(array);
}
return 4.0;
}
<PrivateImplementationDetails>.ThrowSwitchExpressionException(array);
double result = default(double);
return result;
}
} But good luck spotting the difference in a code review, or explaining to anyone who hasn't spent time spelunking the BCL source repository why [..] all is better than [.. var all] !
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I think I'll stick with C, or maybe go back to COBOL.
|
|
|
|