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 alifarahani, Today, 09:40 AM
                  4 responses
                  20 views
                  0 likes
                  Last Post alifarahani  
                  Started by gentlebenthebear, Today, 01:30 AM
                  3 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by PhillT, Today, 02:16 PM
                  2 responses
                  7 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Started by Kaledus, Today, 01:29 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by frankthearm, Yesterday, 09:08 AM
                  14 responses
                  47 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X