Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting position and entering position right away.

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

    Exiting position and entering position right away.

    I want be able to exit a long position and then exit that position and then enter another long position right after I exit the Long position. Is this possible? Or I will have to wait for another candle to occur? I put the code below of what I would want, but it does not work of course.

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    // Condition set 1
    if (CrossAbove(MACD(12, 26, 40), MACD(12, 26, 40).Avg, 1))
    {
    ExitLong();
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(MACD(12, 26, 40), MACD(12, 26, 40).Avg, 1))
    {
    ExitLong();
    EnterLong(DefaultQuantity, "");
    }

    }

    #2
    Hello zaro33,

    When using the managed approach, do not call an exit and an entry at the same time.

    If you are short, just call EnterLong(). If you are long just call EnterShort() without calling the exit first.

    The managed approach automatically sends an order to exit the existing position and then sends an order to enter the new position.

    Calling an exit and entry at the same time will not allow the position to update before entry method call and will result in an overfill or the position becoming double in the opposite direction.

    https://ninjatrader.com/support/foru...16#post1036616
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X