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

Simultaneous Long & Short trades on different instruments from the same strategy

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

    Simultaneous Long & Short trades on different instruments from the same strategy

    Is it possible to have the same strategy place long and short trades simultaneously but on different instruments? I've tried doing some testing and it doesn't appear to work...I couldn't find anything in the forum or manual to suggest that it is possible.

    If it's not possible could you also then confirm that the only way to place simultaneous long & short trades on different instruments would be using different strategies i.e. one strategy for long trades and one strategy for short trades?

    Thanks.

    #2
    Hello newuser,
    Thanks for your post.

    You can submit an order to any BarsInProgress that was added to the script by using the entry order method overload that contains barsInProgressIndex.
    Code:
    EnterLong(int barsInProgressIndex, int quantity, string signalName)
    Last edited by NinjaTrader_JoshG; 05-02-2019, 09:19 AM.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the prompt reply. I can place the trades using EnterLong and EnterShort with the three overloads as per your reply but as soon as I try to place stop and limit orders (using SetStopLoss and SetProfitTarget) the strategy runs to error. It closes out my trades and disables the strategy. I took a screenshot of the error message for reference (the strategy is just called 'Blank' FYI)

      Is there a way I can set a stop and target order once the trades are open without causing the strategy to crash? I was using signal names to try link the stop/profit orders to their respective entry orders but the strategy still crashed.
      Attached Files

      Comment


        #4
        Originally posted by newuser View Post
        Is there a way I can set a stop and target order once the trades are open without causing the strategy to crash?
        Are your stop loss and profit target values static?
        Why not call SetStopLoss and SetProfitTarget in Initialize, before the trade is opened?

        EDIT:
        Carefully read the "Definition" section for these code functions. Note how the first bullet
        suggests calling these functions just once, inside Initialize (although I suspect OnStartUp
        will work equally well). Are you able to try that?


        Last edited by bltdavid; 05-02-2019, 09:19 AM. Reason: Add URLs from documentation

        Comment


          #5
          The stop and profit target values are not static so I can't set them in Initialize()

          But even if the stop and target were static I'm not sure that would help. It appears as though NT7 thinks the stop/profit on the buy order conflict with/somehow apply to the sell order (and viceversa), even though the long and short trades are on different instruments and they have unique signal names ("buy"+Instrument.Fullname and "sell"+Instrument.Fullname)

          Comment


            #6
            Originally posted by newuser View Post
            But even if the stop and target were static I'm not sure that would help.
            Disregard the comments in my second paragraph above. I did a test using a static stop & profit set in Initialize() and you are right - it allows simultaneous long & short trades in different instruments from the same strategy. Only problem is...I don't use a static stop. There has to be a way to make this work...surely...

            Comment


              #7
              newuser,

              You would submit your dynamic stop loss to another instrument just like you would submit one to the primary instrument. Simply tie the orders together by signal name.

              Can you show us some code that demonstrates what you are doing? Also if you prefer, you can send me the script through email.

              Josh G.NinjaTrader Customer Service

              Comment


                #8
                Yeah...I realized I made a mistake in my code. I had a plus instead of a minus(!) so that's why the stop/target orders were giving me grief. <slaps hand on forehead> Never mind!!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Stanfillirenfro, Today, 07:23 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                2 responses
                21 views
                0 likes
                Last Post cmtjoancolmenero  
                Started by olisav57, Yesterday, 07:39 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by cocoescala, 10-12-2018, 11:02 PM
                7 responses
                944 views
                0 likes
                Last Post Jquiroz1975  
                Started by oviejo, Today, 12:28 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X