You can set a break-point, hover over the break-point for the following
Click the gear and set a condition and under Actions uncheck "Continue Execution".
When hit, hover over variables to see what the problem is.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I am trying to figure out why i get this message error:
Error on calling 'OnRender' method on bar 513: Object reference not set to an instance of an object.
My chart has 513 bars in it. I loop throught all the bars of the chart and create a new series of values (candle).
int index;
int LastIndexChecked = 0;
double sum = 0;
for(int barIndex = LastIndexChecked; barIndex <= CurrentBar; barIndex++)
{
double closePrice16 = Bars.GetClose(barIndex);
double openPrice9 = Bars.GetOpen(barIndex+1);
double closePrice = Bars.GetClose(barIndex+1);
double difCP = closePrice16 - openPrice9;
index = barIndex;
sum += difCP;
double candle = closePrice + sum;
Value[0] = candle;
I think somehow a break should be introduce to stop the loop at 513. Every minute a new bar is added in the chart, making the chart bars increase to 514, 515 ...
After a moment my indicator vanish from the chart. If i introduce a break after Value[0] i get a straight line in the chart.
Anyone has an idea where and how to introduce the break statement, if only that is the solution to my problem. Could be Value[0] as well but i am not sure what it is going to change.
Thank you
You can set a break-point, hover over the break-point for the following
Click the gear and set a condition and under Actions uncheck "Continue Execution".
When hit, hover over variables to see what the problem is.
You should use try {} catch {}. In the catch block you can show relevant information. You could then continue the program or exit the program. Tell us if you need details.
Use of try {} catch {} is very useful for diagnostic purposes but it should be used for production code too.
Hello,
The following are basic/simple which you should be able to use in tangent with my first reply or without my first reply.
In regards to try/catch
try
{
var fileContents = File.ReadAllLines("NonExistingFile.txt");
}
catch (Exception exception)
{
MessageBox.Show($"We encountered issues\n{exception.Message}");
}
private (List<string> lines, bool success, Exception exception) ReadSomeFile()
{
List<string> contents = new List<string>();
try
{
var fileContents = File.ReadAllLines("NonExistingFile.txt");
return (lines: contents, success: true, exception: null);
}
catch (Exception ex)
{
return (lines: contents, success: false, exception: ex);
}
}
Usage
var (lines, success, exception) = ReadSomeFile();
if (success)
{
foreach (var line in lines)
{
}
}
else
{
MessageBox.Show($@"Encountered issues {exception.Message}");
}
This is a homebrewed logging class and there are many loggers on the web, this one keeps things simple that knows were the exception was but not the line number. I keped it simple on purpose.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace HandleExceptionsSimple
{
public static class Logger
{
private static TextWriterTraceListener _textWriterTraceListener;
public static void CreateLog()
{
_textWriterTraceListener = new TextWriterTraceListener(
"applicationLog.txt",
"PayneListener");
Trace.Listeners.Add(_textWriterTraceListener);
}
public static void Close()
{
_textWriterTraceListener.Flush();
}
public static void Exception(string message, [CallerMemberName] string callerName = null) =>
WriteEntry(message, "error", callerName);
public static void Exception(Exception ex, [CallerMemberName] string callerName = null) =>
WriteEntry(ex.Message, "error", callerName);
public static void Warning(string message, [CallerMemberName] string callerName = null) =>
WriteEntry(message, "warning", callerName);
public static void Info(string message, [CallerMemberName] string callerName = null) =>
WriteEntry(message, "info", callerName);
public static void EmptyLine() => _textWriterTraceListener.WriteLine("");
private static void WriteEntry(string message, string type, string callerName)
{
_textWriterTraceListener.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss},{type},{callerName},{message}");
}
}
}
Usage
try
{
var fileContents = File.ReadAllLines("NonExistingFile.txt");
}
catch (Exception exception)
{
Logger.Exception(exception);
Logger.Close();
}
Then there is global unhandled exception handling, see my NuGet package where documentation is under Prerequires.