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 NullPointStrategies, Today, 05:17 AM
    0 responses
    41 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X