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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 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