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

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 Skifree, Today, 03:41 AM
                3 responses
                12 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Started by traderqz, Yesterday, 09:06 AM
                5 responses
                32 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by guillembm, Today, 11:25 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by owensd, 04-21-2024, 11:34 PM
                9 responses
                34 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by trilliantrader, 04-10-2024, 09:33 PM
                7 responses
                25 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X