Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by trilliantrader, Today, 08:16 AM
    2 responses
    6 views
    0 likes
    Last Post trilliantrader  
    Started by samish18, Today, 08:31 AM
    1 response
    1 view
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by Creamers, 09-08-2023, 10:26 AM
    6 responses
    157 views
    0 likes
    Last Post JonyGurt  
    Started by funk10101, Today, 08:14 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by bill2023, Yesterday, 08:51 AM
    3 responses
    22 views
    0 likes
    Last Post bltdavid  
    Working...
    X