Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting order quantity by strategy

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

    Setting order quantity by strategy

    Hi,

    I am trying to set my strategy to set the order quantity to a specified value of stocks.

    To do this I have a variable for the value, lets say 10000 (to represent $10000).

    I have another variable for order quantity.

    At the beginning of my code I divide the value by the current ask to determine the correct number of stocks which I then use when EnterLong is called.

    However when I backtest the strategy all trades are always 100 shares in size.

    Note I have "set order quantity" to "by strategy" in the order properties.

    Anyone have any ideas on what I'm doing wrong? Code below:

    Code:
    private double value = 10000; // Default value of shares to buy
    private double Dqty; // Variable for number of shares to buy of type double
    private int Iqty; // Variable for number of shares to buy of type integer
    
    ... (other code here)
    
    //calculate number of shares to buy
    Dqty = value / Ask[0];
    Iqty = Convert.ToInt32(Dqty);
    
    ... (other code here)
    
    EnterLong("Buy1", Iqty);

    #2
    matth,

    Where are you assigning the lqty at?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      I set Iqty as an int with "private int Iqty;" this takes place in the variables region.

      I assign Iqty with "Iqty = Convert.ToInt32(Dqty);" at the beginning of the main code, right after the following:

      Code:
      protected override void OnBarUpdate()
      {
      I hope that makes sense and answers your question. Thanks for your help.

      Comment


        #4
        Hello matth1,

        This is Cameron responding on behalf of Adam.


        At this point we would either need to see the full code or you could use Print Statements and the Output window to verify what is going on with the custom order quantity.


        If you would like us to analyze the code,
        Please send a note to Support[At]NinjaTrader[Dot]Com.

        Put
        ATTN: Cameron in the subject field and a link to this forum post in the body.

        Attach the strategy as a .cs file.
        CameronNinjaTrader Customer Service

        Comment


          #5
          I've managed to figure it out - it's always something minor!

          An error elsewhere was preventing the compile.

          It's all working now.

          Cheers.

          Comment


            #6
            Thanks for letting us know.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            637 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X