Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Reverse position entry + exit position = double entry

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

    Reverse position entry + exit position = double entry

    Hi,

    I have a problem with the strategy I am running.
    There is possibility to get two entries, one from entry position and one from exit position (overfill?) and the next exit position can't handle both of them.

    I have now added "position.quanitity == 0" to my code inside of if sentence that blocks entries if there is already entry inside the strategy.
    This will force strategy wait "flat position" before it can entry again and fixes the double entry problem. But I am losing some potential entries because of it.

    Is there away block exit position if reverse position entry happens as it closes the existing position already.
    Can I add "position.quanitity > 0" to exit position if sentence or how would you approach this?

    Br
    Gelotuz

    #2
    Hello Gelotuz,

    Thank you for your note.

    When using the managed approach, NinjaTrader will automatically flip the position from long to short or vice versa if a position is seen when calling an Entry order in the opposite direction.

    Calling ExitLong() and EnterShort() on the the same bar is guaranteed to cause undesired behavior.

    When calling an entry method in the opposite direction of your position this will cause your position to be reversed. NinjaTrader will automatically submit an order to close your existing position and then enter an order to enter you into the opposite position.

    If you exit and then call an entry method in the same run of OnBarUpdate, the OnPositionUpdate() will not have yet run and NinjaTrader will not yet know that your position is closed. This will cause both actions to complete and end up sending 3 orders. The first order is the exit position from your exit method, the second order is to close the position from NinjaTrader automatically reversing your position, the third order is to enter you into the opposite position.

    The result is that either the script will double the quantity when it reverses or it will cause an overfill and stop the script.

    For example, here's
    11/1/2019 0:05:00,Order,Order='632966e1a4544ec9b05e854aff7fd 7a0/Sim101' Name='ExitLong0' New state=PendingSubmit Instrument='BABA' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='', - This is the exit order submitted by an ExitLong() method

    11/1/2019 0:05:00,Order,Order='a960840f15cd4c39992d648f41631 608/Sim101' Name='Close position' New state=PendingSubmit Instrument='BABA' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='', - This is the automatic order NinjaTrader places to close the existing position

    11/1/2019 0:05:00,Order,Order='781de5123a054e319f4cd4abe17ef 790/Sim101' Name='Short0' New state=PendingSubmit Instrument='BABA' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='', - This is the entry to the opposite position placed with the EnterShort() method

    If you ensure that you're not calling an exit method on the same iteration through On Bar Update, you'll avoid this.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by alifarahani, Today, 09:40 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by RookieTrader, Today, 09:37 AM
    4 responses
    17 views
    0 likes
    Last Post RookieTrader  
    Started by PaulMohn, Today, 12:36 PM
    0 responses
    4 views
    0 likes
    Last Post PaulMohn  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    39 views
    0 likes
    Last Post love2code2trade  
    Started by junkone, Today, 11:37 AM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X