Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Price on NinjaScript

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

    Entry Price on NinjaScript

    How do I get the entry price on ninja script?

    For instance, if you look at the picture below:

    Click image for larger version

Name:	EntryPrice.png
Views:	1449
Size:	20.2 KB
ID:	1155516

    My strategy entered the trade at 09:45 am at the price of $1.2120 and exited at $1.2125.
    I know how to get the exit price but no matter what I do, I can't get the entry price.
    If I try:
    - Close[0], it will get me $1.2125 (Closing of last red bar)
    - Open[0], it will get me $1.2130 (Opening of last red bar)
    - execution.Price, it will get me $1.2125

    How do I get the entry price of every entry?

    Thanks a lot

    #2
    Here you go


    Code:
    protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (entryLong != null && entryLong == execution.Order)
    {
    
    if (entryLong.OrderState == OrderState.Filled || entryLong.OrderState == OrderState.PartFilled || (entryLong.OrderState == OrderState.Cancelled && entryLong.Filled > 0) )
    {
    Print(" entrt price = " + entryLong.LimitPrice);
    }
    
    }
    
    }

    Comment


      #3
      There are limitprice, stopprice.

      Please check what are you used.

      Comment


        #4
        Hi cincai
        thanks a lot for the reply...
        I tried your solution but it didn't work, I keep getting entry price = 0;
        this is because I am not looking for an entry limit price, I didn't set one... I do have a limit price for exit though, but this I already know how to get.

        Comment


          #5
          Hi Eddie DeMeira,
          Try this.

          protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
          {
          Print(price.ToString("N2"));
          }

          "N2" is optional and nicely formats the price point.
          NT-Roland

          Comment


            #6
            Hello Eddie De Meira,

            Thanks for your post.

            You can access Position.AveragePrice in OnBarUpdate() as the actual entry price, when the MarketPosition is not flat.
            Reference: https://ninjatrader.com/support/help...erageprice.htm

            Alternately, you can check Order.AverageFillPrice in OnExecutionUpdate()
            References:

            Comment


              #7
              NT-Roland

              Thank you so much! This was very helpful, actually, it solved my problem
              I noticed you can also format the number of decimals displayed by changing "N2" to "N4" to see four decimals on the price...
              Very, very helpful, thanks again!

              @Paul H.
              Thanks for the help Paul, I had already looked into all of those links you posted but I was having a hard time to determine what to do to get the result I needed.
              It's good to have all those links altogether for the record though.
              cheers,

              Eddie

              Comment


                #8
                If I have created a series of entries.... @"EntryShortA" + EntryNO........

                EntryShortA1
                EntryShortA2
                ​​​​​​​EntryShortA3
                ...etc

                How do I call on each entry price individually? (Can Position.AveragePrice include reference to this? Or di i need to store each entry price as a variable when entered?)

                Further, what is the best loop to use within the OnBarUpdate area of code? (Is it this one? https://ninjatrader.com/support/help...g_commands.htm)

                Comment


                  #9
                  Hello Apm123,

                  Thank you for your post.

                  You could save them to variables or access the averageFillPrice for a specific order from OnOrderUpdate().



                  There is no "best loop" we can recommend - all those are options you can use. The 'best loop' would depend on your specific use case as to which one would make the most sense for what you are trying to accomplish.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  556 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  324 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  545 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  547 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X