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

Managed Approach reverse position and resubmit Exit Orders issue

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

    Managed Approach reverse position and resubmit Exit Orders issue

    Hi NT,

    I have come across the issue using the Managed Approach when swapping positions with existing exit orders attached to previous position.
    It appears the "Close Position" is generated but the OnPositionUpdate() has not yet run yet and does not recognise the new position, so when ExitLongStopMarket & ExitShortStopMarket are then called based on a filled position, i then get the error message Reason='This was an exit order but no position exists to exit'

    So how do i swap a position and wait to re-submit the exit orders to the new position after the onPositionUpdate is called? There are no arguments in onPoisitonUpdate to pass the order name etc to track this position, is there an example of swapping a position using exit orders under the managed approach i have missed? All the examples i have seen only have 1 direction and do not swap.

    Thankyou for your help.
    Regards,

    #2
    Hello mr_trade,

    Thank you for your post.

    Where within your code are you submitting your protective exit orders?

    Could you give a simplified example of your current code?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      thankyou for your quick reply. I’m submitting the exits from OnExecutionUpdate. I gather this is the problem due to the close position not taking into affect till OnPositionUpdate but the new entry is already submitted before the close complete. Is onExecution not the best place to place exits with the managed approach as it would be with the unmanaged?

      Thank you

      Comment


        #4
        Hello mr_trade,

        Thank you for your reply.

        I would suggest rather than using the Order name to track the entry order that you save the entry Order object to a variable in OnOrderUpdate. This way, you can check in OnExecutionUpdate that the order that's processing is the entry order and not the previous order, and submit the protective orders.

        I'd take a look at this example from our help guide that illustrates this:



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

        Comment


          #5
          Hi there,

          Yes this is exactly what I’m doing. The example provided only demonstrates long entry so would not replicate the issue with the swap. When position is swapped the “close position” is created and submit for closing. At the same time on execution is filled for the new position but because the previous position is not closed yet and the new position isn’t open via onPositionUpdate the error message appears saying no position exists yet. So I can’t attach the exit orders to the new position in onExecutionUpdate because it’s too early as stated in the manual, so how do you get around this workflow issue with the managed approach? With unmanaged you would check that the orders are cancelled first then simply reverse the position by doubling up but you can’t do this with managed as it seems to have a built in workflow?

          thank you for your help.

          Comment


            #6
            Hello mr_trade,

            Thank you for your reply.

            Who is your broker? There are known issues with some brokers in tracking position with the managed approach as they do not guarantee the order in which OnOrderUpdate/OnPositionUpdate/OnExecutionUpdate.occurs.

            That being said, I would like to take a look at a reduced version of your script. Any logic unnecessary to reproduce should be removed. Please export the script from Tools > Export NinjaScript Add-on. Do not check the box to export as a compiled assembly or I will not be able to review the code. If you prefer not to post it publicly here, you may send it to scriptingsupport [at] ninjatrader [dot] com with 2910586 ATTN Kate W. in the subject line and a link to this post in the body of the email.

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi Kate,
              Sorry for delay, i have stripped the code back to its core to show you the issue and have emailed over the script.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Option Whisperer, Today, 09:55 AM
              0 responses
              1 view
              0 likes
              Last Post Option Whisperer  
              Started by geddyisodin, 04-25-2024, 05:20 AM
              8 responses
              58 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by halgo_boulder, 04-20-2024, 08:44 AM
              2 responses
              21 views
              0 likes
              Last Post halgo_boulder  
              Started by mishhh, 05-25-2010, 08:54 AM
              19 responses
              6,189 views
              0 likes
              Last Post rene69851  
              Started by gwenael, Today, 09:29 AM
              0 responses
              5 views
              0 likes
              Last Post gwenael
              by gwenael
               
              Working...
              X