Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error Calling OnAccountItemUpdate()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Error Calling OnAccountItemUpdate()

    Click image for larger version

Name:	Screenshot 2024-01-10 202033.png
Views:	186
Size:	336.6 KB
ID:	1285888 Click image for larger version

Name:	Screenshot 2024-01-10 211155.png
Views:	118
Size:	27.1 KB
ID:	1285889 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!

    #2
    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.

    Comment


      #3
      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


        #4
        Originally posted by HappyTrader76 View Post
        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!
        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:


        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


          #5
          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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          90 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          137 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          68 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          120 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          72 views
          0 likes
          Last Post PaulMohn  
          Working...
          X