• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged Order

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

    Unmanaged Order

    Hello,

    This is my first post after my first week of battling (unsuccessfully) with Unmanaged Order.

    I have a number of what must be incredibly basic questions for the more experienced programmers. I would appreciate your help enormously.

    1. Are there a set of basic things you must include/not overlook in the framework of the code for it to work? (The code compiles and the enabled box in the strategy section now checks and remains checked, but no trades are being executed)

    2. What code could I use for the price of the first tick of a session (Not using CurrentDayOHL())? (I want to use this as a reference price from which I will base other orders)

    I will start with just these.

    Thanks very much in advance.

    #2
    Hello Griberit,

    Thank you for writing in. For your first question, could you please confirm if your strategy is yellow or green in the strategies tab of the control center after enabling it?

    This is the only definition for the SubmitOrder() method, so you will need to use all of these parameters each time you call it:
    Code:
    SubmitOrder(int barsInProgressIndex, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string ocoId, string signalName)
    For your second question, you could use something like the following:
    Code:
    #region Variables
        private double sessionStartPrice = 0.0;
    #endregion
    protected override void Initialize()
    {
        CalculateOnBarClose = false;
    }
    protected override void OnBarUpdate()
    {
        if(FirstBarOfSession && FirstTickOfBar){
            sessionStartPrice = Close[0];
        }
    }
    Or another way:
    Code:
    #region Variables
        private double sessionStartPrice = 0.0;
    #endregion
    protected override void Initialize()
    {
       Add(PeriodType.Tick, 1);
       CalculateOnBarClose = true;
    }
    protected override void OnBarUpdate()
    {
        if(BarsInProgress == 1 && FirstBarOfSession)
        {
            sessionStartPrice = Close[0];
        }
        if(BarsInProgress == 0)
        {
            //rest of your logic here
        }
    }
    Please let me know if you have any questions or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Michael,

      Thanks a lot for your prompt reply.

      Here is the code I am trying to get to work. I am using tick data. I am trying to enter stop entry order a certain distance away from the open price of a session, (eg here 6 ticks), with a stop the same distance away from the open price on the other side and a limit profit target 18 ticks from the open price. I am starting with just the long side just so I get something up and running in unmanaged order, before doing both sides. At the moment it is not compiling as it is telling me that FirstBarOfSession does not exist in the current context.

      Comment


        #4
        publicclass Forumexample : Strategy
        {
        #region Variables


        privatedouble sessionStartPrice = 0.0;
        private IOrder longOrder;
        private IOrder longTarget;
        private IOrder longStop;

        #endregion
        ///<summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        ///</summary>
        protectedoverridevoid Initialize()
        {
        Unmanaged =
        true;
        CalculateOnBarClose =
        false;
        longOrder =
        null;
        longTarget =
        null;
        longStop =
        null;
        }

        Comment


          #5
          protectedoverridevoid OnBarUpdate()
          {
          if (FirstBarOfSession && FirstTickOfBar)
          {
          sessionStartPrice = Close[
          0];
          }

          longOrder = SubmitOrder(
          1, OrderAction.Buy, OrderType.Stop, 1, sessionStartPrice + TickSize*6, sessionStartPrice + TickSize*6, "", "EnterLongOrder");

          longTarget = SubmitOrder(
          1, OrderAction.Sell, OrderType.Limit, 1, sessionStartPrice + TickSize*18, sessionStartPrice + TickSize*18, "", "EnterLongTarget");

          longStop = SubmitOrder(
          1, OrderAction.Sell, OrderType.Limit, 1, sessionStartPrice - TickSize*6, sessionStartPrice - TickSize*6, "", "EnterLongStop");
          }

          I hope this is clear.

          Thanks so much in advance.

          Comment


            #6
            Hello Griberit,

            My apologies for the syntactical error. It should be Bars.FirstBarOfSession as opposed to just FirstBarOfSession. More information can be found in out help guide: http://ninjatrader.com/support/helpG...stBarOfSession

            Please let me know if you continue to experience difficulties.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              Michael,

              I am now printing the open for the day. Thank you.

              I am having issues submitting any orders.

              If I comment out the longOrder = SubmitOrder(...) bit, there is no error and the strat turns green. I am now just trying to include longOrder but then there is an issue:

              **NT** Error on calling 'OnBarUpdate' method for strategy 'PJ/a0cd9e2864224373a1bb41f8229848e6': Index was outside the bounds of the array.

              Currently this is the extent of my code: protectedoverridevoid Initialize()
              {
              CalculateOnBarClose = true;
              Unmanaged = true;
              ExitOnClose = true;

              }
              ///<summary>
              /// Called on each bar update event (incoming tick)
              ///</summary>
              protectedoverridevoid OnBarUpdate()
              {

              currentSessionOpenPrice = CurrentDayOHL().CurrentLow[0];

              {
              if(Bars.FirstBarOfSession && FirstTickOfBar)
              {
              Print("Today's open price is: " + currentSessionOpenPrice );
              }

              if(BarsInProgress !=0)
              return;

              longOrder = SubmitOrder(1, OrderAction.Buy, OrderType.Stop, DefaultQuantity, currentSessionOpenPrice + TickSize*6, currentSessionOpenPrice + TickSize*6, "L", "longOrder");
              }

              Thanks once more!

              Comment


                #8
                Just to clarify, I am using tick data

                Comment


                  #9
                  Hello Griberit,

                  Thank you for the update. Here is the definition for the SubmitOrder method:
                  Code:
                  SubmitOrder(int barsInProgressIndex, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string ocoId, string signalName)
                  The first variable is the barsInProgress index. This variable should always be 0 unless you are using a multi-time frame or multi-instrument strategy. In the example you provided you have not added another data series so you need to change the 1 in your example to a 0 and everything should run correctly.

                  Code:
                  longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, DefaultQuantity, currentSessionOpenPrice + TickSize*6, currentSessionOpenPrice + TickSize*6, "L", "longOrder");
                  Please let me know if this does not resolve the issue or if I may be of further assistance.
                  Michael M.NinjaTrader Quality Assurance

                  Comment


                    #10
                    Michael,

                    I finally have some trades coming through. Thank you so much.

                    I will come back to you at my next hurdle if that is OK.


                    Thanks again!

                    Comment


                      #11
                      Hello Griberit,

                      Thank you for the update. I am glad to hear that you are up and running!

                      Please let me know if I may be of further assistance anytime.
                      Michael M.NinjaTrader Quality Assurance

                      Comment


                        #12
                        Hello again Michael,

                        I hope you are well.

                        I am now trying to add an OnExecution section/method.

                        At the moment, the longOrder and shortOrder execute as they should, but none of the other orders are being executed. Once either is filled it is running to the close.

                        I would appreciate your help again greatly. Thanks in advance.

                        Comment


                          #13
                          Here is the code:

                          if(Bars.FirstBarOfSession && FirstTickOfBar)
                          {
                          longOrder = SubmitOrder(
                          0, OrderAction.Buy, OrderType.Stop, DefaultQuantity, longEntry, longEntry, "Long", "longOrder");
                          shortOrder = SubmitOrder(
                          0, OrderAction.SellShort, OrderType.Stop, DefaultQuantity, shortEntry, shortEntry, "Short", "shortOrder");
                          longTarget = SubmitOrder(
                          0, OrderAction.Sell, OrderType.Limit, DefaultQuantity, longExit, longExit, "LongT", "longTarget");
                          shortTarget = SubmitOrder(
                          0, OrderAction.BuyToCover, OrderType.Limit, DefaultQuantity, shortExit, shortExit, "ShortT", "shortTarget");

                          Print(
                          "Today's open price is: " + currentSessionOpenPrice);
                          Print(
                          "LongEntry Price is: " + longEntry);
                          Print(
                          "ShortEntry Price is: " + shortEntry);

                          }

                          }

                          Comment


                            #14
                            protectedoverridevoid OnExecution(IExecution execution)
                            {

                            //Long scenario:

                            //Once filled on longOrder, cancel shortTarget
                            {
                            if (longOrder != null && longOrder == execution.Order)
                            Print(execution.ToString());
                            CancelOrder(shortTarget);
                            }

                            //If filled on longTarget, cancel shortOrder
                            {
                            if(longTarget != null && longTarget == execution.Order)
                            Print(execution.ToString());
                            CancelOrder(shortOrder);
                            }

                            //If filled on shortOrder, cancel longTarget
                            {
                            if(shortOrder != null && shortOrder == execution.Order)
                            Print(execution.ToString());
                            CancelOrder(longTarget);
                            }

                            //Short scenario:

                            //Once filled on shortOrder, cancel longTarget
                            {
                            if (shortOrder != null && shortOrder == execution.Order)
                            Print(execution.ToString());
                            CancelOrder(longTarget);
                            }

                            //If filled on shortTarget, cancel longOrder
                            {
                            if(shortTarget != null && shortTarget == execution.Order)
                            Print(execution.ToString());
                            CancelOrder(longOrder);
                            }

                            //If filled on longOrder, cancel shortTarget
                            {
                            if(longOrder != null && longOrder == execution.Order)
                            Print(execution.ToString());
                            CancelOrder(longTarget);
                            }

                            Thanks again.

                            Comment


                              #15
                              Hello Griberit,

                              Could you please confirm if all of the orders are submitted correctly when you comment out all of your modifications to the OnExecution method? Alternatively, could you please confirm if you remove either your code to go long or your code to go short (and the corresponding code in OnExecution) if the code that is left executes correctly?

                              Thank you in advance.
                              Michael M.NinjaTrader Quality Assurance

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by racehit, Today, 12:50 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post racehit
                              by racehit
                               
                              Started by cmarkb, Today, 12:04 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post cmarkb
                              by cmarkb
                               
                              Started by supernova0219, Yesterday, 07:48 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post supernova0219  
                              Started by qwfxny, Yesterday, 07:20 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post qwfxny
                              by qwfxny
                               
                              Started by bouncetherubble, Yesterday, 04:48 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post bouncetherubble  
                              Working...
                              X