Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

exiting a position

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

    exiting a position

    Hey All,
    I haven't come across any pre defined functions that will stop you out and exit a position only if bar[0] closes above/below some value---or am i just missing it? not looking for just a cross of that value.

    if not I think i could just write my own condition at the beginning of onBarUpdate() that says something like:

    if ( [we have a position] )
    if Close[0] > myValue
    exit position;


    Second question would be, what is the proper way to reference a trade in action, for that if statement to determine whether or not we do have a position.

    Thanks!

    #2
    exiting a position continued

    So I wrote the following in the beginning of onBarUpdate()

    if (Position.Quantity > 0)
    {
    if (Position.MarketPosition.ToString() == ("Short"))
    {
    if (Close[0] > stopLoss)
    {
    Print("triggering stop loss, close: "+Close[0]+" > stoploss "+stopLoss);
    ExitShortLimit(GetCurrentAsk(), "OpenRangeShort");
    }
    }


    when i backtest this I get the following in output window:

    IM SHORT AT 58.75 on 1/4/2012 11:00:00 AM with TARGET: 58.522
    triggering stop loss, close: 58.9 > stoploss 58.86
    triggering stop loss, close: 59.01 > stoploss 58.86


    so it should be putting in the order to close the position on the first candle close at 58.90 but its not getting through until next time around which causes me to exit at 59.01, 11 cents higher then i would want too. investigating why order does not get processed on that first bar....

    Comment


      #3
      slocumtrader,

      This may be due to intrabar granularity.

      Please see the following reference : http://www.ninjatrader.com/support/f...ead.php?t=6652

      Please let me know if I may assist further.
      Adam P.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      80 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      45 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      29 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      32 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      66 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X