• 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

AvgPrice

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

    AvgPrice

    Hello NT Support,

    I have a problem with inquire the avgprice in that moment when I open an order. I'd like to use the avgprice to the stopprice immediatly after opening an order at one tick. My problem is, the avgprice will update, at the next tick, not at the moment of an open. I tried it inquire using IPosition, IOrder, and IExecution methods, but all of them will update at the next tick. Could you send me the right solution how can I reach it immediatelly in OnBarUpdate()?

    thanks Ron
    Last edited by rontrade; 01-09-2012, 01:35 PM.

    #2
    rontrade,

    I am happy to assist you.

    How are you obtaining average price? You are using this to set a stop loss correct? What are your entrance criteria? Could you please provide your code?

    I look forward to helping you resolve your issue.
    Last edited by NinjaTrader_AdamP; 01-09-2012, 03:09 PM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hello Adam,
      here it is an simple code of my method:


      protected override void OnBarUpdate()
      {
      if (Condition1 )
      { string S_Open = "SHORT" + " " + long_count.ToString();
      entryOrder = EnterShort(Open_Value, S_Open);
      DrawVerticalLine("My vertical line2" + CurrentBar, 0, Color.Red, DashStyle.Solid, 3);
      PrintWithTimeStamp("\tS_Open: " +S_Open+ "\tAvgPrice: " + AvgPrice.ToString());
      Stop_Price = AvgPrice + stop_PIP *TickSize * 10;
      }
      }

      protected override void OnOrderUpdate(IOrder order)
      {
      if (entryOrder != null && entryOrder == order)
      {
      if (order.OrderState == OrderState.Filled)
      {entryOrder = null; Print(order.ToString());
      AvgPrice = entryOrder.AvgFillPrice;
      }
      }
      }
      Last edited by rontrade; 01-09-2012, 01:53 PM.

      Comment


        #4
        Hello rontrade,
        I am following for Adam, and is happy to assist you.

        I would use
        Code:
        Stop_Price = Close[0] + stop_PIP *TickSize * 10;
        and in OnOrderUpdate i would reassign the same again as
        Code:
        Stop_Price = order.AvgFillPrice + stop_PIP *TickSize * 10;

        Also in you code you assigned entryOrder as null and after that you are trying to extractact the average price value from that null value.


        Code:
        protected override void OnOrderUpdate(IOrder order)
        {
        if (entryOrder != null && entryOrder == order)
        {
        if (order.OrderState == OrderState.Filled)
        {entryOrder = null; Print(order.ToString());
        AvgPrice = entryOrder.AvgFillPrice; //change to orderr.AvgFillPrice
        }
        Please rectify the same.

        Please let me know if I can assist you any further.

        Regards,
        Joydeep.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post

          and in OnOrderUpdate i would reassign the same again as
          Code:
          Stop_Price = order.AvgFillPrice + stop_PIP *TickSize * 10;
          Also in you code you assigned entryOrder as null and after that you are trying to extractact the average price value from that null value.
          thanks Joydeep,
          but there are some remark to this. I've tried this, but when I use this: order.AvgFillPrice (entryOrder.AvgFillPrice) then its State=PendingSubmit, so the the price will be 0. The executed price will get the right value, when the State will Filled. And I'd like to get this Filled value, in OnBarUpdate(), after directly an opened position not at a new tick. The Close[0] isn't precise for me since the Filled price can be others then the Close[0] price.

          Originally posted by NinjaTrader_Joydeep View Post
          Code:
          protected override void OnOrderUpdate(IOrder order)
          {
          if (entryOrder != null && entryOrder == order)
          {
          if (order.OrderState == OrderState.Filled)
          {entryOrder = null; Print(order.ToString());
          AvgPrice = entryOrder.AvgFillPrice; //change to orderr.AvgFillPrice
          }
          Please rectify the same.
          It works perfectly, it was wrote the right value in AvgPrice but I can reach it at the next tick. But I intend to send the StopLimit related in the open price when I open a position. Since I'm using CalculateOnBarClose = true, and it send a StopLimt at the next open would be hazardous.
          What other solution can you recommend?

          thanks Ron

          Comment


            #6
            Originally posted by rontrade View Post
            thanks Joydeep,
            but there are some remark to this. I've tried this, but when I use this: order.AvgFillPrice (entryOrder.AvgFillPrice) then its State=PendingSubmit, so the the price will be 0. The executed price will get the right value, when the State will Filled. And I'd like to get this Filled value, in OnBarUpdate(), after directly an opened position not at a new tick. The Close[0] isn't precise for me since the Filled price can be others then the Close[0] price.
            Hello rontradde,
            Unless the trade is filled/partfilled you wont have an AvgPrice. So when orderstate is PendingSubmit, its natural to have the avgprice as 0 (zero). So its always good to do a check, like you already did

            Code:
            if (order.OrderState == OrderState.Filled)
            {
            //do stuff
            }
            Alternatively you can also get the price in OnExecution event. Heres a reference link for the same http://www.ninjatrader.com/support/h...nexecution.htm


            When you submit the order (in OnBarUpdate), you wont have any AvgPrice since it is yet to be filled. But since you are submitting Market Orders, you can use Close[0] (or CurrentBid/CurrentAsk) as a reference, and you update/get the exact value at OnOrderUpdate (or in OnExecution) event when the order gets filled. This is only a workable workaround.


            Originally posted by rontrade View Post
            It works perfectly, it was wrote the right value in AvgPrice but I can reach it at the next tick. But I intend to send the StopLimit related in the open price when I open a position. Since I'm using CalculateOnBarClose = true, and it send a StopLimt at the next open would be hazardous.
            What other solution can you recommend?

            thanks Ron
            If you are using CalculateOnBarClose = true, then you can consider placeing the stop/risk management codes in the OnMarketData event. For more refer please here http://www.ninjatrader.com/support/h...marketdata.htm

            Let me know if I can be of any further help.

            Regards,
            Joydeep.
            JoydeepNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by giogio1, 11-10-2019, 11:23 PM
            4 responses
            14 views
            0 likes
            Last Post bltdavid  
            Started by Dolosumo, Today, 01:05 AM
            0 responses
            1 view
            0 likes
            Last Post Dolosumo  
            Started by StevenNelson, Yesterday, 07:31 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Started by dtl-saw, Yesterday, 09:37 PM
            0 responses
            2 views
            0 likes
            Last Post dtl-saw
            by dtl-saw
             
            Started by TazoTodua, Yesterday, 03:01 PM
            3 responses
            14 views
            0 likes
            Last Post TazoTodua  
            Working...
            X