• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Venom, Today, 01:05 PM
      0 responses
      1 view
      0 likes
      Last Post Venom
      by Venom
       
      Started by Dert66, Today, 12:11 PM
      0 responses
      6 views
      0 likes
      Last Post Dert66
      by Dert66
       
      Started by jjanguda, Today, 10:04 AM
      0 responses
      192 views
      0 likes
      Last Post jjanguda  
      Started by sambo81, Today, 09:20 AM
      1 response
      12 views
      0 likes
      Last Post sambo81
      by sambo81
       
      Started by TopGunNote, 05-14-2019, 01:12 PM
      3 responses
      78 views
      0 likes
      Last Post dpaulw
      by dpaulw
       
      Working...
      X