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

account size calculation

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

    account size calculation

    Hi,

    I'm playing around with the scripting and i'm looking for a solution:

    I want to devide my account with the current ask price.

    my code so far, but I'm not sure what to implement at the //do something part.
    {
    //Add your custom indicator logic here.
    if (GetAccountValue(AccountItem.CashValue) > 25000)
    {
    //Do SOmething

    }
    }
    }
    }

    #2
    Hello cube1984, and thank you for your question.

    This code will display your account's value divided by the last traded price to the Tools -> Output Window.

    Code:
    double value = GetAccountValue(AccountItem.CashValue) / Last[0];
    Print("The account value / last traded price = " + value);
    If this was not quite what you were asking, or if there are any other ways we can help, please let us know.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Dear,

      When I try to cmpline the code I get errors on the getaccount code

      thisis my code so far :

      {
      //Add your custom indicator logic here.
      if (GetAccountValue(AccountItem.CashValue) > 25000)
      {
      //Do SOmething
      double value = GetAccountValue(AccountItem.CashValue) / Last[0];
      Print("The account value / last traded price = " + value);
      }

      Comment


        #4
        Hello again cube1984,

        Would it be possible for you to send us the errors you are getting? Either paste the text into a reply, or take pictures?

        To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.
        Click here for instructions
        Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.
        Click here for detailed instruction
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          In attachement the error's
          Attached Files

          Comment


            #6
            It looks like the software didn't attach those for us. Would it be possible to e-mail them to platformsupport[at]ninjatrader[dot]com?

            • Please add this number somewhere in the body of your e-mail : 1555063
            • Please add "Attn : NinjaTrader_JessicaP" in the subject line
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Thank you, I am just letting you know that I have received your files. I will be following up shortly.
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Hello cube1984,

                I had made a couple mistakes, I did not realize you were converting NT7 code to NT8 code. I also mistakenly suggested "Last" when I should have suggested "Close" .

                This code sample should accomplish the goal you are after.

                Code:
                [FONT=Courier New]
                        protected Account getMyAccount()
                        {
                            if (myAccount == null)
                            {
                                lock (Account.Accounts)
                                {
                                    myAccount = Account.Accounts.FirstOrDefault(a => a.Name == "Sim101");
                                }
                            }
                            return myAccount;
                        }
                        private Account myAccount;
                
                        protected override void OnBarUpdate()
                        {
                            if (getMyAccount() == null)
                            {
                                return;
                            }
                            if (myAccount.Get(AccountItem.CashValue, Currency.UsDollar) > 25000)
                            {
                                double value = myAccount.Get(AccountItem.CashValue, Currency.UsDollar) / Close[0];
                                Print("The account value / last traded price = " + value);
                            }
                        }[/FONT]
                To arrive at that example, I first reviewed the code breaking changes page, where I found GetAccountValue had become Account.Get



                Next, when I attempted to use Account directly, I received an error message indicating that Ninja did not know which account I was attempting to work with. That led me to this page documenting Account generally, including a great code sample.



                I highly recommend studying those two pages as you develop your code further.

                Please let us know if there are any other ways we can help.
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Hi,

                  I justed tested the code you have posted and I just get more errors so I followed the links you provided and trying to solve the errors. Screenshot is in attachment.
                  Attached Files
                  Last edited by cube1984; 08-09-2016, 03:03 PM.

                  Comment


                    #10
                    Hello cube1984,

                    Your attachments do not seem to be posting. I am attaching the complete NinjaScript file containing the above code that I tested with before posting it. Please build your strategy off this code. It belongs in your (My) Documents\NinjaTrader 8\bin\Custom\Indicators folder.

                    Please let us know if there are any other ways we can help.
                    Attached Files
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi,

                      First of all thank you to get me on the right line. now I tried the coe you made and there is now an extra box for the indicator. but it's seems that nothing is getting plotted.

                      regards

                      Comment


                        #12
                        Hello cube1984,

                        I am glad you were able to get this indicator installed. Deciding how to plot data is up to you as the programmer. However, if you would like to verify that this script is running as expected, you may visit the NT8 Control Center -> New -> NinjaScript Output . You will see the value printed here.

                        If you would like to learn how to plot to a chart, please review this link.



                        You will want to set Values[0][0] to what I have simply called "value" while inside the "if (myAccount.Get ..." section.

                        And as always we are happy to help with any specific questions that come up.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi,

                          Yes I see an output in the NT script output. Now How Can I plut this value in the indicator box that is showing under my volume box?

                          I added this code:

                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Description = @"Enter the description for your new custom Indicator here.";
                          Name = "Example1555063";
                          Calculate = Calculate.OnBarClose;
                          IsOverlay = false;
                          DisplayInDataBox = true;
                          DrawOnPricePanel = true;
                          DrawHorizontalGridLines = true;
                          DrawVerticalGridLines = true;
                          PaintPriceMarkers = true;
                          ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                          //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                          //See Help Guide for additional information.
                          IsSuspendedWhileInactive = true;
                          // Adds a blue line style plot
                          AddPlot(new Stroke(Brushes.Blue), PlotStyle.Line, "Example1555063");
                          }
                          else if (State == State.Configure)
                          {
                          }
                          }

                          protected Account getMyAccount()
                          {
                          if (myAccount == null)
                          {
                          lock (Account.Accounts)
                          {
                          myAccount = Account.Accounts.FirstOrDefault(a => a.Name == "Sim101");
                          }
                          }
                          return myAccount;
                          }
                          private Account myAccount;

                          protected override void OnBarUpdate()
                          {
                          if (getMyAccount() == null)
                          {
                          return;
                          }
                          if (myAccount.Get(AccountItem.CashValue, Currency.UsDollar) > 25000)
                          {
                          double value = myAccount.Get(AccountItem.CashValue, Currency.UsDollar) / Close[0];
                          Print("The account value / last traded price = " + value);
                          }
                          }
                          }
                          }

                          Comment


                            #14
                            Hello cube1984, and thank you for your question.

                            I had mentioned in my most recent reply, to accomplish this, you will want to set Values[0][0] to what I have simply called "value" while inside the "if (myAccount.Get ..." section . I can modify the tail end of your code sample to accomplish this.

                            Code:
                            [FONT=Courier New]
                            double value = myAccount.Get(AccountItem.CashValue, Currency.UsDollar) / Close[0];
                                        	Print("The account value / last traded price = " + value);
                            [B]Values[0][0] = value;[/B][/FONT]
                            Please let us know if there are any other ways we can help.
                            Jessica P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi,

                              Is it also possible to ad a 2nd calculation lets say I want to calculatr position size on 1/6 of my portfolio:

                              (The account value / 6 ) / last traded price = " + value);

                              edit: found the solution
                              Last edited by cube1984; 09-08-2016, 07:26 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Tim-c, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Tim-c
                              by Tim-c
                               
                              Started by FrancisMorro, Today, 03:24 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post FrancisMorro  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              10 responses
                              1,771 views
                              0 likes
                              Last Post Leafcutter  
                              Started by Rapine Heihei, 04-23-2024, 07:51 PM
                              2 responses
                              31 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              945 views
                              0 likes
                              Last Post spwizard  
                              Working...
                              X