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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      57 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      19 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      9 views
      0 likes
      Last Post cre8able  
      Working...
      X