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 adeelshahzad, Today, 03:54 AM
      4 responses
      25 views
      0 likes
      Last Post adeelshahzad  
      Started by merzo, 06-25-2023, 02:19 AM
      10 responses
      823 views
      1 like
      Last Post NinjaTrader_ChristopherJ  
      Started by frankthearm, Today, 09:08 AM
      5 responses
      17 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      43 views
      0 likes
      Last Post jeronymite  
      Started by yertle, Today, 08:38 AM
      5 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X