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

Position size based on account size

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

    Position size based on account size

    I'd like to include in my forex strategy a position size based on the account size (cash). I've found the AccountItem.TotalCashBalance instruction but i don't know how to use it, where i can put it in the strategy builder, etc, etc. I also have to include the value of the money that i buy. Thanks for help.

    AF

    #2
    Hello Alf63,

    Thank you for your note.

    Account items such as account balance are an advanced concept that would require custom coding outside the strategy builder.

    If you'd like, I can have someone reach out with a list of third party developers that would be interested in building this into your strategy.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello AlanP,

      Thanks for answer. In the short term, why not using the help of a third party developpers (french?) but, after, i'd appreciate to find learning resources and develop other strategies by myself.

      Regards.

      AF

      Comment


        #4
        Hello Alf63,

        May I confirm you'd like a list of third parties?

        When you are ready to work in the NS editor to code yourself, the attached sample will buy x amount of micro lots based on FX account size, you may find this helpful.

        More information on learning NinjaScript,

        I would suggest watching the Strategy Wizard 301 which goes over using the wizard to create strategies.
        Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Wizard.3:23 Strategy Wizard Overview7:...


        See the NinjaScript Editor Youttube,
        Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


        A link to our Help Guide with tutorials can be found below:


        You will find Reference Samples online as well as some Tips and Tricks for both indicators and strategies:

        Click here to see our NinjaScript Reference Samples:


        Click here to see our NinjaScript Tips:


        I look forward to your reply.
        Attached Files
        Last edited by NinjaTrader_AlanP; 01-10-2018, 03:07 PM.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          AlanP,

          Again, thanks for reply. I will study carefully these informations.

          Yes, you can send me a list of third parties.

          AF

          Comment


            #6
            Originally posted by Alf63 View Post
            I'd like to include in my forex strategy a position size based on the account size (cash). I've found the AccountItem.TotalCashBalance instruction but i don't know how to use it, where i can put it in the strategy builder, etc, etc. I also have to include the value of the money that i buy. Thanks for help.

            AF
            below is the code that i've used to solve the problem:

            create these variables:

            Code:
            				
            AccountSize			= 50000;
            RiskPercent			= 0.2;
            Leverage			= 40;
            Above can be the "starting" capital for your strategy. Risk percent is how much you are going to allocate to each trade. Leverage, is the leverage that you are using during your live trading.

            Then to get current account value (available funds for the next trade):

            Code:
            			
            [B]//this code will sum your "starting" capital with current profit/loss on the strategy. [/B]
            double total_fundUSD= AccountSize+Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Closes[1][0])
            			+SystemPerformance.AllTrades.TradesPerformance.Currency.CumProfit;
            
            [B]//this code will take the above account, and multiple it with "risk percent" to calculate how much funds you are going to use on the "next trade."[/B]
            
            double dummyQ = (((int)Math.Floor((total_fundUSD*RiskPercent)/3)) * Leverage); 
            
            [B]//this code will normalize the above calculated volume by 1000's so that it's a even forex lot.[/B]
            fxToBuy =  ((int)(dummyQ/1000))*1000;
            
            [B]//this code will print the amount for the lot you are going to buy[/B]
            Print(fxToBuy);
            
            [B]//this code will give you the current value for the account[/B]
            Print(total_fundUSD);
            This may not be exactly what you are looking for but it has all the information for you to get started. You cannot do this in Strategy Builder, you will have to unlock the code and manually plug the above variables under OnBarUpdate.

            Good luck!

            Comment


              #7
              Hello calhawk01,

              Thanks a lot for this valuable information (you're right, i'll need luck !!) !!

              AF

              Comment


                #8

                Hi, Re: BuyXMicroLotsOfFxPerAccountSize.zip (1.8 KB, 98 views), nothing happens when I run this strat as is.​

                Comment


                  #9
                  Hello trader3000a,

                  Thanks for your note.

                  When testing the example script shared on post number 4 on a 1-Minute EURUSD chart, I am seeing the strategy print out the account size and number of shares to buy to a NinjaScript Output window and place an order on the chart reflecting the number of shares to buy seen in the Output window.

                  Please see attached screenshot demonstrating this.

                  If you enable the script on a 1-Minute EURUSD chart that has live data populating on the chart, do you see the strategy behaving on your end similar to the screenshot attached?

                  Let me know if I may assist further.
                  Attached Files
                  Brandon H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ZenCortexCLICK, Today, 04:58 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post ZenCortexCLICK  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  172 responses
                  2,280 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Irukandji, Yesterday, 02:53 AM
                  2 responses
                  17 views
                  0 likes
                  Last Post Irukandji  
                  Started by adeelshahzad, Today, 03:54 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post adeelshahzad  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X