Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit after set # of bars

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

    Exit after set # of bars

    I am having trouble getting my trade to exit after a set # of bars:

    Here is my code for exit:

    if(this.iUseEOBExit)
    {
    if(



    // Exit after set number of bars
    BarsSinceEntry() == this.iBARSSINCEENTRY ||
    // Exit if bar closes below entry price + some offset
    Close[0]<Position.AvgPrice - this.iTICKSIZE*TickSize

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

    return;
    }
    }

    If I comment out the 'BarsSinceEntry' portion, the other exit which is based on bar close below entry price works. What am I doing wrong? Thanks in advance

    #2
    Hello,

    What is the variable : iBARSSINCEENTRY set to?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Exit after set # of bars

      I have set it to 4. I expect it to be in the range of 2 - 10

      Comment


        #4
        Hello,

        Could you possible post more of your code here? I am not seeing anything immediately obvious here. You can also attach the code itself to your post if that is easier.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, Yesterday, 10:06 AM
        0 responses
        20 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        18 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        14 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        9 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        38 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X