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.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 Carolscogginsi, Today, 10:45 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Carolscogginsi  
                  Started by RaddiFX, Today, 10:15 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post RaddiFX
                  by RaddiFX
                   
                  Started by patrickmlee007, Today, 09:33 AM
                  2 responses
                  18 views
                  0 likes
                  Last Post patrickmlee007  
                  Started by magnatauren, 08-15-2020, 02:12 PM
                  5 responses
                  206 views
                  0 likes
                  Last Post RaddiFX
                  by RaddiFX
                   
                  Started by rene69851, 05-02-2024, 03:25 PM
                  1 response
                  22 views
                  0 likes
                  Last Post rene69851  
                  Working...
                  X