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

How to avoid EnterShort/EnterLong closing Long/Short position?

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

    How to avoid EnterShort/EnterLong closing Long/Short position?

    I have two criteria in my script, one for going long, one for going short on the same instrument. I want my positions only closed when they reach profit target or stop loss.

    Let's say Long Criteria was triggered and I have a long position. At a later point in time, the Short Criteria is triggered, and EnterShort is being executed. The problem is that EnterShort will fully close my previous Long position, and then open the Short position in full too. I do not want my Long position closed, since it hasn't reached profit target or stop loss yet.

    How do I solve that within the same strategy? As a workaround, I could create two strategies, they would run independently. I'd like to implement it though in a single strategy, so that I could get more accurate backtest statistics on drawdown etc. of the combined strategy.

    #2
    Originally posted by mic414 View Post
    I have two criteria in my script, one for going long, one for going short on the same instrument. I want my positions only closed when they reach profit target or stop loss.

    Let's say Long Criteria was triggered and I have a long position. At a later point in time, the Short Criteria is triggered, and EnterShort is being executed. The problem is that EnterShort will fully close my previous Long position, and then open the Short position in full too. I do not want my Long position closed, since it hasn't reached profit target or stop loss yet.

    How do I solve that within the same strategy? As a workaround, I could create two strategies, they would run independently. I'd like to implement it though in a single strategy, so that I could get more accurate backtest statistics on drawdown etc. of the combined strategy.
    Either do what you have yourself outlines, using 2 independent strategies trading in opposite directions, or else use unmanaged orders.

    When using unmanaged orders, you have complete control. Just remember that you also have none of the safety built-in to NT's managed methods, so you have to take care yourself of everything; especially of everything that can possibly go wrong.

    Comment


      #3
      Hello,

      Thank you for the post.

      In general, we wouldn't suggest using two strategies for a long and short side as there would be a disconnect between the two strategies. A strategy has a virtual position and is not aware of what the other strategy may be doing which can cause lapses in logic.

      For this, I would suggest using the Position object to know when you are in a position to prevent the opposite order logic from happening.

      In your conditions to enter, you could do something like the following:


      Code:
      if(Position == MarketPosition.Flat)
      {
         // place entry logic here
      }
      Both the long and short side orders could go inside this code block to prevent any further orders from being submitted after you are already in a position. Once your stop or target was met and you were Flat again, this code could be run once again.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Jesse View Post
        Hello,

        Thank you for the post.

        In general, we wouldn't suggest using two strategies for a long and short side as there would be a disconnect between the two strategies. A strategy has a virtual position and is not aware of what the other strategy may be doing which can cause lapses in logic.

        For this, I would suggest using the Position object to know when you are in a position to prevent the opposite order logic from happening.

        In your conditions to enter, you could do something like the following:


        Code:
        if(Position == MarketPosition.Flat)
        {
           // place entry logic here
        }
        Both the long and short side orders could go inside this code block to prevent any further orders from being submitted after you are already in a position. Once your stop or target was met and you were Flat again, this code could be run once again.

        I look forward to being of further assistance.
        That is not what the OP requested. He wants to be able to simultaneously, in a more or less virtual manner, hold both long and short positions. The reality, of course, is that in that case, he will be flat. However, there is the advantage that one is then ready to resume whichever trade goes in the desired direction. I speak from experience, because that is exactly what I most often do. I let all trades go to completion one way or another, rather than instantly reverse mid trade.

        Comment


          #5
          koganam, can you explain more?

          I did not think this is possible - simultaneously holding long and short positions in the same instrument?

          Comment


            #6
            Originally posted by janseun View Post
            koganam, can you explain more?

            I did not think this is possible - simultaneously holding long and short positions in the same instrument?
            If one insists on using the Managed Orders system that NT provides, the only real way to do this is to run 2 copies of the strategy: one going long only and the other going short only.

            The other way is to use Unmanaged Orders, in which case, one can pretty much do whatever one wants with orders. Be warned: if you use Unmanaged Orders, you must take care of all possible scenarios, or blowing up the account is a real, undesired, possible outcome.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by tsantospinto, 04-12-2024, 07:04 PM
            4 responses
            62 views
            0 likes
            Last Post aligator  
            Started by michi08, 10-05-2018, 09:31 AM
            3 responses
            740 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by sightcareclickhere, Today, 01:55 PM
            0 responses
            1 view
            0 likes
            Last Post sightcareclickhere  
            Started by Mindset, 05-06-2023, 09:03 PM
            9 responses
            259 views
            0 likes
            Last Post ender_wiggum  
            Started by Mizzouman1, Today, 07:35 AM
            4 responses
            18 views
            0 likes
            Last Post Mizzouman1  
            Working...
            X