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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    52 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    276 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X