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 AaronKoRn, Yesterday, 09:49 PM
          1 response
          18 views
          0 likes
          Last Post Rikazkhan007  
          Started by ageeholdings, Today, 07:43 AM
          0 responses
          12 views
          0 likes
          Last Post ageeholdings  
          Started by pibrew, Today, 06:37 AM
          0 responses
          4 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by rbeckmann05, Yesterday, 06:48 PM
          1 response
          14 views
          0 likes
          Last Post bltdavid  
          Started by llanqui, Today, 03:53 AM
          0 responses
          9 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Working...
          X