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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X