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

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:	845
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:

            Paul H.NinjaTrader Customer Service

            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

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by helpwanted, Today, 03:06 AM
              1 response
              10 views
              0 likes
              Last Post sarafuenonly123  
              Started by Brevo, Today, 01:45 AM
              0 responses
              8 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              5 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              242 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              386 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X