Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

LImit entries per direction within code

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

    LImit entries per direction within code

    Is there a way to limit the number of entries per direction for a specific set of orders within the strategy code?

    For example, of the first 6 orders in the code only the first 2 to meet the criteria for entry should be executed and of the last 8 orders in the code, only the first 3 orders to get triggered should be executed.

    So that even if the strategy calls to execute all 14 orders because of the criteria being met on the chart, and the entries per direction is set to 14 for that strategy when applied to the chart, it will nonetheless only send out the first 2 orders of the set of 6 orders, and the first 3 orders of the set of 8 orders.

    Is there a way to do this within the code of one strategy?

    I know I can just make them into 2 separate strategies and set the entries per direction to 2 for the first code and 3 for the second code, but is there a way to get this technique all within one strategy?
    Last edited by werido; 03-08-2013, 02:27 PM.

    #2
    Hello werido,

    You would only be able to set the Entries per direction and Entry handling once inside of a Strategy.

    With that said, you should be able to add additional conditions inside of your Strategy to be able to limit the number of trade that you would like to take. For example you can add a bool or an integer user defined variable to limit this.

    Code:
    pseudo code
    int LimitTrades;
    
    OnBarUpdate()
    for(int i=0; i < LimitTrades; i++)
    {
       // Entry order
    }
    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello werido,

      You would only be able to set the Entries per direction and Entry handling once inside of a Strategy.

      With that said, you should be able to add additional conditions inside of your Strategy to be able to limit the number of trade that you would like to take. For example you can add a bool or an integer user defined variable to limit this.

      Code:
      pseudo code
      int LimitTrades;
      
      OnBarUpdate()
      for(int i=0; i < LimitTrades; i++)
      {
         // Entry order
      }
      Let us know if we can be of further assistance.

      ok so I can put the first set of 6 orders in place of where you wrote //Entry order, but where do I set the entries per direction to 2 in this code?

      Comment


        #4
        Hello werido,

        Inside the Initialize() method.

        Code:
        protected override void Initialize() 
        { 
            EntriesPerDirection = 2; 
        }
        Here is a link to our Help Guide that goes over EntriesPerDirection.


        Here is a link to our Help Guide that goes over EntryHandling.
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JC View Post
          Hello werido,

          Inside the Initialize() method.

          Code:
          protected override void Initialize() 
          { 
              EntriesPerDirection = 2; 
          }
          Here is a link to our Help Guide that goes over EntriesPerDirection.


          Here is a link to our Help Guide that goes over EntryHandling.
          http://www.ninjatrader.com/support/h...ryhandling.htm

          This method will only set the entries per direction to 2 for the whole code. I want only part of the code to have 2 and the rest 3, all in the same strategy.

          Comment


            #6
            Originally posted by werido View Post
            This method will only set the entries per direction to 2 for the whole code. I want only part of the code to have 2 and the rest 3, all in the same strategy.
            You simply need 2 separate counters, one for each set.
            Each entry is gated by the counter reaching the maximum count.
            On each entry, you increment the counter.

            Example for one set. (in pseudocode)

            Code:
            private int MaxSet1Trades = 2;
            private int Set1TradesCounter = 0;
            Code:
            if (Set1TradesCounter < MaxSet1Trades)
            {
            if (Set1Cond1)
            {
            MakeEntry();
            Set1TradesCounter++;
            }
            if (Set1Cond2)
            {
            MakeEntry();
            Set1TradesCounter++;
            }
            if (Set1Cond3)
            {
            MakeEntry();
            Set1TradesCounter++;
            } 
            }
            //et.c.,
            Remember to reset your Set1TradesCounter when you go flat, or at the start of the day, or whenever your trading is to be reenabled.

            Comment


              #7
              Originally posted by koganam View Post
              You simply need 2 separate counters, one for each set.
              Each entry is gated by the counter reaching the maximum count.
              On each entry, you increment the counter.

              Example for one set. (in pseudocode)

              Code:
              private int MaxSet1Trades = 2;
              private int Set1TradesCounter = 0;
              Code:
              if (Set1TradesCounter < MaxSet1Trades)
              {
              if (Set1Cond1)
              {
              MakeEntry();
              Set1TradesCounter++;
              }
              if (Set1Cond2)
              {
              MakeEntry();
              Set1TradesCounter++;
              }
              if (Set1Cond3)
              {
              MakeEntry();
              Set1TradesCounter++;
              } 
              }
              //et.c.,
              Remember to reset your Set1TradesCounter when you go flat, or at the start of the day, or whenever your trading is to be reenabled.

              This won't work in a backtest because of the need to reset. Is there a way to do this intrinsically in the code without a counter that needs to be reset?

              Comment


                #8
                Originally posted by werido View Post
                This won't work in a backtest because of the need to reset. Is there a way to do this intrinsically in the code without a counter that needs to be reset?
                Sorry? I fail to see what Backtest has to do with anything.

                Comment


                  #9
                  Originally posted by koganam View Post
                  Sorry? I fail to see what Backtest has to do with anything.
                  I have two strategies that I'm trying to combine into one so that I can run a simultaneous backtest. Each strategy is optimized by a certain max number of entries per direction, if I just combine the codes without being able to specify how many max entries per direction for each set of code, then I won't be getting the same outcome as if I run both strategies on a singe chart.

                  I'm trying to have one strategy that combines both codes and their respective max entries per direction so that I can backtest that strategy. There is no way to backtest two strategies simultaneously and get one chart and performance results of the outcome. Of course I can just run both strategies on a chart going forward, but I want to see from a backtest what it can do and if for example the max drawdowns are not at the same time which would be a huge plus.

                  Comment


                    #10
                    Originally posted by werido View Post
                    I have two strategies that I'm trying to combine into one so that I can run a simultaneous backtest. Each strategy is optimized by a certain max number of entries per direction, if I just combine the codes without being able to specify how many max entries per direction for each set of code, then I won't be getting the same outcome as if I run both strategies on a singe chart.

                    I'm trying to have one strategy that combines both codes and their respective max entries per direction so that I can backtest that strategy. There is no way to backtest two strategies simultaneously and get one chart and performance results of the outcome. Of course I can just run both strategies on a chart going forward, but I want to see from a backtest what it can do and if for example the max drawdowns are not at the same time which would be a huge plus.
                    And I just showed you what to do. You simply have to have separate counters. How many times do you want the trades to be taken in a day? Or do you want trades to be taken anytime the strategy is flat, or anytime either entry type is flat? It is a matter of deciding when entries can be taken.

                    There is no other way than using a counter. If you want to know how many times an event happens, (in this case, your trades), you must use a counter. And yes, EntriesPerDirection uses a counter under the covers. There is no EntriesPerDirectionPerUserDefnedTradeBlock.

                    Backtest, or Realtime, has nothing to do with the matter. At least, not if your trades are all being generated from OnBarUpdate(). Trades are trades.

                    Comment


                      #11
                      ok, think i got it. thank you

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by DJ888, 04-16-2024, 06:09 PM
                      4 responses
                      12 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by terofs, Today, 04:18 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post terofs
                      by terofs
                       
                      Started by nandhumca, Today, 03:41 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post nandhumca  
                      Started by The_Sec, Today, 03:37 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post The_Sec
                      by The_Sec
                       
                      Started by GwFutures1988, Today, 02:48 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Working...
                      X