"Error on calling 'OnStateChange' method: The calling thread cannot access this object because a different thread owns it."
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Error on calling 'OnStateChange' method
Collapse
X
-
Error on calling 'OnStateChange' method
I converted and successful compiled a NT7 indicator to NT8 but when I load it into my chart it generated the following error in the Log file ... what am I doing wrong;
"Error on calling 'OnStateChange' method: The calling thread cannot access this object because a different thread owns it."Tags: None
-
Thanks, Gaby.Originally posted by NinjaTrader_Gaby View PostHello omololu,
Thank you for your post.
What is the scripting trying to do, what code do you have?
Are you trying to launch a new thread or invoke into the UI thread? If so, Dispatcher.InvokeAsync() is used to invoke into another existing thread, such as the UI thread.
The "OnStateChange" portion of my scripts is as shown below ... the scripts is expected to pop up a window containing some trends details;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Plots the trend of moving averages in a linear display.";
Name = "MyTestIndicator Pop";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = false;
DrawOnPricePanel = false;
PaintPriceMarkers = false;
drawhistory = true;
historylength = 7;
historyScroll = false;
}
else if (State == State.Configure)
{
open = new Series<double>(this);
high = new Series<double>(this);
low = new Series<double>(this);
close = new Series<double>(this);
timestamp = new Series<int>(this);
Mopen = new List<double>();
Mhigh = new List<double>();
Mlow = new List<double>();
Mclose = new List<double>();
Mtimestamp = new List<int>();
candlecolor = new List<int>();
Maj = new List<int>();
MajPIR = new List<double>();
Min = new List<int>();
MinPIR = new List<double>();
}
else if (State == State.DataLoaded)
{
thisWindow.Title = Instrument.FullName + " MyTestIndicator Pop";
thisWindow.Width = 400;
thisWindow.Height = 140;
thisWindow.Show();
dialogOn = true;
}
Comment
-
Hello,
It's not clear from this code what could be causing the error. I suggest debugging the script by commenting out lines of code in your script until the error stops. Once the error stops, uncomment out the last line of code you commented out. Does the error return?
If so, that is the line of code causing the error. What is this line of code?
Comment
-
Hi Gaby,Originally posted by NinjaTrader_Gaby View PostHello,
It's not clear from this code what could be causing the error. I suggest debugging the script by commenting out lines of code in your script until the error stops. Once the error stops, uncomment out the last line of code you commented out. Does the error return?
If so, that is the line of code causing the error. What is this line of code?
I commented the following lines in my scripts and which resulted to NO error message in my Log file;
thisWindow.Title = Instrument.FullName + "
'MyTestIndicator Pop";
thisWindow.Width = 400;
thisWindow.Height = 140;
thisWindow.Show();
However, the indicator does still not plot.
Comment
-
Hi Gaby,Originally posted by NinjaTrader_Gaby View PostHello,
What is this code for? Are you creating your own window within the script?
If the indicator isn't plotting, you'll need to debug the script further to figure out why.
Yes, I'm creating a window pop up that contains some trend details.
omololu
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
558 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment