Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit trades in strategy

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

    Limit trades in strategy

    hi...what code do I need to use to limit the amount of trades? for example, i want to enable over 20 instruments to be ready to trade once conditions are met, but i also woul like to limit the number of individual separate trades for any one account. how would i do that? so, just want to enable 20 or so but tell it to trade only if i have less than, say, 7 open positions...sorry sent with mobile device....

    #2
    Hello birdog,
    To clarify further are you trying to apply 20+ different strategies on different instruments and want to open positions in 7 strategy only at one time, (even if more than 7 (say 12) strategies generate signals to go long/short.

    If so then you can use the unsupported code to know that you have 7 open position for different instruments.
    Code:
    this.Account.Positions.Count > 7 return;
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hey Joy:

      It is only 1 Strategy enabled on 20 or so instruments, but I want to limit the amount of open instruments of the 20 as they execute to, say, under 7 open total positions. If 6 are open, then the next trade signal should not execute a 7th, 8th, 9th, etc until the total trade positions of the 20 drop below 6 etc. So, basically, I want the code to act, simply, as another filter...total account positions must be < 7 in order for the next signal/trade to actually execute. What code should I use for that behavior?



      Greg

      Comment


        #4
        Hello Greg,
        You can use this unsupported code to do it.
        Code:
        this.Account.Positions.Count < 7 
        {  //do something }
        However please note, if you have any other strategy then you have to further custom code it.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          ok...got it...I just insert in the OnBarUpdate section before the "if then" statements so it applies to all ifs and and else ifs below it...no #region Variables or anything like that right?

          Comment


            #6
            Hello Greg,
            Ya, right. The Accounts object holds the information.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Joy...getting code compiling error...What is the simplest, preferably, "one line code" I can put immediately after:

              Code:
              protected override void OnBarUpdate()
                      { 
                             if (Historical) return;
                             if (Position.MarketPosition == MarketPosition.Flat)
                             ---here---
              then executable "if & else if & then statements"

              Last edited by birdog; 01-30-2013, 04:51 PM.

              Comment


                #8
                also...is it:

                this.Account.Positions.Count < 7

                or

                Account.Positions.Count < 7 (without "this" in the beginning)

                Comment


                  #9
                  Hello Greg,
                  Both the codes are same and you can use any of them.
                  Code:
                  this.Account.Positions.Count < 7 
                  
                  Account.Positions.Count < 7
                  The code compiles fine at my end. Are you able to resolve it, If not then please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                  Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                  I look forward to assisting you further.

                  *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                  JoydeepNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by charlesugo_1, 05-26-2026, 05:03 PM
                  0 responses
                  65 views
                  0 likes
                  Last Post charlesugo_1  
                  Started by DannyP96, 05-18-2026, 02:38 PM
                  1 response
                  149 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by CarlTrading, 05-11-2026, 05:56 AM
                  0 responses
                  162 views
                  0 likes
                  Last Post CarlTrading  
                  Started by CarlTrading, 05-10-2026, 08:12 PM
                  0 responses
                  99 views
                  0 likes
                  Last Post CarlTrading  
                  Started by Hwop38, 05-04-2026, 07:02 PM
                  0 responses
                  286 views
                  0 likes
                  Last Post Hwop38
                  by Hwop38
                   
                  Working...
                  X