Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLong opens up two positions

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

    EnterLong opens up two positions

    In my strategy I am calculating to go long or go short, here is the code snippet I am using .


    if (longSignal && !longOpened)
    {
    ExitShort();
    EnterLong();
    longOpened = true;
    shortOpened = false;
    }
    if ( shortSignal && !shortOpened )
    {
    ExitLong();
    EnterShort();
    longOpened = false;
    shortOpened = true;
    }​

    When strategy starts of it opens 1 position (long or short), when the reversal is called upon it is opening the 2 positions on the opposite direction and the number of positions keeps climing up . At one point it had about 12 positions opened (Thank god I was running on sim account). My original code did not have the ExitLong or ExitShort, added it in to see if I can prevent the addition in the number of positions.

    #2
    Hello,

    Thank you for your post.

    This is expected if you call an Exit and an Enter method on the same bar.

    An order with the name 'Close position' is automatically sent by NinjaTrader when calling an entry order in the opposite direction of the position. Calling an exit order and an entry order at the same time will result in 3 orders being submitted. The Exit order, the Close position order, and the Entry order.

    This will double the position in the opposite direction or cause an overfill. If this is your strategy you are programming, and if you are trying to reverse the position, call the entry in the opposite direction without calling an exit order.

    Please see this forum post for a detailed explanation:


    If you have any other questions, please let me know.​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 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