Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with ExitLongStop

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

    Issue with ExitLongStop

    Hi i have an issue with my strategy that doesnt exit my trade.
    I don't want to use any Stop or Targets as i just want to exit my trades after X bar from entry.
    Here below the code.

    Any idea whats wrong??


    Code:
    protected override void OnBarUpdate()
            {
             if (xCustomIndicator.TriggerLow[0] > 60)
                        {        
                         barNumberOfOrder = CurrentBar;                        
                         EnterShortStop(1, Close[0]-1*TickSize,"ShortEntry"); 
                        }
              }
               int NbBars = CurrentBar - barNumberOfOrder;
               if (NbBars==10)                      
                {    
                    if (Position.MarketPosition == MarketPosition.Long) 
                    {
                        ExitLongStop(Close[0]-1,"LongEntry");    
                    }
                    if (Position.MarketPosition == MarketPosition.Short) 
                    {
                        ExitShortStop(Close[0]+1,"ShortEntry");    
                    }
                }
          }

    #2
    Hello cbadr,

    Thanks for your post.

    The best way to ensure that you exit your position would be to use a market order directly such as ExitLong("LongEntry") or ExitShort("ShortEntry").

    The ExitLongStop() or ExitShortStop() requires that price hits the specified stop level to then market order out. Looking at the values in your code "Close[0]-1" could be the source of issues as the code is taking the close value of the current bar and subtracting a price value of 1. I'm not sure of your intent of what instrument a value of 1 would be applicable. If you intend that to be a single tick (tick being the smallest price movement in any instrument) then you would need Close[0] - 1 * TickSize. Note: if you are using CalculateOnBarClose=true then that means you are assessing price based on the last closed bar and not the current price so the actual price may be above or below that trigger price and cause the orders to be ignored or otherwise generate an error, both of which would be detailed in the "log" tab of the NinjaTrader7 control center.

    Additional information, You may want to look at BarsSinceEntry() as a means to determine the number of bars since entry to trigger your exits (nothing wrong with what you have, just another way to do the same thing). https://ninjatrader.com/support/help...sinceentry.htm

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X