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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X