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 NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                56 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                132 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X