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!
See more
See less

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:	80
Size:	336.6 KB
ID:	1285888 Click image for larger version

Name:	Screenshot 2024-01-10 211155.png
Views:	51
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.
    Emily C.NinjaTrader Customer Service

    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.
        Emily C.NinjaTrader Customer Service

        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 futtrader, 04-21-2024, 01:50 AM
          4 responses
          41 views
          0 likes
          Last Post futtrader  
          Started by Option Whisperer, Today, 09:55 AM
          1 response
          11 views
          0 likes
          Last Post bltdavid  
          Started by port119, Today, 02:43 PM
          0 responses
          7 views
          0 likes
          Last Post port119
          by port119
           
          Started by Philippe56140, Today, 02:35 PM
          0 responses
          7 views
          0 likes
          Last Post Philippe56140  
          Started by 00nevest, Today, 02:27 PM
          0 responses
          7 views
          0 likes
          Last Post 00nevest  
          Working...
          X