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 Balage0922, Today, 07:38 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Balage0922  
                  Started by JoMoon2024, Today, 06:56 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post JoMoon2024  
                  Started by Haiasi, 04-25-2024, 06:53 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post Massinisa  
                  Started by Creamers, Today, 05:32 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Creamers  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  12 responses
                  1,786 views
                  0 likes
                  Last Post Leafcutter  
                  Working...
                  X