Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to automate quantity orders?

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

    How to automate quantity orders?

    Hello everyone,

    First time here and developer of strategies. I am trying to automate my quantity orders based on my account. I try to code for getaccountvalue() but it throws a cs0120 "an object reference is required for the non-static object, field, method or property."

    I am trying to code it into onbarupdate() and the error code say its located on line 28 in the variables or #region. So how do it get the account value so i do calculations on it without throwing an error code?


    Thanks

    #2
    Originally posted by ericson View Post
    Hello everyone,

    First time here and developer of strategies. I am trying to automate my quantity orders based on my account. I try to code for getaccountvalue() but it throws a cs0120 "an object reference is required for the non-static object, field, method or property."

    I am trying to code it into onbarupdate() and the error code say its located on line 28 in the variables or #region. So how do it get the account value so i do calculations on it without throwing an error code?


    Thanks
    Please post the exact code.

    I see it takes 1 parameters.

    Code:
    Syntax
    GetAccountValue(AccountItem accountItem)
    
     
    
    Parameters
    
    accountItem
     Possible values:
    AccountItem.BuyingPower
    
    AccountItem.CashValue
    
    AccountItem.RealizedProfitLoss

    Comment


      #3
      Hello ericson,

      Thank you for your post and welcome to the NinjaTrader Support Forum!

      Sledge is correct, there must be a parameter passed through the method. Such as the example from the Help Guide item on GetAccountValue():
      Code:
      protected override void OnBarUpdate()
      {
          // Checks to see if the account has more than $25000
          if (GetAccountValue(AccountItem.CashValue) > 25000)
              // Do something;
      }
      For information on GetAccountValue() please visit the following link: http://www.ninjatrader.com/support/h...countvalue.htm

      Please let me know if you have any questions.

      Comment


        #4
        Actually, I figured it out, but i have another problem:

        Code:
        double equity;
        int qty;
        
                /// <summary>
                /// This method is used to configure the strategy and is called once before any strategy method is called.
                /// </summary>
                protected override void Initialize()
                {
        
                    CalculateOnBarClose = true;
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
        			equity = Math.Round(GetAccountValue(AccountItem.CashValue));
        			qty = ((int) equity) / 10000;
        I think the casting from double to int is still carrying the lost information to "qty." I performed a market replay connection and it was supposed to execute an order for 10 shares, yet ordered 9 and 1 at the same date/time as separate executions.

        So Order summary say 10 only, yet executions say 9 and 1.

        I want a whole 10 and single commision. Why is this?

        Comment


          #5
          Originally posted by ericson View Post
          Actually, I figured it out, but i have another problem:

          Code:
          double equity;
          int qty;
          
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
          
                      CalculateOnBarClose = true;
                  }
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                      equity = Math.Round(GetAccountValue(AccountItem.CashValue));
                      qty = ((int) equity) / 10000;
          I think the casting from double to int is still carrying the lost information to "qty." I performed a market replay connection and it was supposed to execute an order for 10 shares, yet ordered 9 and 1 at the same date/time as separate executions.

          So Order summary say 10 only, yet executions say 9 and 1.

          I want a whole 10 and single commision. Why is this?
          That is simply a reflection of reality: you have no control over how your broker will fill your orders, unless they have a FillOrKill Order type. NinjaTrader does not have that order type.

          Comment


            #6
            Hello ericson,

            Thank you for your response.

            You can track the executions through OnExecution() and ensure that the quantity is correct for your desired quantity. This will also allow you to use IOrder objects to track the order itself as well.

            For information on OnExecution() please visit the following link: http://www.ninjatrader.com/support/h...nexecution.htm

            For information on IOrder objects please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rhyminkevin, Today, 04:58 PM
            4 responses
            52 views
            0 likes
            Last Post dp8282
            by dp8282
             
            Started by iceman2018, Today, 05:07 PM
            0 responses
            5 views
            0 likes
            Last Post iceman2018  
            Started by lightsun47, Today, 03:51 PM
            0 responses
            7 views
            0 likes
            Last Post lightsun47  
            Started by 00nevest, Today, 02:27 PM
            1 response
            14 views
            0 likes
            Last Post 00nevest  
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            50 views
            0 likes
            Last Post futtrader  
            Working...
            X