Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntryExecution not working

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

    BarsSinceEntryExecution not working

    Hello,

    I am creating a strategy in which the system will set an initial order. After that order is executed, the system should submit another order. The strategy submits the orders in the same bar. Would you please help me figuring out the problem?

    if ( CrossBelow(EMA1, SMA1, 1) )

    {
    EnterShortLimit(0, true, 1, Close[0] + 10), "SE01");
    }

    if (BarsSinceEntryExecution(0, "SE01", 1) > 0 || BarsSinceEntryExecution(0, "SE01", 1) == -1)
    {
    EnterShortLimit(0, true, 1, Close[0] + 20, "SE02");
    }

    #2
    Hello Jorge.andres.o,

    This code does not use an else with the if, so both ifs can be true.

    Use an else or else if, if you don't want both to be true at the same time.

    Code:
    if ( CrossBelow(EMA1, SMA1, 1) )
    {
    EnterShortLimit(0, true, 1, Close[0] + 10), "SE01");
    }
    
    [B]else if[/B] (BarsSinceEntryExecution(0, "SE01", 1) > 0 || BarsSinceEntryExecution(0, "SE01", 1) == -1)
    {
    EnterShortLimit(0, true, 1, Close[0] + 20, "SE02");
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for the help. I have not been able to figure out your tips. I want to place the second entry one bar after the strategy places the first entry regardless of the status of the first entry. So far I tried this:


      if ( CrossBelow(EMA1, SMA1, 1) )
      {
      EnterShortLimit(0, true, 1, Close[0] + 10), "SE01");
      }
      else if (BarsSinceEntryExecution(0, "SE01", 1) == 1)
      {
      EnterShortLimit(0, true, 1, Close[0] + 20, "SE02");
      }

      But the second entry does not trigger.

      Comment


        #4
        Hello Jorge.andres.o,

        If the first entry does not fill, you would still like the second condition to be true?
        In that case, BarsSinceEntryExecution() will be -1 (no entry) and not 1 bar ago.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,

          No. I don't want to submit the second order if the first order does not execute. However, the second order is not submitted even when the first order is executed. Do you see any evident problem?

          Comment


            #6
            Hello Jorge.andres.o,

            Is the condition to place the order evaluating as true?

            Use prints to print the time of the bar and all values used in the condition.


            Is TraceOrders showing a message that an order was ignored or cancelled?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              I am using this code:

              Print(string.Format("{0} | BarsSinceEntryExecution(0, SE01, 1): {1}", Time[0], +BarsSinceEntryExecution(0, "SE01", 1) ));

              Am I dong it right?

              Comment


                #8
                Hello Jorge.andres.o,

                The 'else if' of the condition set will only be evaluated if the 'if' above evaluates as false. We would also want to print these values of the EMA1 and SMA1 on the previous and current bars.

                The + before BarsSinceEntryExecution(0, "SE01", 1) does not appear correct, and I always suggestion adding to the print what you are comparing with.

                ..."BarsSinceEntryExecution(0, SE01, 1): {1} == 1"
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Mindset, 04-21-2026, 06:46 AM
                0 responses
                90 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by M4ndoo, 04-20-2026, 05:21 PM
                0 responses
                137 views
                0 likes
                Last Post M4ndoo
                by M4ndoo
                 
                Started by M4ndoo, 04-19-2026, 05:54 PM
                0 responses
                68 views
                0 likes
                Last Post M4ndoo
                by M4ndoo
                 
                Started by cmoran13, 04-16-2026, 01:02 PM
                0 responses
                120 views
                0 likes
                Last Post cmoran13  
                Started by PaulMohn, 04-10-2026, 11:11 AM
                0 responses
                69 views
                0 likes
                Last Post PaulMohn  
                Working...
                X