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

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 cutzpr, Today, 08:54 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post cutzpr
                  by cutzpr
                   
                  Started by benmarkal, Today, 08:44 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post benmarkal  
                  Started by Tin34, Today, 03:30 AM
                  2 responses
                  26 views
                  0 likes
                  Last Post Tin34
                  by Tin34
                   
                  Started by sastrades, Yesterday, 09:59 AM
                  2 responses
                  38 views
                  0 likes
                  Last Post brucerobinson  
                  Started by ETFVoyageur, Today, 12:52 AM
                  1 response
                  21 views
                  0 likes
                  Last Post Leeroy_Jenkins  
                  Working...
                  X