Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AccountSize

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

    AccountSize

    All,

    I’m having some challenges with AccountSize.

    I’m planning to use the methodology discussed on another thread to calculate position size based on remaining account equity. Notably,

    Code:
     
    [COLOR=blue][FONT=Courier New]double[/FONT][/COLOR][COLOR=black][FONT=Courier New] CAccountSize = AccountSize + Performance.AllTrades.TradesPerformance.Currency.CumProfit;[/FONT][/COLOR]
    (see thread: http://www.ninjatrader-support2.com/vb/showthread.php?t=11614 and some code that PrTester has kindly shared).

    Unfortunately, I am getting an account size of 0 when testing. I’ve checked this setting in the Control Centre -> Options -> Simulator (Initial Cash) where I assume this number is obtained – see screen shot. It should be starting with AccountSize equal to 10,000.

    The output from the following lines of code is 0.

    Code:
    [COLOR=black][FONT=Courier New]Print([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"Account Size = "[/FONT][/COLOR][COLOR=black][FONT=Courier New]+ AccountSize);[/FONT][/COLOR]
    Can someone point me in the right direction here?

    Thanks,

    Dan
    Attached Files

    #2
    Dan, unfortunately accessing this Sim101 account info is not supported.

    You can set this however directly in your Initialize() as you need it - http://www.ninjatrader-support.com/H...countSize.html

    Comment


      #3
      Bertrand,

      Thank you very much for the reply.

      I had tried this before but I tried it again after your pointer. Unfortunately, AccountSize is still showing as zero in the output.

      Below I have copied in my Initialise function code. Is there something to do with placement within this function?

      Code:
      [COLOR=blue][FONT=Courier New]protected [/FONT][/COLOR][COLOR=blue][FONT=Courier New]override [/FONT][/COLOR][COLOR=blue][FONT=Courier New]void[/FONT][/COLOR][COLOR=black][FONT=Courier New] Initialize()[/FONT][/COLOR]
      [COLOR=black][FONT=Courier New]      {[/FONT][/COLOR]
       
       
       
      [COLOR=black][FONT=Courier New]                ClearOutputWindow();[/FONT][/COLOR]
       
       
      [COLOR=black][FONT=Courier New]                Add(PeriodType.Day, [/FONT][/COLOR][COLOR=purple][FONT=Courier New]1[/FONT][/COLOR][COLOR=black][FONT=Courier New]);[/FONT][/COLOR]
      [COLOR=black][FONT=Courier New]                Add(PeriodType.Minute, [/FONT][/COLOR][COLOR=purple][FONT=Courier New]15[/FONT][/COLOR][COLOR=black][FONT=Courier New]);[/FONT][/COLOR]
       
      [COLOR=black][FONT=Courier New]                AccountSize = [/FONT][/COLOR][COLOR=purple][FONT=Courier New]10000[/FONT][/COLOR][COLOR=black][FONT=Courier New];[/FONT][/COLOR]
       
      [COLOR=black][FONT=Courier New]                TraceOrders        = [/FONT][/COLOR][COLOR=blue][FONT=Courier New]true[/FONT][/COLOR][COLOR=black][FONT=Courier New];[/FONT][/COLOR]
       
      [COLOR=black][FONT=Courier New]          CalculateOnBarClose = [/FONT][/COLOR][COLOR=blue][FONT=Courier New]true[/FONT][/COLOR][COLOR=black][FONT=Courier New];[/FONT][/COLOR]
       
       
       
      [COLOR=black][FONT=Courier New]      }[/FONT][/COLOR]
      Kind regards,

      Dan

      Comment


        #4
        You're welcome Dan, tried this quickly on my end and displays the 10K here on my end fine, in the Initialize() -

        Code:
         
        protected override void Initialize()
        {
        CalculateOnBarClose = true;
        AccountSize = 10000;
        }
        then in the OnBarUpdate -

        Code:
         
        protected override void OnBarUpdate()
        {
        Print(AccountSize.ToString());
        }
        You post your full code here if you wish and we'll take a look - thanks!

        Comment


          #5
          Bertrand,

          Thank you again for your prompt response.

          Unfortunately, I'm still seeing 0. I've tried to make my code like exactly like yours (perviously, I was using an implict cast in the print statement).

          My code now looks like yours:

          Code:
          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
           
           
           
          [SIZE=2][FONT=Courier New]ClearOutputWindow();[/FONT][/SIZE]
           
           
          [SIZE=2][FONT=Courier New]Add(PeriodType.Day, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Add(PeriodType.Minute, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]15[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
           
           
           
          [SIZE=2][FONT=Courier New]TraceOrders = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
           
          [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
           
          [SIZE=2][FONT=Courier New]AccountSize = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
           
          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event.[/COLOR][/SIZE][/FONT]
          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
          [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Account Size = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]+ AccountSize.ToString());[/SIZE][/FONT]
           
          [/SIZE][/FONT]
          The code obviously follows on with the reminder of the onbarupdate() function.

          Unfortunately, still zero.

          Thanks,

          Dan

          Comment


            #6
            Dan, you're welcome - please test this simple sample attached. Tested this briefly on EURUSD 5 min and works as expected.
            Attached Files

            Comment


              #7
              Bertrand,

              Thanks again for your reply.

              OK, ghost in the machine.

              Closed down all the scripts, imported yours, ran it, worked correctly (as expected).

              Then re-ran mine, all working now.

              Thanks again for your help.

              Kind regards,

              Dan

              Comment


                #8
                Ok, good to hear this is resolved for you.

                Comment


                  #9
                  Bertrand,

                  After further testing it does appear to be a bug here somewhere.

                  I’ve now implemented this as a testing process after I started to see errors. I’ve described below the steps I've taken:

                  1. The AccountSize is set to 10000.
                  2. Then run my script
                  3. Change the account size to 20000.
                  4. Re compile the script
                  5. Run the script
                  6. Account size still shows as 10000
                  7. Run AccountSize test script (the script you sent me)
                  8. Accountsize prints correctly = 10000
                  9. Go back and re-run my script – account now correct at 20000

                  If you like I can send over my code via the support email address for testing to see if you can recreate the error.

                  Kind regards,

                  Dan

                  Comment


                    #10
                    Dan, after you recompiled your script with the new set account size value, did you then press F5 to rerun your changed NinjaScript test file fresh? You can for sure send me the code to support at ninjatrader dot com and I will take a look.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    669 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    378 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    111 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    575 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    580 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X