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

Submit multiple orders & Restrict Orders

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

    Submit multiple orders & Restrict Orders

    Hello NinjaTraders,

    I have several questions regarding a strategy I am currently working at.

    1.) On the start of each new day, I want to submit a Long Limit as well as a Short Limit order, which cancel each other as soon as one is being executed. However, I can only submit one order at a time, depending which one I put first in the code.

    Code:
    EnterLongLimit(DefaultQuantity, Low[0], "");
    EnterShortLimit(DefaultQuantity, High[0], "");
    2.) I would like to restrict any order, so that it only gets executed if the preceding order in the same direction (long/short) wasn't closed by a stop loss. However, this should only be true until the end of the trading session (i.e. end of day) and reset afterwards.

    3.) If the profit target of the current position is met, the strategy waits until the next bar to execute a limited order (which happens to be on the same level as the profit target). Is there a way, to simultaneously execute the profit target as well as the limit order?

    I would highly appreciate any help on these three questions, since my programming knowledge is rather limited.

    Regards,

    Sepp

    #2
    Hello Sepp,

    1. You can only enter order in different directions using the Unmanaged Approach. Using the Managed Approach will have order handling rules against this.



    2. You may want to create a new variable to check to see if the Stop Loss order was filled inside of the OnOrderUpdate and then reset the variable when the "Bars.FirstBarOfSession" is true:

    FirstBarOfSession: http://www.ninjatrader.com/support/h...rofsession.htm

    Here is a reference sample on working with OnOrderUpdate that you may view.
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    3. What is your CalculateOnBarClose (COBC) set to?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello JC,

      Thank you for your ridiculously fast answer

      1. So the easiest solution is to write a strategy for each direction (long/short), since it is not possible to combine them in one (besides the unmanaged approach)?

      2. Even with your link, I am not sure how to adress the Stop Loss precisely. I think of referring to the "Stop Loss" exit name, once the order gets executed. In this case, I guess, the OnExecution() task is suited better. But is there a command to address the exit name of an order?

      3. It is on true. That should explain my problem, so thank you for that!

      Regards,
      Sepp

      Comment


        #4
        Hello Sepp,

        1. Correct.

        2. That would work as well yes. You may use "execution.Name" to get the order name of the execution.

        Example:

        Code:
        protected override void OnExecution(IExecution execution)
        {
        	if("Long1" == execution.Name)
               //Do Something
        }


        3. With COBC set to true, NinjaTrader is only going to run your code inside of OnBarUpdate() once at the close of the bar so if you would like to have two orders possible fire off you may want to change this to false, so NinjaTrader is processing your OnBarUpdate() on each incoming tick of data.

        Last edited by NinjaTrader_JC; 08-23-2013, 10:13 AM.
        JCNinjaTrader Customer Service

        Comment


          #5
          Thank you JC, I finally managed to resolve all of my problems!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DawnTreader, 05-08-2024, 05:58 PM
          7 responses
          25 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by sgordet, Today, 05:24 AM
          0 responses
          4 views
          0 likes
          Last Post sgordet
          by sgordet
           
          Started by royhagerman, Today, 04:30 AM
          0 responses
          1 view
          0 likes
          Last Post royhagerman  
          Started by haas88, 03-21-2024, 02:22 AM
          18 responses
          208 views
          0 likes
          Last Post haas88
          by haas88
           
          Started by Board game geek, Today, 02:20 AM
          0 responses
          7 views
          0 likes
          Last Post Board game geek  
          Working...
          X