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
Error Calling OnAccountItemUpdate()
Collapse
X
-
Error Calling OnAccountItemUpdate()
I have a strategy that calculates OnBarUpdate() and I use OnAccountItemUpdate() to show the PnL (realized + unrealized) on the chart. To draw on the chart I use Draw.TextFixed. When I run the strategy it usally works just fine but sometimes throws an Error Message: Error on calling "OnAccountItemUpdate" "Index was outside the bounds of the array". I assume that it has to do with mulithreading and I used a dispatcher but it still randomly produces this same error. I attached the strategy to Visual Studio and ran it in Debug Mode I attached the Screenshot of VS and a Screenshot of the affected FixedText with the tag "text_1". I just can't think of anything I could do still. Thank you for looking at it!Tags: None
-
Hello HappyTrader76,
Thank you for your note.
What is the result if you call Draw.TextFixed() within OnBarUpdate() rather than in OnAccountItemUpdate()? You could toggle a bool to determine if the text should be red or lime. Calling the Draw methods, such as Draw.TextFixed() is intended to be done via OnBarUpdate() so they are in sync with the bar indexes. This would allow the draw object to update with each call of OnBarUpdate(), which you could set to calculate OnPriceChange() to keep the PnL up-to-date with each change of price.
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
-
Thank you Emily for the quick response. The calculation mode is set to OnBarClose() because of the indicators I use and to avoid weird signals when Price closes above or below certain indicators. I'll give your tip a try and see what I can do. Thanks!
Comment
-
Originally posted by HappyTrader76 View PostThank you Emily for the quick response. The calculation mode is set to OnBarClose() because of the indicators I use and to avoid weird signals when Price closes above or below certain indicators. I'll give your tip a try and see what I can do. Thanks!
We also have a reference sample that demonstrates how to separate logic to process either on bar close or on each tick here:
Please don't hesitate to reach out with any additional questions or concerns.Emily C.NinjaTrader Customer Service
Comment
-
I found out that when I write the current PnL into a Button by changing Button.Content instead of Draw.TextFixed it works without any problems. Not exactly what I wanted but it works if I call the Button through ChartControl.Invoke Async... Problem solved.
Thank you for your help!
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by AaronKoRn, Yesterday, 09:49 PM
|
1 response
18 views
0 likes
|
Last Post
by Rikazkhan007
Today, 09:24 AM
|
||
Started by ageeholdings, Today, 07:43 AM
|
0 responses
12 views
0 likes
|
Last Post
by ageeholdings
Today, 07:43 AM
|
||
Started by pibrew, Today, 06:37 AM
|
0 responses
4 views
0 likes
|
Last Post
by pibrew
Today, 06:37 AM
|
||
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
14 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
9 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
Comment