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 PhillT, 04-19-2024, 02:16 PM
      4 responses
      31 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by ageeholdings, 05-01-2024, 05:22 AM
      5 responses
      36 views
      0 likes
      Last Post ageeholdings  
      Started by reynoldsn, Today, 02:34 PM
      0 responses
      8 views
      0 likes
      Last Post reynoldsn  
      Started by nightstalker, Today, 02:05 PM
      0 responses
      15 views
      0 likes
      Last Post nightstalker  
      Started by llanqui, Yesterday, 09:59 AM
      8 responses
      30 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Working...
      X