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, 02: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, 04: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, 02:53 PM.

      Comment


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

        I would use
        Code:
        Stop_Price = [B]Close[0][/B] + 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)
        {[B]entryOrder = null[/B]; Print(order.ToString());
        AvgPrice =[COLOR="Red"] entryOrder[/COLOR].AvgFillPrice; [COLOR="Green"]//change to orderr.AvgFillPrice[/COLOR]
        }
        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)
          {[B]entryOrder = null[/B]; Print(order.ToString());
          AvgPrice =[COLOR=Red] entryOrder[/COLOR].AvgFillPrice; [COLOR=Green]//change to orderr.AvgFillPrice[/COLOR]
          }
          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 agclub, 04-21-2024, 08:57 PM
            4 responses
            18 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Irukandji, Today, 04:58 AM
            0 responses
            3 views
            0 likes
            Last Post Irukandji  
            Started by fitspressoburnfat, Today, 04:25 AM
            0 responses
            2 views
            0 likes
            Last Post fitspressoburnfat  
            Started by Skifree, Today, 03:41 AM
            1 response
            4 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Started by usazencort, Today, 01:16 AM
            0 responses
            4 views
            0 likes
            Last Post usazencort  
            Working...
            X