Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Avg Entry price plot is not correct

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

    Avg Entry price plot is not correct

    I want to plot average entry (breakeven) price throughout the chart at all times reflecting at all times any position I haven to have on. It does not appear to be accurately doing this.

    I have included a picture so you can see where the avg entry plot has failed to update
    Here is the code snippet:

    Code:
    else if (State == State.Configure)
    			{
    				AddDataSeries("EURUSD", BarsPeriod.BarsPeriodType, 4 * BarsPeriod.Value, Data.MarketDataType.Last);
    				AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);
    				AddPlot(Brushes.Lime, "Average price"); //-------HERE WE HAVE PLOTTING AVERAGE ENTRY PRICE
    			}
    Attached Files

    #2
    Hello ShruggedAtlas,

    Thank you for the post.

    The code you have shown is simply the plots definition but this does not provide detail on how you set the plot. Can you provide an example of how you are currently setting and plotting the value?

    In general, the average entry price would need to be gathered from the order fills in the OnExecutionUpdate override. Are you currently doing this?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      No i have no other code to define the avg price. Is there some online help to describe how to do this? I'm not familiar with OnExecutionUpdate override procedure. I'll try and lookup what that does. Any ideas on what the overall approach is would be helpful

      Comment


        #4
        Hello ShruggedAtlas,

        Thank you for the reply.

        Based on the image, it seems the value of your plot is being set somewhere in the script already. It looks like that's the first added plot, so likely somewhere in your code, you have a Value[0] = or Values [0][0] = which would be setting this. Can you look in your script and see what you have in OnBarUpdate right now and if the value is currently being set to something?

        Before we go further I want to take a step back and review your concern along with the information we have now.

        You noted:
        I want to plot average entry (breakeven) price throughout the chart at all times reflecting at all times any position I have to have on.
        Are you looking for the average entry price (breakeven) price for a specific order or just your position in general? Depending on what you want, you can either use the OnExecutionUpdate for individual orders average fill prices or you can use the Position objects for strategy or account positions average prices.

        Depending on the scope of what you want, you may be able to just use the Position or PositionAccount objects and their AveragePrice variables. OnExecutionUpdate can be used to gather individual executions and their average fill prices for more advanced tracking.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Solved!
          To fix the problem I have to go to Options:Trading menu and check the "Use FIFO for position average price calculation" - I have included a picture of what that looks like for anyone interested.

          -----------------------------------

          Ok i was wrong - I do have this value assignment as follows: I'm looking to plot a line that shows average entry for the total of the positions as a whole. So when one of the positions exits, the line should adjust accordingly just as it does when a new order is triggered.

          Code:
          if (BarsInProgress != 0) 
          				return;
          
          			if (CurrentBars[0] < 1
          			|| CurrentBars[1] < 1)
          			return;
          			
          			Values[0][0] = (Position.AveragePrice != 0)?Position.AveragePrice:Close[0];
          Attached Files
          Last edited by ShruggedAtlas; 05-29-2018, 10:36 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GwFutures1988, Today, 02:48 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by ScottWalsh, 04-16-2024, 04:29 PM
          6 responses
          32 views
          0 likes
          Last Post ScottWalsh  
          Started by frankthearm, Today, 09:08 AM
          10 responses
          36 views
          0 likes
          Last Post frankthearm  
          Started by mmenigma, Today, 02:22 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by NRITV, Today, 01:15 PM
          2 responses
          10 views
          0 likes
          Last Post NRITV
          by NRITV
           
          Working...
          X