• 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 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 jerblaster23, Today, 03:42 PM
    0 responses
    2 views
    0 likes
    Last Post jerblaster23  
    Started by brian meade, Today, 01:39 PM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by Johnny Santiago, Today, 12:20 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by NinjaTrader_Brandon, Today, 10:24 AM
    0 responses
    50 views
    0 likes
    Last Post NinjaTrader_Brandon  
    Started by ptertich, Today, 07:56 AM
    2 responses
    15 views
    0 likes
    Last Post Johnny Santiago  
    Working...
    X