Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AccountItem.CashValue returns 0

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

    AccountItem.CashValue returns 0

    I'm testing on the demo account right now which has a cash value of $100,000.

    This is the call:

    Code:
    double accountSize = GetAccountValue(AccountItem.CashValue);
    Print("Position size: " + positionSize);
    In backtesting (have not tested live yet) it's returning 0.

    Position Size: 0
    What am I doing wrong?

    #2
    Hello molecool,

    Thank you for your post.

    Where are you defining positionSize? I do not see this defined in your code.

    I look forward to your response.

    Comment


      #3
      Hello molecool,

      In addition, GetAccountValue() is always zero on historical data. Backtesting is always done on historical data. For information on GetAccountValue() please visit the following link: http://www.ninjatrader.com/support/h...countvalue.htm

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello molecool,

        In addition, GetAccountValue() is always zero on historical data. Backtesting is always done on historical data. For information on GetAccountValue() please visit the following link: http://www.ninjatrader.com/support/h...countvalue.htm
        I suspected that much, seems like I have to use a default value for backtesting. Not a big deal but a bit inconvenient. I assume it has to do with the complexity involved in attaching a live (or demo) account to historical executions? I think there should be a way to use a 'one-time' demo account for a backtest or for historical executions. Just a thought.

        Per your prior question - I'm using some proprietary code to calculate positions sizes for Forex as well as the futures. Glad to share the one for the futures:

        Code:
        protected double calculatePositionSize(double stopInFullTicks) {
           double accountSize = GetAccountValue(AccountItem.CashValue);
           double unitCost = Instrument.MasterInstrument.PointValue;
           double money = accountSize * (RiskRatioPercent / 100);
           double positionSize = money / unitCost / stopInFullTicks;
           double positionSizeTruncated = Convert.ToInt32(positionSize / TickSize) * TickSize;
        }
        I'm truncating the position size at the end to be arch conservative.

        The forex piece was quite a tough one and I use similar logic as the one on my Rcalc implemented in javascript:



        It considers various factors such as direct and indirect pairs and even accounts for account currency, although in the NT version that's hard set to USD. A more difficult piece was the currency priority which decides which currency becomes the lowest and which the highest priority.

        I may be convinced to donate this piece as I think it's something that would very much benefit the rest of the community. I'll test it for a while to make sure it's stable and reliable.
        Last edited by molecool; 07-15-2013, 09:57 AM.

        Comment


          #5
          Hello molecool,

          Thank you for your response.

          There is no need to provide the code for the positionSize information, I just wanted to make sure you understand that the accountSize is not the same value as positionSize as detailed in your original post.

          I have forwarded your suggestion to our development team for the option to edit the backtest account settings for your tests so they can be accessed similar to real-time accounts (SIM101 for example), I think this would be a great feature as well.

          Please let me know if I may be of further assistance.

          Comment


            #6
            Hello molecool,

            Thank you for your suggestion on how we can improve our product. It has been inserted into our tracking system with the unique ID # 2466.

            Comment


              #7
              I think a lot of people would benefit from an FX conversion module. The code isn't that complicated and I think it would benefit a lot of people.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              648 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              572 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              574 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X