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

AccountCa$h

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

    AccountCa$h

    Hello!
    I'm trying to calculate lot size equivalent to 2% of my current account size.
    Code:
    GetAccountValue(NinjaTrader.Cbi.AccountItem.CashValue) == 0
    GetAccountValue(NinjaTrader.Cbi.AccountItem.BuyingPower) == 0
    GetAccountValue(NinjaTrader.Cbi.AccountItem.TotalCashBalance) == 0
    Thx
    Attached Files
    Last edited by schattencheg; 08-22-2018, 05:42 AM.

    #2
    Hello schattencheg,

    Thanks for your post.

    If the account provides the information, TotalCashBalance could be used. If it does not, you would have to deduct the position from CashValue.

    CashValue will get the current account size and will update on the close of a position. If you would like to keep a running total consistent with your strategies position, you could create a variable and subtract the position quantity times the position's average price.

    For example:
    Code:
    protected override void Initialize()
    {
            CalculateOnBarClose = true;
    	SetProfitTarget(CalculationMode.Ticks, 10);
    	SetStopLoss(CalculationMode.Ticks, 10);
    }
    
    protected override void OnBarUpdate()
    {
    	if(Historical)
    		return;
    	
    	Print((int)((GetAccountValue(NinjaTrader.Cbi.AccountItem.CashValue) * 0.02)/Close[0]) - Position.Quantity * Position.AvgPrice);
    	Print("");
    	
    	if(Position.MarketPosition == MarketPosition.Flat)
    		EnterLong((int)((GetAccountValue(NinjaTrader.Cbi.AccountItem.CashValue) * 0.02)/Close[0]));
    }
    I'll include a link to GetAccountValue's and Position's documentation as well as some further detail on which Account Items are available for our supported providers for the thread's reference.

    GetAccountValue - https://ninjatrader.com/support/help...countvalue.htm

    Position - https://ninjatrader.com/support/help...7/position.htm

    Accounts tab (which Account Items are available depending on your provider) - https://ninjatrader.com/support/help...counts_tab.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer.
      Tell me please why you check for Historical?
      Code:
      if(Historical)
      		return;

      Comment


        #4
        Hello schattencheg,

        GetAccountValue returns 0 with historical data. The return statement is to skip historical data so GetAccountValue's output would be meaningful.

        Please let us know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello, Jim!
          Thanks for your reply.
          Now i'm facing new problem. When i trying to optimize my strategy i have following results:
          Gross profit: 3471,11$
          Gross loss: -6479,84$
          Total Net Profit: -3008$

          But Cumulative profit is 12,07%.

          Can you explain this to me, please?
          Attached Files

          Comment


            #6
            Hello schattencheg,

            I wouldn't expect to see the Cumulative Profit shown in black for a negative percentage. When we look in the summaries tab, we see what we should expect to see.

            I tested on my end with NinjaTrader 7 R38 and the SampleMACrossover strategy and did not see this issue. Could you confirm that you are seeing the same behavior on your end with this version?

            Update installers can be found here - https://ninjatrader.com/PlatformDirect

            I look forward to being of further assistance.
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              I have R38 version and when run backtest of SimpleMACrossover have same results as you.
              But still when testing my strategy have red positive percents when total net profit -3700$, what am i doing wrong??
              Attached Files

              Comment


                #8
                Hello schattencheg,

                I am not sure which settings you used to backtest your strategy and what time frame you are backtesting against.

                So I can verify, when you test with SampleMACrossover and default settings, you are seeing the correct behavior when you tested the same instruments as you have with your strategy? The issue is specific to your strategy alone?

                We did release a new version of NinjaTrader 7 earlier today, R39. There was not a "fix" included for what you are encountering, but for next steps, I'd like you to close NinjaTrader and restart your computer, and then to install R39 before testing the Strategy Analyzer again.

                If you are still encountering issues at this point, I would like to arrange a time where we can get connected so I can take a closer look. Please then send me a message at platformsupport [at] ninjatrader [dot] com with the text "Attn Jim," the thread URL, and a time we can get connected.(Please include a time zone.) Our regular support hours are 8:30am to 6pm US Eastern, Monday through Friday.

                I look forward to being of further assistance.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by funk10101, Today, 12:02 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by GLFX005, Today, 03:23 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by nandhumca, Yesterday, 03:41 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by The_Sec, Yesterday, 03:37 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by vecnopus, Today, 06:15 AM
                0 responses
                1 view
                0 likes
                Last Post vecnopus  
                Working...
                X