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

Position.AvgPrice

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

    Position.AvgPrice

    Greets,

    I am trying to 'capture' the price of the entry, when the order is placed, for further use.

    Code:
    [FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]private[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]double[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial][COLOR=#000000] MyEnterP125 = [/COLOR][/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial][COLOR=#000000];[/COLOR][/FONT]
     
    [FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]protected[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]override[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]void[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial] OnBarUpdate()[/FONT]
    [FONT=Arial]{ sThisPrice.Set(Position.AvgPrice);[/FONT]
     
    [FONT=Arial][FONT=Arial]{ [/FONT][FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial] ( (Position.MarketPosition == MarketPosition.Flat) && (timeSeries[[/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial]] >= [/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]1[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial]) )[/FONT]
    [FONT=Arial][COLOR=#008000][FONT=Arial][COLOR=#008000]// Try to go LONG[/COLOR][/FONT]
    [/COLOR][/FONT][FONT=Arial]{ [/FONT][FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial] ( WatchToGoLong == [/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]1 )[/COLOR][/FONT]
    [/COLOR][/FONT].................
    [FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]if[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial] ((iOrderL5 == [/FONT][FONT=Arial][COLOR=#0000ff][FONT=Arial][COLOR=#0000ff]null[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial] || Historical) && iQuantity5 != [/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial])[/FONT]
    [FONT=Arial]{ iOrderL5 = EnterLong([/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial], iQuantity5, sENTRY5L);[/FONT]
    [FONT=Arial]MyEnterP125 = sThisPrice[[/FONT][FONT=Arial][COLOR=#800080][FONT=Arial][COLOR=#800080]0[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial]];[/FONT]
    [FONT=Arial]Print([/FONT][FONT=Arial][COLOR=#800000][FONT=Arial][COLOR=#800000]"Entry Price PT125 "[/COLOR][/FONT][/COLOR][/FONT][FONT=Arial]+MyEnterP125);[/FONT]
    [FONT=Arial]}[/FONT]
     
    [/FONT]
    I also had tried

    MyEnterP125 = Position.AvgPrice;

    (without using the DataSeries.Set etc) ... everything compiles but I only get '0'
    (as in MyEnterP125 = 0; ) at the print during the strategy run on whatever attempt that does compile ...

    Obviously missing something ...

    Any assist is appreciated!

    Thanks,
    Jon
    Last edited by Trader.Jon; 03-21-2011, 01:52 AM.

    #2
    Your brackets look funny. Are you sure that you have posted the correct code?

    Comment


      #3
      MyEnterP125 = Position.AvgPrice
      This instruction is correct, but you cannot execute it in OnBarUpdate()
      immediately after executing an Enter..().
      You can place it in OnExecution() or query it on the next bar.

      Baruch

      Comment


        #4
        Originally posted by koganam View Post
        Your brackets look funny. Are you sure that you have posted the correct code?
        I only posted the relevant portions for clarity and not all the brackets were carried forward.

        Thanks for the feedback.

        Jon

        Comment


          #5
          Originally posted by Baruch View Post
          This instruction is correct, but you cannot execute it in OnBarUpdate()
          immediately after executing an Enter..().
          You can place it in OnExecution() or query it on the next bar.

          Baruch
          Baruch,

          Thanks, I will give that a try.

          Jon

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Austiner87, Today, 03:42 PM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by cshox, Today, 11:11 AM
          2 responses
          15 views
          0 likes
          Last Post cshox
          by cshox
           
          Started by algospoke, Today, 06:53 PM
          0 responses
          10 views
          0 likes
          Last Post algospoke  
          Started by mlprice12, 12-21-2021, 04:55 PM
          3 responses
          297 views
          0 likes
          Last Post paypachaysa  
          Started by lorem, 04-25-2024, 09:18 AM
          20 responses
          86 views
          0 likes
          Last Post lorem
          by lorem
           
          Working...
          X