Announcement
Collapse
No announcement yet.
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.
-
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
-
On the note of OnBarClose vs. OnPriceChange/OnEachTick, you can have your calculation set to either OnPriceChange or OnEachTick if you'd like and still filter certain logic to process on the close of a bar using a check for if IsFirstTickOfBar is true or not: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.
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 NullPointStrategies, Today, 05:17 AM
|
0 responses
44 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment