Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit code disables all exit

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

    Exit code disables all exit

    I am using the following code to exit my trade:

    // Using the end of bar exit
    if(this.iUseEOBExit)
    {
    if(

    // After 5 bars have passed since entry, exit the position
    BarsSinceEntry() >= 5

    )
    {
    if(this.iQuantity1 != 0 && tVars.iOrder[1] == null)
    tVars.iOrder[
    1] = ExitShort("eob", string.Empty);

    return;
    }
    }

    However, when I back test, not only does the above exit not work, it appears to disable all other exit modes as well. I get one single trade which enters at the start of the back test period and ends at the end of the back test period.

    I have other exit modes which is based on profit target, loss target and time based targets. All of these get disabled.

    #2
    sandeshrai,

    Are there any messages in log tab when you run the strategy?

    Is it performing according to the logic you set? For example, after 5 bars since the first entry you set to return; This means it will exit OnBarUpdate() routine and not process any logic further down.

    Code:
    if (BarsSinceEntry() >= 5)
    { 
    [COLOR="Red"][B]return;[/B][/COLOR]
    }
    Last edited by NinjaTrader_RyanM1; 06-07-2012, 10:01 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello Ryan,

      Here is the message I am getting in the Log "Error on calling 'OnBarUpdate' method for strategy 'sSandeshV3B/93e8de2f6b634adcaa208befa8d479d9': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntry() method in the context of a multi-time frame and instrument strategy."

      Comment


        #4
        Thanks for the reply. The code you posted matches your description of the strategy behavior. You should correct the issue reported in log tab, and then look into why you are returning out 5 bars after the first entry. Here's where you can see supported overloads for BarsSinceEntry()
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan. That helped

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          666 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X