Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pos.Qty in OnBarUpdate and OnPosition

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

    Pos.Qty in OnBarUpdate and OnPosition

    Hello,

    I have a problem with position.quantity I´m working with now for months. I have no idea whats going on.

    Output window shows from Onbarupdate where I do print together with the entry (Print("Position.Quantity: " + Position.Quantity); Print(Time[0])

    17.11.2013 04:35:51
    Position.Quantity: 0

    But there is a trade with 3 contracts and output window shows from my OnPosition with Print("OnPosition.Position.Quantity: " + Position.Quantity);Print(Time[0])
    contractskL1a 1
    17.11.2013 04:35:51
    OnPosition.Position.Quantity: 1
    17.11.2013 04:35:51
    contractskL1b 2
    17.11.2013 04:35:51
    OnPosition.Position.Quantity: 2
    17.11.2013 04:35:51
    contractskL1c 3
    17.11.2013 04:35:51
    OnPosition.Position.Quantity: 3

    Why is Pos.Qty from OnBarUpdate=0? OK, I can live with, maybe this is to fast with the entry and NinjaTrader needs to count up in OnExecution or OnPosition. No Problem when in OnbarUpdate the PosQty is not correct. But it should be correct and working from OnPosition. The problem is that my exits do not work because conditions Position.Quantity==3 is not true:


    if(Position.MarketPosition == MarketPosition.Long)
    {if(Position.Quantity==3
    && GetCurrentBid() > Position.AvgPrice + 10 * TickSize)
    {exitOrder1a = ExitLong(1);}


    There is no exit! I assume because Pos.Qty is not 3 in Onbarupdate (as shown in output window) How can this be that Pos.Qty is different? How can I refer in my conditions to correct Pos.Qty from OnPosition please?


    Thank you
    Tony
    Last edited by tonynt; 11-17-2013, 02:45 PM. Reason: clearify

    #2
    Hello Tony,

    Thank you for your post.

    OnBarUpdate() will not reflect the current position until the next call of OnBarUpdate() after OnPositionUpdate() has been called. However, your condition should still return an ExitLong():
    Code:
    if(Position.MarketPosition == MarketPosition.Long)
    {if(Position.Quantity==3
    && GetCurrentBid() > Position.AvgPrice + 10 * TickSize)
    {exitOrder1a = ExitLong(1);}
    Does the above condition eventually call the ExitLong(), or is the ExitLong() never called?

    I look forward to your response.

    Comment


      #3
      Hello Patrick,

      thank you for your reply.

      This occurs with simulated datafeed when I tested strategies on the weekend.

      Is this a reason?

      Thanks
      Tony

      Comment


        #4
        Hello Tony,

        Thank you for your response.

        I would not expect to see this behavior on the Simulated Data Feed. The Simulated Data Feed, while internally generated fake data, should still act as a real-time feed when running NinjaScript strategies.

        I look forward to assisting you further.

        Comment


          #5
          Hello Patrick,

          thank you for your reply. It occurs also with live-datafeed (zen-fire) now. I have no idea why.

          But please let me inform correct: with "my exits do not work" this was a wrong translation - sorry. There are exitslong but they should not be because I have as condition if(Position.Quantity==3 &&). I post here the targets where this occurs

          else if(Position.MarketPosition == MarketPosition.Long && exitpips == false && exittargets == true)
          {
          if(Position.Quantity==3 &&
          GetCurrentBid() >= Instrument.MasterInstrument.Round2TickSize(Donchia nChannel(21).Upper[0]))
          exitOrder1a = ExitLong(1);

          else if(Position.Quantity==2 &&
          Close[0] < Instrument.MasterInstrument.Round2TickSize(Donchia nChannel(8).Mean[1]))
          exitOrder1b = ExitLong(1);

          else if(Position.Quantity==1 &&
          Close[1] >= HMA(89)[1] && Close[0] < HMA(89)[0])
          exitOrder1c = ExitLong(1);
          }

          exitOrder1a is executed BEFORE Donchian21 is touched and exitOrder2b is executed immediately afterwards (this is logically depending from position of price). Only entryOrder1c is not triggered because the Close > and Close < is not true yet.

          Therefore I checked with output window and there I saw that Position.Quantity shows 0 in onbarupdate but 3 (as correct) in onposition.

          I hope I could explain now correctly.


          Thank you for your support.
          Tony
          Last edited by tonynt; 11-18-2013, 03:24 PM.

          Comment


            #6
            Hello Tony,

            Thank you for your response.

            Can you provide your strategy code or a toy version that details this item in your response?

            I look forward to your response.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by futtrader, Today, 01:16 PM
            0 responses
            4 views
            0 likes
            Last Post futtrader  
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,789 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            838 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,294 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Working...
            X