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

Latency when get Account item in indicator

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

    Latency when get Account item in indicator

    Dear Support,

    I have an indicator that is set on Calculate.OnEachTick.

    in OnBarUpdate() I get the account item and there are no problems, values are all correct, then I render on chart in OnRender (All work well).

    But I noted a little delay comparing it to P&L in the account tab of Ninjatrader, with this volatility is not good (they are not in sync).

    What's the way to print (or render on chart) the P&L values as quickly as possible?

    thank you, best regards

    AndreaBhs

    #2
    Hello AndreaBhs, thanks for your post.

    The fastest way to get an update would be to use the AccountItemUpdate event method:

    https://ninjatrader.com/support/help...itemupdate.htm

    That event will trigger the exact moment any account item changes.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris, thanks for your reply.

      I tried using AccountItemUpdate, but I noted that the delay still remain (maybe a little better, but I don't know...)
      However, Before I did a mistake, also the P&L in the account tab is delayed as my indicator.

      I would update onRender fast as the P&L on Chart Trader .

      As you can see in the image below, Both my indicator and the account tab are wrong, they show 210 $.
      But Chart Trader show 255 $ (that is correct)

      Click image for larger version

Name:	Immagine 2021-03-04 190354.png
Views:	383
Size:	101.6 KB
ID:	1144922

      Is there a way to have in my indicator the same speed of the P&L in the chart trader?

      thanks, regards

      AndreaBhs


      Comment


        #4
        Hello AndreaBhs,

        Thanks for your message.

        Please note that charts update visually on a 250ms interval. OnAccountItemUpdate would get you the most recent AccountItem value, as soon as the AccountItem is updated.

        If you print out the value from OnAccountItemUpdate in the output window, you will see the most recent price level there.

        We do not offer a supported means to change a chart's visual update interval as frequent re-renders of the chart can cause a performance impact.

        Please let us know if there is anything else we can do to help.

        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          So, I tried this indicator in NinjaTrader EcoSystem: TickRefresh | NinjaTrader Ecosystem

          This work well on chart updates . Price Marker and indicators as VOL are updated quickly than a normal chart, and there are no problem with CPU or GPU usage.
          As you can see in the image below, to the left is normal chart (250ms refresh), and to the right is a chart with a refresh of 1ms.
          So, this indicator work correctly.

          Click image for larger version

Name:	TICKREFRESH.png
Views:	379
Size:	30.5 KB
ID:	1145032

          But, if I apply this indicator to my chart to show P&L, this is lagged.

          So, my question is: What type of logic uses the Chart Trader To show P&L? Because also in the Account Tab of Control Center of Ninjatrader P&L is lagged.

          I need to render on a chart the P&L value in REAL TIME as Chart Trader Show, not lagged.

          I tried to print in OutPut window, same delay.

          I think the problem is not the refresh rate, but the method used to get P&L of a position. Why Chart Trader is in Real Time and I can't render as the same speed?

          If you need, I can post my code

          thank you for your support, best regards

          AndreaBhs


          Comment


            #6
            I did other test.

            In OnRender function, if I draw a string of Close[0] this is shown in real time, with no delay.
            In the same indicator, if I draw a string of UnrealizedProfitLoss this is not shown in realt time, there is a delay.
            The delay is greater than 250ms, also 1 second (a difference of 40 - 60 - 80 dollars with this volatiliy...)

            So, I think problems are both the two methods:

            1 OnAccountItemUpdate
            2 Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar);

            I think that I need to get the P&L from my position, not form Account item.

            It's not a refresh problem

            Comment


              #7
              Hello AndreaBhs,

              Thanks for the detail.

              Please note that while you may have decent performance while testing the Tick Refresh indicator, moments of higher volatility will cause the chart to re-render much more frequently and lagging symptoms can be encountered.

              I have a Position Display Indicator on the User App Share that uses Position.GetUnrealizedProfitLoss in OnRender. This may not be lock step with Chart Trader but it provides the calculation of Unrealized PnL for the position with every render pass. This sounds like what you are trying to achieve.

              This indicator provides a customizable text box which displays a position’s UnRealized PnL, Realized PnL of a selected account, and the overall cash value of the account.


              The link above is publicly available.

              The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.


              We look forward to assisting.
              JimNinjaTrader Customer Service

              Comment


                #8
                Dear Jim,
                thanks for your reply.

                I will test your method and I will let you know!

                Best regards

                AndreaBhs

                Comment


                  #9
                  Jim you saved me!!!!

                  Your indicator is perfect, I have implemented your code in my indicator, now it is very fast!

                  With a frame rate of 25ms (only on this chart) it is faster then Chart Trader now!!!

                  Thank you very much for your help

                  best regards

                  AndreaBhs

                  Comment


                    #10
                    Dear Jim,
                    I noted an issue with the unrealized profit.

                    While using "Sim101" account all work well, when using another account the indicator continues to calculate the unrealized profit / loss.

                    See below image: UnRealized PnL is 2,00 $ (Correct)

                    Click image for larger version  Name:	postionopen.png Views:	0 Size:	21.2 KB ID:	1145400

                    But when my target is trigger Unrealized PnL is still shown (9,50 $)

                    Click image for larger version  Name:	postionclose.png Views:	0 Size:	23.7 KB ID:	1145401

                    The strange thing is that on "Sim101" Account there isn't this problem, this appear on other account (I tested DEMONTXXXX) that was created by Ninja Lifetime version.
                    Also OneUp Trader account has the same problem.

                    I tried to Print in Ninjascript Output this in your script:

                    Code:
                    private void OnPositionUpdate(object sender, PositionEventArgs e)
                    {
                       if (e.MarketPosition == MarketPosition.Flat)
                       {
                          position = null;
                          Print(position.MarketPosition.ToString());
                       }
                    
                       else if (e.MarketPosition != MarketPosition.Flat)
                       {
                          position = e.Position;
                          Print(position.MarketPosition.ToString());
                       }
                    }
                    And I get this:

                    1) For Sim101 account: MarketPosition show short (or long) when I open a trade, but when I close it in the output nothing happen (I think that it would show "Flat". So output when I close is wrong, but indicator work properly.

                    2) For others account: MarketPoition show short (or long) twice time, when I open a trade e when I close it (instead of "flat"). So output is wrong and also the indicator

                    Can you help me?

                    Thank you, best regards
                    Last edited by AndreaBhs; 03-08-2021, 06:16 AM.

                    Comment


                      #11
                      I did other investigation:

                      OnPositionUpdate - MarketPosition.Flat works only on SIM - NinjaTrader Support Forum

                      In the link above the same problem.

                      I send all my order by clicking the "BUY MKT" button on chart trader.
                      Stop loss (stop order) and profit target (limit order) are placed by an atm strategy.
                      I use different ATM strategy during my trades.
                      Sometimes I close my order manually by clicking the "CLOSE" button on chart trader.

                      Errors occur also if I place an order with ATM strategy section ---> "NONE"

                      I don't understand why this method is ok on SIM101 account and not in the others.

                      If it's a problem of ATM strategy why UnrealizedPnL is ok when I'm long or short but not when I'm flat?

                      PS.: I need to get unrealized P&L in a indicator, not in a strategy
                      Last edited by AndreaBhs; 03-08-2021, 06:09 AM.

                      Comment


                        #12
                        Dear Support,

                        any advice about above post?

                        thank you, best regards

                        AndreaBhs

                        Comment


                          #13
                          Hello AndreaBhs,

                          Our regular support hours are 8:30am to 6pm US Eastern, Monday through Friday. Please allow us some time to assist other clients and return to open tickets.

                          With regards to the Position update not showing when returning flat on Rithmic based connections, this has been reported and fixed in the next release of NinjaTrader 8. Ticket ID NTEIGHT-14707.

                          The number for the ticket ID will be listed in the Release Notes page of the Help Guide when Release 24 becomes available. I cannot offer an ETA, but this update should be available soon.

                          Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

                          I have just tested our internal build and was seeing PositionUpdates I would expect with NinjaTrasder Continuum accounts, Rithmic/Rithmic for NinjaTrader Brokerage accounts, and Sim accounts.

                          I look forward to assisting.
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            Hi Jim, very thank you for your reply, and sorry if i solicited too soon

                            I will wait for the Release 24 update

                            Best regards,

                            AndreaBhs

                            Comment


                              #15
                              Dear Jim,

                              I confirm that with release 24 the problem has been solved.

                              Now also with Rithmic based connections the Position update showing when returning flat.

                              Thank you!

                              Best Regards

                              Andrea Bhs

                              Originally posted by NinjaTrader_Jim View Post
                              Hello AndreaBhs,

                              Our regular support hours are 8:30am to 6pm US Eastern, Monday through Friday. Please allow us some time to assist other clients and return to open tickets.

                              With regards to the Position update not showing when returning flat on Rithmic based connections, this has been reported and fixed in the next release of NinjaTrader 8. Ticket ID NTEIGHT-14707.

                              The number for the ticket ID will be listed in the Release Notes page of the Help Guide when Release 24 becomes available. I cannot offer an ETA, but this update should be available soon.

                              Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

                              I have just tested our internal build and was seeing PositionUpdates I would expect with NinjaTrasder Continuum accounts, Rithmic/Rithmic for NinjaTrader Brokerage accounts, and Sim accounts.

                              I look forward to assisting.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mestor, 03-10-2023, 01:50 AM
                              15 responses
                              378 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by samish18, Yesterday, 08:57 AM
                              10 responses
                              27 views
                              0 likes
                              Last Post samish18  
                              Started by matty89, 03-02-2020, 08:31 AM
                              34 responses
                              3,039 views
                              1 like
                              Last Post NinjaTrader_BrandonH  
                              Started by kujista, Today, 05:44 AM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by samish18, Today, 08:31 AM
                              0 responses
                              0 views
                              0 likes
                              Last Post samish18  
                              Working...
                              X