Announcement

Collapse
No announcement yet.

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 cmoran13, Yesterday, 01:02 PM
          0 responses
          29 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          21 views
          0 likes
          Last Post PaulMohn  
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          160 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          95 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          148 views
          2 likes
          Last Post CaptainJack  
          Working...
          X