Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
"Unhandled exception: Write lock may not be acquired with read lock held"
Collapse
X
-
Originally posted by NinjaTrader_ChrisL View PostHi Bob, You can send an email to scriptingsupport at ninjatrader.com and include the file export. I will test it out on my side to see if I can reproduce this.
While I was exporting the scripts I noticed that the export engine was requesting a number of files that my strategy and indicator do not use.
I found that I had named a strategy as SWING.cs, the same as the indicator swing.cs.
I renamed the SWING strategy and excluded it from the compilation process.
Then I proceeded to create the export zip file again.
This time, only the required files were included as expected. So, I ran my strategy again and it has not frozen.
I'll let it run a while to see what happens before sending you the scripts, as the cause of the "unhandled exception..." error may have been contained.
Bob
- Likes 1
Comment
-
Originally posted by NinjaTrader_ChrisL View PostHi Bob, You can send an email to scriptingsupport at ninjatrader.com and include the file export. I will test it out on my side to see if I can reproduce this.
Bob
Comment
-
Hi Bruce! I recently upgraded to 8.0.28 and have been having this same write lock/freezing/deadlock issue. I THINK it's being caused by my Price Action Swing Pro indicator I downloaded from a forum. It was last updated 5.22.22 and worked perfectly fine before this forced upgrade for CQG users. Are you able to look at this code and pinpoint the issue? Is it a brush issue like the OP had? Everything worked fine before this update
This is one of the major indicators I use in my scalping strategy and the freezing issue has caused me to miss out on so much money this week smh.
Originally posted by QuantKey_Bruce View Postbobperez Regarding that snippet above, I don't like the look of that SetOpacity function - that seems like it is probably the problem. If what you are trying to do is have a color that's an input parameter, plus an opacity that is an input parameter, then in State.Configure or State.DataLoaded, you should create your new partially transparent brush ONE TIME there in OnStateChanged in the handler for that state and freeze it right then, and everywhere else in your code refer to that saved variable instance of the partially transparent brush. Don't do it in a setter, and don't do it a bunch of times. I know that might sound like voodoo, but if you do it the way I described you won't have to worry about all this and if you do it like I described you should be okay. If you want to "go crazy" and even make an array for every possible opacity you can do that and stick them all in an array in advance. But that's pretty wasteful of resources. Try to stick to a reasonable number of opacities.
A key problem you might not be realizing is you're doing that brush operation in OnBarUpdate, while the screen is being drawn in OnRender. Those run in different threads, AT THE SAME TIME. So, if you are changing the brushes around in OnBarUpdate, you're always flirting with doom. Make all the brushes you are going to ever need in OnStateChanged BEFORE OnBarUpdate ever starts running and BEFORE OnRender starts drawing the screen - then when OnRender refers to these brushes they're already frozen and they are not in the middle of being replaced or in some weird interim state such as they might be if OnRender runs while you're in the middle of updating them. I would recommend you also have a variable bool MyBrushesAreInitialized = false; and only set that to true after you've initialized them all in State.Configure or State.DataLoaded, and if you are doing any custom OnRender, at the top of that function add if (!MyBrushesAreInitialized) return; so you have no chance of working with partially initialized brushes. If you are not doing custom OnRender, just get all your brushes set up first in OnStateChanged and freeze them there. Don't change any brush instances in OnBarUpdate.
And don't listen to anything ChatGPT says about issues like this - it has no idea and just prints out things that sound good but lead you to waste tremendous amounts of time trying to figure out what's slightly wrong with what it said when the fact is what it said is completely ungrounded in reality. There's a reason we don't yet have ChatGPT flying commercial airliners or doing open heart surgery. A good number of such passengers and patients would be dead right away.
NinjaTrader_ChelseaB is absolutely correct that you shouldn't send "" for the symbol in AddDataSeries. You absolutely need to make that a null or you are asking for trouble.Attached Files
- Likes 1
Comment
-
No, that's more than I could take on in response to a public forum post because I'm heavily committed already. I did take a quick look and it uses WPF resources all over the place, but that does not mean it is doing anything wrong. Someone may be able to audit it - perhaps its original author could assure it is doing everything correctly or perhaps NinjaTrader Support could comment on what to look for with this particular issue.
- Likes 1
Comment
-
Understood. thank you
Originally posted by QuantKey_Bruce View PostNo, that's more than I could take on in response to a public forum post because I'm heavily committed already. I did take a quick look and it uses WPF resources all over the place, but that does not mean it is doing anything wrong. Someone may be able to audit it - perhaps its original author could assure it is doing everything correctly or perhaps NinjaTrader Support could comment on what to look for with this particular issue.
Comment
-
trader123456789, I get the same NT chart lock ups and error message sometimes during fast market times when charts are lagging. Maybe that is your case as well. To test if your charts are lagging when you get the error, go here and download and install the ChartLagTime indicator script. Next time you get the error and your charts freeze, see if you charts were lagging at that time. Might help troubleshooting.
Comment
-
Originally posted by QuantKey_Bruce View Postbobperez Regarding that snippet above, I don't like the look of that SetOpacity function - that seems like it is probably the problem. If what you are trying to do is have a color that's an input parameter, plus an opacity that is an input parameter, then in State.Configure or State.DataLoaded, you should create your new partially transparent brush ONE TIME there in OnStateChanged in the handler for that state and freeze it right then, and everywhere else in your code refer to that saved variable instance of the partially transparent brush. Don't do it in a setter, and don't do it a bunch of times. I know that might sound like voodoo, but if you do it the way I described you won't have to worry about all this and if you do it like I described you should be okay. If you want to "go crazy" and even make an array for every possible opacity you can do that and stick them all in an array in advance. But that's pretty wasteful of resources. Try to stick to a reasonable number of opacities.
A key problem you might not be realizing is you're doing that brush operation in OnBarUpdate, while the screen is being drawn in OnRender. Those run in different threads, AT THE SAME TIME. So, if you are changing the brushes around in OnBarUpdate, you're always flirting with doom. Make all the brushes you are going to ever need in OnStateChanged BEFORE OnBarUpdate ever starts running and BEFORE OnRender starts drawing the screen - then when OnRender refers to these brushes they're already frozen and they are not in the middle of being replaced or in some weird interim state such as they might be if OnRender runs while you're in the middle of updating them. I would recommend you also have a variable bool MyBrushesAreInitialized = false; and only set that to true after you've initialized them all in State.Configure or State.DataLoaded, and if you are doing any custom OnRender, at the top of that function add if (!MyBrushesAreInitialized) return; so you have no chance of working with partially initialized brushes. If you are not doing custom OnRender, just get all your brushes set up first in OnStateChanged and freeze them there. Don't change any brush instances in OnBarUpdate.
And don't listen to anything ChatGPT says about issues like this - it has no idea and just prints out things that sound good but lead you to waste tremendous amounts of time trying to figure out what's slightly wrong with what it said when the fact is what it said is completely ungrounded in reality. There's a reason we don't yet have ChatGPT flying commercial airliners or doing open heart surgery. A good number of such passengers and patients would be dead right away.
NinjaTrader_ChelseaB is absolutely correct that you shouldn't send "" for the symbol in AddDataSeries. You absolutely need to make that a null or you are asking for trouble.
Draw.Rectangle(this,"Box3"+CurrentBar,false, totalbars+1, Upperboundary,1,Lowerboundary, Brushes.Transparent, supplyColor, Opacity3);
So if I just remove the opacity input all together from script, then the opacity will default to 100 or do I need to just remove the inputs for the variable and state the opacity in the code here
ie
Draw.Rectangle(this,"Box3"+CurrentBar,false, totalbars+1, Upperboundary,1,Lowerboundary, Brushes.Transparent, supplyColor, 70);
or can i remove the Opacity3 all together and would the below be correct
Draw.Rectangle(this,"Box3"+CurrentBar,false, totalbars+1, Upperboundary,1,Lowerboundary, Brushes.Transparent, supplyColor);
Thanks for your feedback
DTS
Comment
-
If you're not doing custom OnRender, the advice above does not necessarily apply to your situation. I am not aware of a lock issue with the inbuilt drawing objects, but I am definitely aware of a lock issue regarding OnRender as described above which is what I was giving guidance how to avoid.
Comment
-
I did remove the variable inputs, but as you thought that was not my issue. I am pretty sure this indicator is likely my issue. I have used it for several years until the recent changes.
It has gotten to the point if I mouse over the chart for just a few seconds I get the Lock.Last edited by DTSSTS; 09-28-2023, 06:45 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by patrickmlee007, Today, 09:33 AM
|
2 responses
17 views
0 likes
|
Last Post Today, 08:56 PM | ||
Started by magnatauren, 08-15-2020, 02:12 PM
|
5 responses
206 views
0 likes
|
Last Post
by RaddiFX
Today, 08:46 PM
|
||
Started by rene69851, 05-02-2024, 03:25 PM
|
1 response
21 views
0 likes
|
Last Post
by rene69851
Today, 08:20 PM
|
||
Started by ETFVoyageur, Yesterday, 07:05 PM
|
5 responses
45 views
0 likes
|
Last Post
by ETFVoyageur
Today, 08:08 PM
|
||
Started by jpeep, 08-16-2020, 08:31 AM
|
13 responses
487 views
0 likes
|
Last Post
by notenufftime
Today, 07:39 PM
|
Comment