Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mulientries problem.

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

    Mulientries problem.

    Hallo.
    I want to programme strategy with few entries per direction.
    Each set of condition is same but I want to place only one order in one bar. How to do not let strategy place all orders at the same time??
    My Example:
    //first entry
    if (Close[1] < Close[0])
    {
    entryOrderLong1 = EnterLong(positionsize, "MyEntryLong2");
    }
    //second entry
    if (Close[1] < Close[0])
    {
    entryOrderLong2 = EnterLong(positionsize, "MyEntryLong2");
    }

    I mean what are the possible solutions to do not let strategy place both orders at the same bar??
    Maybe some samples are available??

    Rgds
    Czarek

    #2
    Czarek,

    If you have the exact same conditions then they will place at the same bar. You need to come up with your own conditions that will separate them. Different conditions = different times the trades will go at.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh.
      Can you type me sample of time condition whih separate entries and let the place only one entry in one bar?
      Czarek

      Comment


        #4
        Run CalculateOnBarClose = true.

        CODE NOT TESTED
        Code:
        // In variables section
        private bool entered1 = false;
        private bool entered2 = false;
        private bool entered3 = false;
        
        // In OnBarUpdate()
        if (Close[0] > Close[1] && entered1 == false)
        {
             EnterLong();
             entered1 = true;
        }
        
        if (Close[0] > Close[1] && entered1 && entered2 == false)
        {
             EnterLong();
             entered2 = true;
        }
        
        if (Close[0] > Close[1] && entered2 && entered3 == false)
        {
             EnterLong();
             entered3 = true;
        }
        etc. etc.
        This is just a quick grunt way to do it. You can come up with whatever techniques you want on your own too.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh.
          If I set like this:
          Code:
          //Second enter for long
             if  (entryOrderLong2 == null
           
              && Close[1] < Close[0]
              && enteredLong1 == true
              && enteredLong2 == false
           
              && Position.MarketPosition == MarketPosition.Long)
           
             {
                  entryOrderLong2 = EnterLong(positionsize, "MyEntryLong2");
              enteredLong2 = true;
             }
           
             //Third enter for long
             if  (entryOrderLong3 == null
           
              && Close[1] < Close[0]
           
              && enteredLong2 == true
              && enteredLong3 == false
           
           
           
              && Position.MarketPosition == MarketPosition.Long)
           
             {
              entryOrderLong3 = EnterLong(positionsize, "MyEntryLong3");
              enteredLong3 = true;
             }
           
             //Fourth enter for long
             if  (entryOrderLong4 == null
           
              && Close[1] < Close[0]
           
              && enteredLong3 == true
              && enteredLong4 == false
              && Position.MarketPosition == MarketPosition.Long)
           
           
             {
           
              entryOrderLong4 = EnterLong(positionsize, "MyEntryLong4");
              enteredLong4 = true;
             }
          All orders placed same time.
          If I set like your sampel second order will be placed only when first is exited.
          I would like to place all 4 orders per one direction.
          Where the mistake is?
          Czarek

          Comment


            #6
            Czarek,

            There is a logical gap in the method I posted earlier so you cannot use it as is. You will need to figure it out on your own. I cannot code everything for you. The idea is to use flags to determine if you have already entered a trade or not.

            NOT TESTED
            Code:
            private bool flag1 = true;
            private bool flag2 = false;
            private bool flag3 = false;
            
            if (flag1 == false)
                 flag2 = true;
            
            if (flag1 == false && flag2 == false)
                 flag3 = true;
            
            if (Close[0] > Close[1] && flag1)
            {
                 EnterLong();
                 flag1 = false;
            }
            
            if (Close[0] > Close[1] && flag2)
            {
                 EnterLong();
                 flag2 = false;
            }
            
            if (Close[0] > Close[1] && flag3)
            {
                 EnterLong();
                 flag3 = false;
            }
            These are ideas. You will have to run with them and adjust them for your needs.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh.
              I hope I understand that flags determinate if I have already entered order or not.
              If I already has entered order and lock the next order ( by changing flag from true to false for example) this order is not placed in bar[0] but is also do not place in the future. Method OnBarUpdate do not change anything when the next bar will come so there are no way to place anoter entry in future if former order haven't be exited. I'm not sure I'm right, of course.

              I think maybe the better will be save times of the entries to variable and call it in next order condition + few minutes. What is the syntax represent order execution time? So the code will be likee: execution time= firstEntryTime
              than I will put to the second entry time condition ToTime(Time[0] )> firstEntryTime + 5 minutes. What you think about this??

              Comment


                #8
                Here Czarek. This may be an easier approach. Use BarsSinceEntry().

                Again, not tested code
                Code:
                if (Close[0] > Close[1] && entered == false)
                {
                     EnterLong();
                     entered = true;
                }
                
                if (Close[0] > Close[1] && BarsSinceEntry() == 1)
                {
                     EnterLong();
                }
                
                if (Close[0] > Close[1] && BarsSinceEntry() == 2)
                {
                     EnterLong();
                }
                You can get the time based off of the IOrder, but that is way to complex programming for this.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Hallo Josh.
                  Thanks for you reply.
                  Looks the BarsSinceEntry method is good but it is refer always to first entry. It mean that bars since entry is calculated from first entry in direction. Are the any way to change it to be calculated always from last entry??
                  Best Regards
                  Czarek

                  Comment


                    #10
                    Unfortunately this is not possible.
                    RayNinjaTrader Customer Service

                    Comment


                      #11
                      Does BarsSinceEntry("Signal1") get reset when a position for "Signal1" is exited or when a position is reentered with the same signal name?

                      Comment


                        #12
                        When reentered with the same signal name.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        607 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        353 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        105 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        560 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        561 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X