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.

          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.

              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?

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,265 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X