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

BarsSinceEntry

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

    BarsSinceEntry

    I have tried the following exit. It should exit after 5 bars. In my case I am using a 1 second chart which I select when I set the strategy to run.

    if (this.BarsSinceEntry() > 5)
    {
    ExitShort("", "");
    ExitLong("", "");
    }

    I would expect any position to close out after 5 seconds in this case. But it seems to just be ignoring it.

    #2
    I suggest debugging your strategy as per here: http://www.ninjatrader-support.com/v...ead.php?t=3418

    and here

    Comment


      #3
      Did this exit system work in the end for you? I am trying it on a 3 minute chart but the strategy exits the position straight away which is frustrating.

      Everington_f

      Comment


        #4
        Everington_f, what are you using to exit your positions? Can you provide us a snippet of the code you're using?
        AustinNinjaTrader Customer Service

        Comment


          #5

          if (this.BarsSinceEntry() > 4)
          {
          ExitLong("Long");
          ExitShort("Short");
          }

          else


          if (Position.MarketPosition == MarketPosition.Long)
          {
          if (Close[0] < aligator.Lips[barsAgo] - stopOffset * TickSize)
          {
          if (!Historical)



          {

          }
          ExitLong(
          "Long");
          }
          }
          if (Position.MarketPosition == MarketPosition.Short)
          {
          if (Close[0] > aligator.Lips[barsAgo] + stopOffset * TickSize)
          {
          if (!Historical)
          {

          }
          ExitShort(
          "Short");

          Comment


            #6
            Everington_f, it appears you have two sets of exit conditions. Do you know which one is causing the exits? The easiest way to get to the root of a problem is to reduce the program until everything functions correctly, then add functionality one layer at a time until you find the problem.
            AustinNinjaTrader Customer Service

            Comment


              #7
              the bars since entry function is causing the problem... the strategy has worked for months without this additional condition...

              Comment


                #8
                Everington, it looks like you will have to debug. I recommend using Print() statements to get a feel for the data your strategy is using.

                In your case, since you said the strategy has worked fine without the BarsSinceEntry, just add a simple
                Code:
                Print("BarsSinceEntry:\t" + this.BarsSinceEntry())
                in OnBarUpdate() and see what values come back.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Everington, another useful tool to figure out what is happening is TraceOrders. TraceOrders will let you know exactly what is happening with orders and why.
                  In Initialize:
                  Code:
                  TraceOrders = true;
                  AustinNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Waxavi, 04-19-2024, 02:10 AM
                  3 responses
                  41 views
                  0 likes
                  Last Post gaz0001
                  by gaz0001
                   
                  Started by Max238, Today, 01:28 AM
                  2 responses
                  26 views
                  0 likes
                  Last Post NinjaTrader_ChristopherJ  
                  Started by Shansen, 08-30-2019, 10:18 PM
                  25 responses
                  949 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by JonesJoker, 04-22-2024, 12:23 PM
                  8 responses
                  42 views
                  0 likes
                  Last Post JonesJoker  
                  Started by timko, Today, 06:45 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post timko
                  by timko
                   
                  Working...
                  X