Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I see the Account Maximum Unrealized Balance & Minimum Unrealized Balance?

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

    How can I see the Account Maximum Unrealized Balance & Minimum Unrealized Balance?

    Hello

    I would like to know if is there a quick way to see the Maximum Unrealized Account Balance and also the Minimum Unrealized Account Balance during a multiple-positions trade. I mean a trade with multiple long and short positions all them as a whole, as 1 single trade, so it can be considered as a portfolio trade.

    I don't know if could be a built-in NT8 feature to see this, or maybe an indicator or Add-On to see these 2 values and also the Account Balance at the close of that trade, or if maybe these can be shown in the NT8 main Control Center.

    Let's say for example:
    - Your Account Balance before to start a trade is $1,000.
    - Then you open a trade, and while the trade is open the Balance reached $1,200 as Maximum Favorable Balance Excursion and also the Balance reached $800 as Maximum Adverse Balance Excursion.
    - Finally the trade was closed at $1,100 Account Balance


    So, what I need is a way to see these 3 statistics values, ideally in a quick visual way.


    Thank you
    Last edited by futurenow; 02-11-2021, 11:06 AM.

    #2
    Hello futurenow,

    While NinjaTrader's Trade Performance window is capable of calculating a variety of statistics (a full list may be found at https://ninjatrader.com/support/help...efinitions.htm), the platform would not be able to calculate these values on the fly or on a historical level.

    The reason for this is how this would require the trade to be assessed over the whole duration and compared against the highest/lowest tick that occurred during the time it was open, before calculating both values.

    While this would be something that could be developed as an add-on, we are not aware of it existing at this time.

    If you are interested in learning more about potentially programming this add-on, please don't hesitate to let me know. I would be happy to forward this to our NinjaScript Team to have a second look at.
    Manfred F.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Manfred View Post
      Hello futurenow,

      While NinjaTrader's Trade Performance window is capable of calculating a variety of statistics (a full list may be found at https://ninjatrader.com/support/help...efinitions.htm), the platform would not be able to calculate these values on the fly or on a historical level.

      The reason for this is how this would require the trade to be assessed over the whole duration and compared against the highest/lowest tick that occurred during the time it was open, before calculating both values.

      While this would be something that could be developed as an add-on, we are not aware of it existing at this time.

      Thank you for the fast response

      Yes, I've been checking the NinjaTrader's Trade Performance window and it doesn't show the statistics values I mention above, it shows the MAE, the MFE, the ETD and Drawdown but any of them show what I need because they are mainly based on long or short positions but not based on all positions seen as a whole, as a portfolio that is specifically what I need.


      Originally posted by NinjaTrader_Manfred View Post
      If you are interested in learning more about potentially programming this add-on, please don't hesitate to let me know. I would be happy to forward this to our NinjaScript Team to have a second look at.
      Yes, I would like to learn how to programing and see these values, ideally to see them running in real-time while a trade is open, exactly as the NT8 Control Center Accounts tab shows the Unrealized and the PnL values, running tick-by-tick in real-time either with a Live, Demo, Simulated or Market Replay trade. Soemthing like this would be perfect, so being able to see what I need maybe in any chart or maybe in the main NT8 Control Center window as an extra tab as shown in the attached picture.

      I have a very very basic programming basis but I've never programed an indicator, so any video or tutorial would help, hoping it directly goes to the part where I can start to develop something like this and not to have to spend 1 week learning every small detail to then start with.

      Thank you very much


      Attached Files

      Comment


        #4
        Hello futurenow, thanks for your post.

        An Addon can be created to read all executions occurring on a selected account. As far as what the addon does with the provided account data is entirely customizable and flexible since it is built from the ground up. We have an example addon demonstrating some capabilities of an addon (including reading account data). Please install the sample addon linked on this help guide page to study the source code:

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

        Please let me know if you have any questions about this material.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello futurenow, I am replying to this forum post in your request for more information here:

          https://ninjatrader.com/support/foru...rt#post1141435

          I will prove further direction into what the requirements will be but note that the scripting support team will not be able to spend time designing or developing custom addons or indicators. If further help is needed, a NinjaScript consultant may be hired from the NinjaTrader Ecosystem to develop the script in its entirety.

          Since you want an Indicator like PositionDisplay indicator, you would not need to make a full addon with its own window, an Account object can be set up from within an indicator just as the PositionDisplay indicator does. e.g.

          lock (Account.All)
          account = Account.All.FirstOrDefault(a => a.Name == AccountName);

          From there, update events are subscribed to where the account data will be updated:
          account.AccountItemUpdate += OnAccountItemUpdate;

          For the account overall unrealized PnL, you would get the AccountItem.UnrealizedProfitLoss. See all of the account items that get updated in this event here, there is a lot of data that can be accessed from this event:

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

          To get an AccountItem at any time (not only when it updates), you may use the Account.Get(AccountItem) method to get any account item.

          Please let me know if you have any questions about this material.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChrisL View Post
            Hello futurenow, I am replying to this forum post in your request for more information here:

            https://ninjatrader.com/support/foru...rt#post1141435

            I will prove further direction into what the requirements will be but note that the scripting support team will not be able to spend time designing or developing custom addons or indicators. If further help is needed, a NinjaScript consultant may be hired from the NinjaTrader Ecosystem to develop the script in its entirety.

            Since you want an Indicator like PositionDisplay indicator, you would not need to make a full addon with its own window, an Account object can be set up from within an indicator just as the PositionDisplay indicator does. e.g.

            lock (Account.All)
            account = Account.All.FirstOrDefault(a => a.Name == AccountName);

            From there, update events are subscribed to where the account data will be updated:
            account.AccountItemUpdate += OnAccountItemUpdate;

            For the account overall unrealized PnL, you would get the AccountItem.UnrealizedProfitLoss. See all of the account items that get updated in this event here, there is a lot of data that can be accessed from this event:

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

            To get an AccountItem at any time (not only when it updates), you may use the Account.Get(AccountItem) method to get any account item.

            Please let me know if you have any questions about this material.

            Thank you for the assistance and for the information

            I can't find the right logic make the necessary comparisons that calculates the values I need, doing it in an efficient way.

            Could you please paste here in the next response the necessary code to make the calculations of the 3 values I need, and in that way I can continue adding those code portions into a new indicator development.

            I mean, what would be the calculations to tell indicator that calculates the next 3 values and show them into the chart text box?

            - the Account Maximum Unrealized Balance
            - the Account Minimum Unrealized Balance
            - the Account Balance when a trade is closed

            Also, as I see the Position Display Indicator is created directly by NinjaTrader team, could be possible to get its development code template to modify it with want I need and in that way I could make those modifications starting from a good point. It would be very helpful, because I see it shows one of the 3 values I need as shown in the attached picture.

            Thank you


            Attached Files

            Comment


              #7
              Hello futurenow, thanks for your reply.

              For Account Maximum Unrealized Balance, that sounds something like AccountItem.CashValue + AccountItem.UnrealizedPnL, and this would change over time, so you would record and update the highest value of this calculation as time goes on.

              For the account balance when the trade is closed, that will be reflected in AccountItem.CashValue.

              Our Scripting Support team's goal is to provide insight and direction for accomplishing your goals and to educate you on how you can take debugging steps with NinjaScript to check your work. If you are looking for services to have code written for you, this would be a task better suited for a NinjaScript Consultant in the NinjaTrader Ecosystem. If you are interested in those services, please let me know.

              The Position Display Indicator is open source and you can view the source code in the NinjaScript Editor after importing the indicator. If you have questions about the code inside, please let us know.

              Best regards.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChrisL View Post
                For the account balance when the trade is closed, that will be reflected in AccountItem.CashValue.
                Thank you, this work to get Account Balance closed at the last closed trade.

                Originally posted by NinjaTrader_ChrisL View Post
                For Account Maximum Unrealized Balance, that sounds something like AccountItem.CashValue + AccountItem.UnrealizedPnL, and this would change over time, so you would record and update the highest value of this calculation as time goes on.
                To know the Maximum Unrealized Account Balance and the Minimum Unrealized Account Balance I'm using the next portion of code into Position Display Indicator:

                Code:
                ...
                And it is working, but when for any reason you need to do any kind of indicator settings chage or something similar, any small change, then the indicator restarts to the initial Max and Min values to "0", so it is not a effcient way to get these 2 values I need.

                Please, I need you ask to your work colleagues about a way to get these 2 values in another way, I don't know, maybe extracted from the account log information or something similar, because there must be a way to obtain these 2 values from a more direct source like the one I'm using that is simply based in actual information and not in historical information that is exactly what I'm needing.


                Originally posted by NinjaTrader_ChrisL View Post
                For Account Maximum Unrealized Balance, that sounds something like AccountItem.CashValue + AccountItem.UnrealizedPnL, and this would change over time, so you would record and update the highest value of this calculation as time goes on.
                The way you suggest ""AccountItem.CashValue + AccountItem.UnrealizedPnL", it will just give the exact same result as what NetLiquidation shows in the NT8 Control Center because it is the Account Balance closed at the last trade + the current Unrealized PnL, what is the exact definiton of what NT8 call to "NetLiquidation" and what I need is not that because it is already given as an "AccountItem", so please try to scale this and see the correct and accurate way to get these 2 values: Maximum Unrealized Account Balance and the Minimum Unrealized Account Balance.
                Last edited by futurenow; 02-18-2021, 08:43 PM.

                Comment


                  #9
                  Hello futurenow, thanks for your reply.

                  There is no fundamental value that will give you Maximum Unrealized Account Balance and the Minimum Unrealized Account Balance. This must be calculated manually in your script with the Account information that is provided in the Account class. I'm sorry but I have already given you all the examples and information that I possibly could. If you do not know how to calculate this or use the Account class, you will need to hire a NinjaScript consultant and describe the exact specification for the indicator.

                  Best regards,

                  -ChrisL
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChrisL View Post
                    Hello futurenow, thanks for your reply.

                    There is no fundamental value that will give you Maximum Unrealized Account Balance and the Minimum Unrealized Account Balance. This must be calculated manually in your script with the Account information that is provided in the Account class. I'm sorry but I have already given you all the examples and information that I possibly could. If you do not know how to calculate this or use the Account class, you will need to hire a NinjaScript consultant and describe the exact specification for the indicator.

                    Best regards,
                    -ChrisL
                    Your answer could simply be "I did a brief reseach here in the office and I can confirm there is no fundamental value that will give you Maximum Unrealized Account Balance and the Minimum Unrealized Account Balance" that would have been a possitive answer, instead of repeat, repeat and keep repeating the same about to go "...to hire a NinjaScript consultant and describe the exact specification for the indicator", because you clearly see I'm telling I'm using a way to get the values but maybe is not the more sophisticated way, but after all, a way that is clearly written in the previous reply, so I don't see the need to to say "If you do not know how to calculate this..."

                    I see in others posts your work colleagues do not hesitate to put any code suggestion, any code improve for more a more effcient code or logic, any possitive coment, or any in general, intead to write answers ending in "you may see to go to a consultant", "you may see to go to a consultant", "you may see to go to a consultant".

                    I thank to all the NinjaTrader reps that have responded in the posts but when as in this case, a user is finally progressing and getting results in a goal, I don't see any kind of need to respond in the way you did. So sorry but is what I think.

                    Comment


                      #11
                      Hello futurenow,

                      This is Chelsea the Scripting Support Lead Hand here at NinjaTrader.

                      We do appreciate your patience and we are happy to continue providing any assistance we are able.

                      As a heads up, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support over the phone in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                      That said, we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.


                      Our team does provide examples where appropriate, and when there is a suitable existing example we can provide. Typically, we do not provide anything that requires custom calculations or logic at request. We do often provide examples where custom calculations are not involved, to demonstrate code from the help guide or to convey an idea of how to use a documented tool.


                      To address you directly, I have double checked that the AccountItems and FundamentalData arguments have not changed in the help guide. Unfortunately, a Maximum Unrealized Balance & Minimum Unrealized Balance are not available AccountItems that can be retrieved in a NinjaScript. Only the AccountItems documented in the help guide will be supported items that can be retrieved in a NinjaScript.

                      If you have confirmed the API of the connection type you have has this available, I will be happy to submit a feature request for the NinjaTrader Development team to consider creating an AccountItem for these values available in the API.

                      Where you have mentioned:
                      "I can't find the right logic make the necessary comparisons that calculates the values I need, doing it in an efficient way."

                      ChrisL is providing you with correct information. It will be outside of the scope our support team to create this custom logic for you.
                      This thread will remain open for any community members that would like to develop this custom logic as a convenience to you.

                      You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.


                      With that above said as a disclaimer about the expectations of the Scripting Support staff, we would like to offer any assistance we are able, to get you on the path to succeeding at your goal.
                      Where are you getting stuck in your custom logic?

                      Are you saving these values to a text file or a collection as they are changing so that you are recording every change of these values to a resource outside of the script?
                      Is this from an <Account>.AccountItemUpdate event?
                      How are you saving these values?
                      Last edited by NinjaTrader_ChelseaB; 02-18-2021, 04:53 PM.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you very much for your reply Chelsea

                        Originally posted by NinjaTrader_ChelseaB View Post
                        To address you directly, I have double checked that the AccountItems and FundamentalData arguments have not changed in the help guide. Unfortunately, a Maximum Unrealized Balance & Minimum Unrealized Balance are not available AccountItems that can be retrieved in a NinjaScript. Only the AccountItems documented in the help guide will be supported items that can be retrieved in a NinjaScript.

                        If you have confirmed the API of the connection type you have has this available, I will be happy to submit a feature request for the NinjaTrader Development team to consider creating an AccountItem for these values available in the API.
                        I haven't confirmed this because I'm not sure yet about what data-feed provider use, but I think it could added as a internal NT8 feature that be independent of the API connection, because in this case we are talking about just 2 simple variables that can be stored and they will require just 2 double variable type of storage space, ideally in the server side, so it won't be a heavy process at all, it would be extremely light in terms of process and storage. So yes, I would like you submit a feature request to have access to the historical Maximum Unrealized Balance & Minimum Unrealized Balance that could be taken from the Net Liquidation and stored, and to be available either if you restart the platform, or if work in another computer etc. so in case Ninja decide not put this feature as a server side, then it could be backup to pass the information to other PC, just as an example.


                        With that above said as a disclaimer about the expectations of the Scripting Support staff, we would like to offer any assistance we are able, to get you on the path to succeeding at your goal.

                        Where are you getting stuck in your custom logic?
                        Thank you for this, I hope you could help me in the next in averyting you can.

                        Actually I have been successfully customized the Position Display Indicator (NT8) (https://ninjatraderecosystem.com/use...lay-indicator/) to do several extra calculations in addition to those it has by default, using 'AccountItem' sources and more, to then display some variables results in a chart textbox, showing some variables values I need to be aware how the trading process goes, so yes, the main core part of the indicator purpose is already done, and there are only 2 more features I'm needing but I haven't been able get them working and displaying. These 2 features I need are the next:
                        • The feature #1 is I need that when a condition is met, then the Position Display Indicator calculates and displays in its textbox the next:
                        - The specific time and date of the event. For Live, Demo or Simulated this will be the current calendar date and time, but for Playback it will be the date of the Market Replay moment the event happened, for example, if today Feb 24, 2021 you run a Market Replay from Jan 11, 2021 and the event happened that day at 10:45:03 am, then the time and date to be displayed need to be the one of that past day that is the date and time showed in the Playback small control floating window, to show it into the indicartor's textbox as a message like the next:
                        "The strategy has failed to meet the minimum necessary requirements at 10:45:03 am, on Jan 11, 2021"

                        - if not, then would be visually useful to have a permanent message, until the opposite event, like:
                        "The strategy is currently in positive territory, you can continue trading"

                        For this I've tried something variations of the next but not positive results for now:




                        Code:
                        // simplified code portion with '...' where extra code is needed but not written to not to have a very large message because this is already in the [B]Position Display Indicator[/B]
                        ...
                        private double NetLiquidation;
                        private double FailureLevel = 500;
                        private DateTime time&date_ofFailureLevel;
                        ...
                        if (NetLiquidation =< FailureLevel)
                        {
                            // time&date_ofFailureLevel = [B][COLOR=#e67e22]code_to_get_time_of_the_event;[/COLOR][/B]
                            ...
                            string label = "[B]Strategy progress status[/B]:" +"\n\n"+
                            ...
                            // the next would be the idea to print the message "[COLOR=#c0392b]The strategy has failed to meet the minimum necessary requirements at[B] hh:mm:mm a/pm[/B], on [B]Mmm DD, YYYY[/B][/COLOR]"
                            "[COLOR=#c0392b]The strategy has failed to meet the minimum necessary requirements at[/COLOR]"+ string time&date_ofFailureLevelstring = time&date_ofFailureLevel.ToString("N2");
                            ...
                            DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, time&date_ofFailureLevelstring, Font, time&date_ofFailureLevel < 0 ? negativeBrush : positiveBrush);
                        }
                        
                        else
                        {
                            string label = "[B]Strategy progress status[/B]:" +"\n\n"+
                            ...
                            // permanent print the message "[COLOR=#27ae60][B]The strategy is currently in positive territory, you can continue trading[/B][/COLOR]" //while NetLiquidation > 500.00 in this example.
                        }
                        ...
                        • About the The feature #2 is even a more easy logic than the #1 and I'm currently working in a possible solution, but if get stuck I could message here about that.

                        With these 2 features I will have the main and most important features I need that as you can see are not fancy or complicated processes.


                        Are you saving these values to a text file or a collection as they are changing so that you are recording every change of these values to a resource outside of the script?
                        Is this from an <Account>.AccountItemUpdate event?
                        How are you saving these values?
                        About this, I'm not saving the variable values in text file or anything similar export process, actually, the value is held in the same variable until any change that meets with the condition criteria. So for example, if the variable minNet_Liquidation is currently = 720 and then the account get a new Net Liquidation minimum value like 710, then it will simply updates its value having and displaying 710 and done.

                        I'm working these Net Liquidation calculations in the next way:
                        Code:
                        else if (State == State.DataLoaded)
                            ...
                            Net_Liquidation = account.Get([B]AccountItem.NetLiquidation[/B], Currency.UsDollar);
                            ...
                            maxNet_Liquidation = [B]Math.Max[/B](maxNet_Liquidation, Net_Liquidation);     // maxNet_Liquidation with a preset initial value
                            minNet_Liquidation = [B]Math.Min[/B](minNet_Liquidation, Net_Liquidation);        // minNet_Liquidation with a preset initial value
                            ...
                        Finally I specify below to display the 3 variables: Net_Liquidation, maxNet_Liquidation, minNet_Liquidation into the indicator textbox and done, but as actualy I'm in the development process to continue customizing the indicator, when I'm running a Market Replay, everytime I make an update into the indicator code, when the indicartor get refreshed then it reset the 2 custom variables values I've added in this section: maxNet_Liquidation and minNet_Liquidation, so it would helpful to have a patch way to "solve" this.

                        I don't know how to export and save these values into a text file like a .txt mainly because I haven't needed to do that for the moment, but now you mention this about to save these values I'm wondering if would be useful to save them in any way, that I think it would be a trivial process.

                        Thank you very much for all Chelsea. I hope you can help me with these that for you maybe it means 5 minutes but for me it could mean 1 or 2 days, and that if I find the way about how to do it. I know I can get this done with someone, but now I'm having a real progress I would like to learn how to finish the rest, because I've been able to put to work the core part, obtaining the main calculations and displaying them in a textbox into any chart I need, so with some extra code I will be ready.
                        Last edited by futurenow; 02-24-2021, 12:19 PM.

                        Comment


                          #13
                          Hello futurenow,

                          I have submitted a feature request to have Maximum Unrealized Balance & Minimum Unrealized Balance tracked and so they can be referenced historically. We will update this post with a feature request ticket ID as it becomes available. EDIT: Your feedback is tracked in the ticket ID SFT-620.

                          Please note that feature request interest is tracked and weighed against the feasibility of a feature before implementation is considered. We cannot offer an ETA or a promise of fulfillment. Features that are implemented are noted in the release notes page of the Help Guide.

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

                          I do want to mention that NetLiquidation is received for specific connections: CQG, Continuum, Interactive Brokers and Sim accounts. You can reference the Accounts tab documentation to see which connections support which AccountItems.

                          https://ninjatrader.com/support/help...TheAccountsTab

                          To pick up on the current time in NinjaScript, you could do the following. Please note that Cbi.Connection.PlaybackConnection.Now is used to get the current Market Replay time.

                          Code:
                          if (Account.Connection.Options.Name == "Playback Connection")
                              Print(NinjaTrader.Cbi.Connection.PlaybackConnection.Now);
                          else
                              Print(DateTime.Now);
                          You can consider writing your values to a file and fetching those values when the script transitions to State.Realtime in OnStateChange so previous values can be retrieved after reloading the script. some examples that describe using a StreamReader and a StreamWriter to write to file can be found below.

                          Using a StreamReader - https://ninjatrader.com/support/help...o_read_fro.htm

                          Using a StreamWriter - https://ninjatrader.com/support/help...o_write_to.htm

                          We look forward to assisting.
                          Last edited by NinjaTrader_Jim; 03-03-2021, 04:06 PM.
                          JimNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by wzgy0920, 04-20-2024, 06:09 PM
                          2 responses
                          26 views
                          0 likes
                          Last Post wzgy0920  
                          Started by wzgy0920, 02-22-2024, 01:11 AM
                          5 responses
                          32 views
                          0 likes
                          Last Post wzgy0920  
                          Started by wzgy0920, Yesterday, 09:53 PM
                          2 responses
                          49 views
                          0 likes
                          Last Post wzgy0920  
                          Started by Kensonprib, 04-28-2021, 10:11 AM
                          5 responses
                          192 views
                          0 likes
                          Last Post Hasadafa  
                          Started by GussJ, 03-04-2020, 03:11 PM
                          11 responses
                          3,234 views
                          0 likes
                          Last Post xiinteractive  
                          Working...
                          X