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 rbeckmann05, Yesterday, 06:48 PM
    1 response
    12 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Working...
    X