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.
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by lightsun47, Today, 03:51 PM
    0 responses
    5 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    8 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    44 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    13 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    9 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X