Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Batch OCA orders on session close

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

    Batch OCA orders on session close

    Hi,

    I have a 1min BarOnClose=false strategy that I have been running without problems on a realtime basis.

    I would like to change the functionality to use it simply as batch uploader of bracket-orders to Interactive Brokers.
    I would like to run it after the close as this is what I add/subtract from to derive the respective StopIn Long/Short levels.

    I suppose the best way to run it (please offer alternatives) is as a backtest on a folder of the Tradeable instruments.
    It would then fire the OCA groups acrros to IB after each instrument test.

    Which order functions would I best use to place contingent OCA's?
    Which feature/flafg do I use to allow the orders to be delivered as Inactive so they can be checked in the IB Trrader Workstation before manually being activated by a trader?

    protected override void Initialize()
    {
    Add(PeriodType.Day, 1);

    CalculateOnBarClose = false;
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (Bars.FirstBarOfSession)
    {
    firstDailyOpen = Open[0];
    lastDailyClose = Closes[1][0];
    }

    Because I am putting the orders in before the next open in the case of Equities, and after in the case of the 24hr FX market, I want to check if the last bar read was the end of the final daily session or start of the next incomplete session

    Can you please suggest which functions to look at.

    Thanks

    #2
    Hello abfc123,

    Unfortunately there's no way to place contingent or inacitve orders. Once you route an order to Interactive Brokers, they handle it and orders are typically in a working or accepted state.

    Any end of session identification must be custom coded, using Time functions or BarsSinceSession(). There is not a built in method or property to identify last bar of session.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So there is no way to replicate Bracket orders in NT?

      Also, to perform an action at the end of the backtest(ie after last bar), is there a way to test for this condition?


      if (CurrentBar == Count-1) gives me multiple lines.

      Thks

      Comment


        #4
        There's no way to submit inactive orders or orders awaiting approval in TWS. If this fits with your understanding of bracket, then it's not possible with NinjaTrader.

        You can do some actions at the end of a strategy run in OnTermination()


        You can also work with Historical property. This returns true on Historical bars and false on real time bars.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Regarding using OnTermination(), I am backtesting on a list of instruments. I want to know when it has completed the backtest on each separate instrument in the list.
          Is it correct that there would be one strategy run, and therefore a call to the OnTermination() method for each instrument?

          Thks

          Comment


            #6
            Regarding using OnTermination(), I am backtesting on a list of instruments. I want to know when it has completed the backtest on each separate instrument in the list.
            Is it correct that there would be one strategy run, and therefore a call to the OnTermination() method for each instrument?

            Thks

            Comment


              #7
              Correct - OnTermination() will be processed for each instrument in the list.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thanks Ryan.

                So after each run , I want to check if the current date is within 5mins of the date of the last session close.
                If so, and also flat, I want to try emulating Bracket setup

                LongTarget2
                LongTarget1
                LongStopIn
                LongStopLoss

                as resting orders

                Is this viable?

                Thks

                Comment


                  #9
                  Sorry, I don't follow here. A backtest is only run on historical data, so you won't be able to use it to submit live working orders.

                  OnTermination is run once the strategy has completed, so you can't use this method to submit orders.

                  You may be looking for an ATM strategy rather than a NinjaScript strategy. These are targets and stop losses that are automatically submitted once the entry order has been filled. You define your target and stop losses before the entry order is submitted.


                  If you want to use a NinjaScript strategy to submit this particular combination of orders, you would need to use our unmanaged order system.


                  You can make checks with the current date / time compared to the time stamp of a bar.
                  Ryan M.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
                  80 responses
                  19,666 views
                  5 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by adeelshahzad, Today, 03:54 AM
                  2 responses
                  15 views
                  0 likes
                  Last Post adeelshahzad  
                  Started by dappa, Today, 09:18 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by bill2023, Yesterday, 08:51 AM
                  5 responses
                  24 views
                  0 likes
                  Last Post bltdavid  
                  Started by frankthearm, Today, 09:08 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X