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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        47 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        15 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        21 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X