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 NRITV, Today, 01:15 PM
    2 responses
    8 views
    0 likes
    Last Post NRITV
    by NRITV
     
    Started by frankthearm, Today, 09:08 AM
    7 responses
    31 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by maybeimnotrader, Yesterday, 05:46 PM
    5 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by quantismo, Yesterday, 05:13 PM
    2 responses
    19 views
    0 likes
    Last Post quantismo  
    Started by adeelshahzad, Today, 03:54 AM
    5 responses
    33 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X