Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is the script allowed to submit a take profit order first and then enter into?

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

    Is the script allowed to submit a take profit order first and then enter into?

    Hi Ninjatrader Engineers,

    I'm using script editor to create my strategy. I want to, for example, enter into a long position with a profit targe. To make sure the enter price can be captured, I hope to submit an exit order with a higher price first as the exit point, and then submit the enterlonglimit() order with current price. I'm not sure if it is possible to submit the two orders at the same time as shown below:
    I tried the following two expressions but neither works. Do you know how to submit the enter and take profit order at the same time? Or I have to wait for the long position established? Thanks!


    #1

    if(GetCurrentAsk(0)==Close[0]&&Purchase_flag==1)
    {
    Purchase_flag=2;
    EnterShortLimit(0,Close[0]+1,@"S1");
    EnterLongLimit(0, Close[0], @"Long1");
    Print("Purchase_flag0");

    }



    #2
    if(GetCurrentAsk(0)==Close[0]&&Purchase_flag==1)
    {
    Purchase_flag=2;
    ExitLongLimit(Close[0]+1,"");
    EnterLongLimit(0, Close[0], @"Long1");
    Print("Purchase_flag0");

    }​

    #2
    Hello AndrewDu,

    Thank you for your post.

    Please note that the managed approach (used by the Strategy Builder) automatically reverses the position when an entry is called in the opposite direction.

    NinjaTrader will automatically submit a Close position order to close the previous position before entering the new position.


    Your script is currently calling two methods opposite of each other on the same bar, at the exact same time.


    Be sure not to call an exit and then an entry on the same bar. This would cause the position to become double the opposite direction or cause an overfill.

    Please see this forum post which explains in detail:



    You may also want to review the Managed Approach Internal Order Handling rules:

    HTML Code:
    https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandl ingRulesThatReduceUnwantedPositions

    Calling EnterShortLimit() and EnterLongLimit() at the same time violates the internal order handling rules.


    You will need to modify the logic of your script to make sure you are not (1) calling two entry methods in the opposite direction at the same time, effectively reversing your position and (2) calling an entry and an exit on the same bar.

    Please let me know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    69 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    42 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    24 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    27 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    54 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X