• 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

AvgEntryPrice() question

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

    AvgEntryPrice() question

    I just need to verify something:

    The Average Entry Price for a specific product is reset every time a position is closed (flattened)? In other words, when I retrieve the AvgEntryPrice, I'm not getting the average entry price over the entire day (session), correct?

    For example, if I open a position in stock XYZ in the moring, buy 100 shares at $10, and then close (flatten) the XYZ position, my AvgEntryPrice for that trade equals 10. If in the afternoon I open a new position in XYZ and buy at a price of $20, my AvgEntryPrice should be 20, not 15 ((10+20)/2). Is that correct? So there is no carry over of entry prices?

    I'm pretty sure that is how it works, but I need to double check.


    Thanks for your help.

    #2
    It resets for every new position.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Lets say I am building positions into a winning long position. I am only looking to take small profits off along the way when and a certain exit condition is true, BUT i need to verify that the current close is greater than any Entry Price. Using avg position price does not work b/c on the avg I am ahead PNL but I might be still be below the last entry price which can take me exit or reduce my position b/c the conditions are met but I have no way to state and close is greater than entry. There is avgentryprice but i dont see how to code that and it still may do the same thing as average position price

      Comment


        #4
        Originally posted by hifreq View Post
        Lets say I am building positions into a winning long position. I am only looking to take small profits off along the way when and a certain exit condition is true, BUT i need to verify that the current close is greater than any Entry Price. Using avg position price does not work b/c on the avg I am ahead PNL but I might be still be below the last entry price which can take me exit or reduce my position b/c the conditions are met but I have no way to state and close is greater than entry. There is avgentryprice but i dont see how to code that and it still may do the same thing as average position price
        If you want to reference data, you will have to store the data.

        Store the entry prices in a list, and remove the corresponding entries when you exit the corresponding position.

        Comment


          #5
          Hello hifreq,

          Thank you for your post.

          As koganam suggested storing the value of the entry on entry would be the best method for your item. You can use OnExecution() to pull the price of the execution.

          For information on OnExecution() please visit the following link: http://www.ninjatrader.com/support/h...nexecution.htm

          Please let me know if I may be of further assistance.
          Patrick H.NinjaTrader Customer Service

          Comment


            #6
            Thanks, unfortunately its above my programming IQ. Is there an easy way to state that the current bid/ask needs to be above/below the last entry price?

            Comment


              #7
              Hello hifreq,

              Thank you for your response.

              The following is a basic example of storing the price of a filled order:
              Code:
              private IOrder entryOrder = null;
              private double lastEntry = 0;
              protected override void OnBarUpdate()
              {
                  if (entryOrder == null && Close[0] > Open[0])
                       entryOrder = EnterLong();
              }
              
              protected override void OnExecution(IExecution execution)
              {
                  if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
                       lastEntry = execution.Price;
              }
              For information on OnExecution() please visit the following link: http://www.ninjatrader.com/support/h...nexecution.htm
              For information on IOrder objects please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

              And then if we want to check that the current bid or ask is above the lastEntry double we can use the following:
              Code:
              if(BarsSinceEntry() > 1 && (GetCurrentBid() > lastEntry || GetCurrentAsk() > lastEntry))
              {
              //Do something
              }
              I used BarsSinceEntry() to ensure we have a previous entry.

              Please let me know if I may be of further assistance.
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                Thanks very much for your assistance - i am getting the following error "An Array cannot be specified in a variable declaration. I have this line of code that may be causing that problem

                for (int a = 0; a< BarsArray.Length; a++)
                Print(this.Name+" Bars data ["+a+"] contains "+BarsPeriods[a].ToString()+" of "+BarsArray[a].Count+" bars, commencing at "+BarsArray[a].Get(0).Time);
                }


                any ideas?

                Comment


                  #9
                  Hello hifreq,

                  Thank you for your response.

                  I tested that code and it works fine on my end. Can you attach your full code to your response so I may investigate this matter further?
                  Patrick H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by johnnybegoode, Today, 07:02 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post johnnybegoode  
                  Started by YevhenShynkarenko, Today, 05:02 PM
                  1 response
                  11 views
                  0 likes
                  Last Post YevhenShynkarenko  
                  Started by lahabatha, Today, 04:42 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post lahabatha  
                  Started by explorer101, Today, 03:39 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by faisamtrader, Today, 03:32 PM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X