Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.MarketPosition==MarketPostion.Flat

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

    Position.MarketPosition==MarketPostion.Flat

    Hi,

    I have an unmanaged strategy where in the if statement have set to only trigger the criteria if Position.MarketPosition==MarketPostion.Flat, and it still triggers. I copied the strategy and put it in a managed approach and it works fine. Does this rule not work in unmanaged strategies?

    Thanks,
    AgriTrdr

    #2
    Originally posted by AgriTrdr View Post
    ... and it still triggers ...
    "Inconceivable!"

    Originally posted by AgriTrdr View Post
    I copied the strategy and put it in a managed approach and it works fine. Does this rule not work in unmanaged strategies?
    It should work fine for both.

    Got any example code you can upload?

    Comment


      #3
      Did you enter the position through the strategy?
      If you enter manually or from another strategy it is not seen

      run this code to tell

      PNLaccount = PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Currency, Close[0]);
      PNLposition = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);
      Print(" PNLaccount="+PNLaccount+" Position PNLposition="+PNLposition);

      My next post is on this subject related to Addon.

      Comment


        #4
        Thank you both for your replies. Here's the basic structure:

        OnBarUpdate()
        {
        if (Time> 9:30)
        {
        Close[0] > VWAP
        EnterLong();

        Close[0] < VWAP
        EnterShort();

        else if (Position.MarketPosition==MarketPosition.Flat)
        {
        Close[0]>CurrentDayOpen
        EnterLong();

        Close[0]<CurrentDayOpen
        EnterShort();
        }
        }

        Comment


          #5
          Hello AgriTrdr,

          Note, the Position does need time to update in OnPositionUpdate() after the order has filled.

          I recommend you enable TraceOrders to see when the order is submitted. Print the marketPosition in OnPositionUpdate(). Then print the Position.MarketPosition in OnBarUpdate before the condition that uses this to confirm what this value is.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi ChelseaB,

            I do have prints throughout the strategy so it is letting me know this condition is not picking up. I also have another set with prints if (Position.MarketPosition==MarketPosition.Long) and if (Position.MarketPosition==MarketPosition.Short) with prints and that's not printing in the unmanaged approach but is printing in the managed approach.

            You've recommended to "Print the marketPosition in OnPositionUpdate()". A couple questions regarding that:

            1. Should OnPositionUpdate() be after OnBarUpdate?
            2. Do you've an example or should I copy the entire condition that uses (Position.MarketPosition==MarketPosition.Long) into OnPositionUpdate()?

            Thanks

            Comment


              #7
              Hello AgriTrdr,

              OnPositionUpdate is run when the position updates. This is not related to OnBarUpdate and is not guaranteed to be before or after.

              You can use Position.MarketPosition in OnBarUpdate(), just know that this won't change in OnBarUpdate until the position updates and then the bar updates after.

              If you have prints provide the output from your prints saved to a text file.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                What is the Calculate setting for your strategy?

                Comment


                  #9
                  Hi bltdavid,

                  It's OnBarClose.

                  Thanks

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  52 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  130 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  70 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  49 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X