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

Some doubt about order management

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

    Some doubt about order management

    Hey Ninjas,

    I need some help about order management, I have read the help page, but there is a point i am not sure about.

    I am currently running a multi instrument strategy, and under some conditions, I want to submit orders on each instrument. For now, I use this syntax:

    EnterLong(Which Instrument ,How many, signal name);

    and I do something like that for every instrument I have. When I try to use:

    if (BarsInProgress == compteur){
    EnterLong(How many, signal name);
    }

    the result is not the same. What is the difference between the two?

    Moreover, let's say I have 2 Long position on an instrument, and now my algorithm tell me to be flat. Currently, I do:
    ExitLong("", signal name);
    and when my algorithm tell me to have 1 short position, I use:
    Exitlong("", signal name);
    EntryShort(Instrument, 1, signal name);
    Is it correct? What about going from 2 Long to 1 Long? And to 3 Long?
    I keep last actions required by my algorithm in an int array...

    Thank you.

    #2
    bigben,

    The first option would submit an order to the instrument from the data series.

    The second option would wait until the OnBarUpdate() method is called for that specific data series before it enters the order.

    Here is a reference sample on scaling out of a position.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      Say I'm working on a 45 minutes time frame for all instruments. I need to wait to have all data to submit orders. How can I do that? Can I check if OnBarUpdate() has been called for all instruments?

      Thank you

      Comment


        #4
        I need to wait to have all data to submit orders
        What exactly do you mean by that.If you give us some more detail on specificly what you are trying to do we may be able to offer some additional information.

        OnBarUpdate() is called for each series and each change in the bar. Each OnBarUpdate call has an BarsInProgress and each one of these are called individually.

        They are their own separate units until you add code to take action based on them.

        In the case you describe the best idea I have for you is to set a flag for all OnBarUpdate()'s to set to true. Once all OnBarUpdate()s flag to true then you can take some action.

        Waiting for confirmation for ALL BIP's would delay your entry an OnBarUpdate() call most likely.

        -Brett

        Comment


          #5
          Thank you Brett.

          What I do is a computation on historical closes in a multi instrument strategy. Indeed, even if I can have the price of every instrument 10 second before the bar close, I think it would be ok. I tried to do it with CalculateOnBarClose = false, coupled with if (DateTime.Now < Time[0].AddSeconds(-10)), but when I try to access the price with Closes[i][0], is it really the last tick for all instruments? And Closes[i][1] is the previous close?

          Then I can use a flag to prevent the computation from being done twice.

          It would be simplier for me even to store data whenever I want this way. So I can create my own bar, in order to avoid different bars for different instruments... For example, YG and TF don't have the same 45 minutes bars...

          I really appreciate your help.
          Last edited by bigben1; 05-07-2012, 02:13 PM.

          Comment


            #6
            Originally posted by bigben1 View Post
            I think it would be ok. I tried to do it with CalculateOnBarClose = false, coupled with if (DateTime.Now < Time[0].AddSeconds(-10)), but when I try to access the price with Closes[i][0], is it really the last tick for all instruments? And Closes[i][1] is the previous close?

            Then I can use a flag to prevent the computation from being done twice.
            I really appreciate your help.

            With calculate on bar close = false, Closes[i][0] will always be the latest tick. OnBarUpdate() would be called once every incoming tick.

            I am not sure what you mean here as far as preventing calculations from being done twice. Each calculation will be unique if you have CalculateOnBarClose() = false for those series with 0 indices since OnBarUpdate() would be called for each tick.

            You could try the following reference sample, it may be what you are looking for.

            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Thanks, but it is not really what I'm looking for. Sorry for my poor English...

              Let's consider an example. I would like to trade 5 Instruments. To do so, my algorithm need historical data. But my problem today is that those historical data are not synchronized, and if I try to wait for the last OnBarsUpdate with a flag or something like that, it would delay my trade. So what I need is to store data every "real" 45 minutes for example. So, once I have enough historical data, my algorithm can pass order every 45 minutes on these 5 instruments.

              Am I clear enough?

              Comment


                #8
                bigben,

                You can use the term :

                if( Historical )
                {

                }

                To check if you are on a historical bar. For CalculateOnBarClose = false, I would suggest using the BarsInProgress along with FirstTickOfBar to check when a new bar just opened. This would be one tick after the closing of the last bar.

                For example :

                If ( BarsInProgress == 0 && FirstTickOfBar)
                {

                // OnBarUpdate() was called for the primary (chart) instrument
                // do something

                }

                If ( BarsInProgress == 1 && FirstTickOfBar)
                {

                // OnBarUpdate() was called for the first added instrument
                // do something

                }

                If ( BarsInProgress == 2 && FirstTickOfBar)
                {

                // OnBarUpdate() was called for the second added instrument
                // do something

                }

                I believe this is what you are asking, but feel free to let me know if this is not sufficient. I would be happy to make more suggestions.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you, I'll try something like this, but "do something" should be "do nothing". I need to wait for all updates, and I guess I can deal with that with a flag. What is the idea with placing a FirstTickOfBar in the condition? Isn't it the definition of OnBarsProgress?
                  Would it be possible to create my own Data series?

                  Thank you again

                  Comment


                    #10
                    bigben,

                    You can create your own dataseries.



                    As far as the first tick of bar, this is built in for use when CalculateOnBarClose = false, since OnBarUpdate() would be called multiple times per bar as its updated tick by tick for real time data.

                    BarsInProgress can be checked to see which series is being updated, however it doesn't guarantee this data series is being updated on the closing of the bar since it can be updated tick by tick. FirstTickOfBar can be used to check if a new bar just opened when CalculateOnBarClose = false.
                    Adam P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Radano, 06-10-2021, 01:40 AM
                    19 responses
                    605 views
                    0 likes
                    Last Post Radano
                    by Radano
                     
                    Started by KenneGaray, Today, 03:48 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post KenneGaray  
                    Started by thanajo, 05-04-2021, 02:11 AM
                    4 responses
                    470 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Started by aa731, Today, 02:54 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post aa731
                    by aa731
                     
                    Started by Christopher_R, Today, 12:29 AM
                    0 responses
                    11 views
                    0 likes
                    Last Post Christopher_R  
                    Working...
                    X