• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can I tag a position created by a strategy?

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

    Can I tag a position created by a strategy?

    Can I tag a position created by a strategy?
    I create an entry order named "foo",
    I want to find out how this position closed.
    I can assign an exit order, but that is not what I want.

    For example, I open a position, with the signal name of "foo" for the order.
    At some point that position will be closed, by either the broker, me, my strategy, or a exit session on close etc.

    How can I find out how/what method closed the position? FYI there is a bug with systemperformance, so I cannot use that.

    #2
    Hello lakersfan,

    Thanks for your post.

    I see that you have already opened a thread on this topic here. Please continue working with that technician to further discuss why our recommendation to use SystemPerformance is not adequate for your purposes.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      I have tried all methods described by other technicians,I have carefully worded what I am looking to accomplish different enough that it is a NEW and different THREAD, if you are unable to help, then how do I go about getting a refund for the NinjaTrader license that I purchased?

      Comment


        #4
        Hello lakersfan,

        As I understand you are trying to identify the Exit execution of a trade, our recommendation is the same here. We would suggest to use SystemPerformance and access the Trade object from a SystemPerformance TradesCollection and then reference the name of the Exit execution to see what execution closed that trade. This is what we suggested in your thread with Kate.

        If you are trying to accomplish something differently in this thread other than trying to identify the Execution that closed a trade, please elaborate so we can assist further.

        If you are still trying to accomplish identifying the Exit execution that closed a trade, but are having trouble using SystemPerformance, please continue working with Kate. If you found a bug, please tell us how to reproduce it so we can report it.

        If you have questions regarding our organization of forum threads or questions regarding the assistance you are receiving, please send an email to platformsupport [at] ninjatrader [dot] com with the text "Attn Jim Scripting Support Lead 2644351" and include a link to this thread. You will have to discuss these matters with me before discussing a refund.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jim View Post
          Hello lakersfan,

          As I understand you are trying to identify the Exit execution of a trade, our recommendation is the same here. We would suggest to use SystemPerformance and access the Trade object from a SystemPerformance TradesCollection and then reference the name of the Exit execution to see what execution closed that trade. This is what we suggested in your thread with Kate.

          If you are trying to accomplish something differently in this thread other than trying to identify the Execution that closed a trade, please elaborate so we can assist further.

          If you are still trying to accomplish identifying the Exit execution that closed a trade, but are having trouble using SystemPerformance, please continue working with Kate. If you found a bug, please tell us how to reproduce it so we can report it.

          If you have questions regarding our organization of forum threads or questions regarding the assistance you are receiving, please send an email to platformsupport [at] ninjatrader [dot] com with the text "Attn Jim Scripting Support Lead 2644351" and include a link to this thread. You will have to discuss these matters with me before discussing a refund.

          We look forward to assisting.
          Yes, I have tried systemPerformance, but there is a bug on my machine, and on several other posts that I have read. I sent a log and trace, but the issue was not resolved.
          I have implemented my own record-keeping of trades, using onpsitionupdate, onexecutionupdate and onorderupdate in place of systemperformance, however all I need to accomplish at this point is to figure out what method closed a position, By this I mean tagging a position, to know which position I am talking about.

          .FromEntrySignal only applies to stops and targets, but what If my broker closes the position? How do I get the trade information for that?

          Comment


            #6
            Hello lakersfan,

            Log and Trace files will not be enough to investigate that sort of issue. We would want a small test script and steps to take that can demonstrate the issue without other code involved. Could you provide such an example for our review?

            If you are trying to track that on your own, you could check in OnExecutionUpdate when the strategy's Position object is not flat (Strategy Positions are updated as early as OnExecutionUpdate) This would be when the position is opened and you could track using variables in your script, like a dictionary with a custom class that holds Entry and Exit Executions. You could also use a string for the open position which would match your dictionary's key for that position. When OnExecutionUpdate happens again and the Position is Flat, you can reference your dictionary with that open position string for the key, and then assign the Exit execution there.

            You would then achieve "tagged positions" as well as being able to identify which Exit execution closed an entry.

            You would be re-inventing the wheel for a lot of functionality that would be done easily with SystemPerformance. If Kate's solution is not working for you, please continue working with her.

            If you have a small test case to provide for reproducing an issue with SystemPerformance, please send us a test script and steps to hit the issue over email.

            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jim View Post
              Hello lakersfan,

              Log and Trace files will not be enough to investigate that sort of issue. We would want a small test script and steps to take that can demonstrate the issue without other code involved. Could you provide such an example for our review?

              If you are trying to track that on your own, you could check in OnExecutionUpdate when the strategy's Position object is not flat (Strategy Positions are updated as early as OnExecutionUpdate) This would be when the position is opened and you could track using variables in your script, like a dictionary with a custom class that holds Entry and Exit Executions. You could also use a string for the open position which would match your dictionary's key for that position. When OnExecutionUpdate happens again and the Position is Flat, you can reference your dictionary with that open position string for the key, and then assign the Exit execution there.

              You would then achieve "tagged positions" as well as being able to identify which Exit execution closed an entry.

              You would be re-inventing the wheel for a lot of functionality that would be done easily with SystemPerformance. If Kate's solution is not working for you, please continue working with her.

              If you have a small test case to provide for reproducing an issue with SystemPerformance, please send us a test script and steps to hit the issue over email.

              We look forward to assisting.
              Unfortunately the systemperformance issue is not a coding problem. My ninjatrader is just not logging my trades with systemperformance. I have used the unedited examples by NT technicians, and it does not work. Systemperformance is not logging any trades.
              Your example on how to achieve what I want, i think might work. How do I access the position ID? (not order)

              Comment


                #8
                Hello lakersfan,

                Do you see an issue with SystemPerformance when setting IncludeTradeHistoryInBacktest to true?

                IncludeTradeHistoryInBacktest - https://ninjatrader.com/support/help...inbacktest.htm

                There wouldn't be a Position ID to retrieve. We do not have a Position ID with the Position object, and we do not show these in the Positions tab of the Control Center or in log and trace files.

                You could use the Execution ID from the entry order, or use your own unique string to make an ID if you want.

                Execution object - https://ninjatrader.com/support/help.../execution.htm

                We look forward to assisting.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jim View Post
                  Hello lakersfan,

                  Do you see an issue with SystemPerformance when setting IncludeTradeHistoryInBacktest to true?

                  IncludeTradeHistoryInBacktest - https://ninjatrader.com/support/help...inbacktest.htm

                  There wouldn't be a Position ID to retrieve. We do not have a Position ID with the Position object, and we do not show these in the Positions tab of the Control Center or in log and trace files.

                  You could use the Execution ID from the entry order, or use your own unique string to make an ID if you want.

                  Execution object - https://ninjatrader.com/support/help.../execution.htm

                  We look forward to assisting.
                  Yes, I have tried IncludeTradeHistoryInBacktest = true, but that still does not work. Can you please provide a sample code of how I would accomplish this "You could use the Execution ID from the entry order, or use your own unique string to make an ID if you want.", If unable could we open up a feature request that would collect position objects?

                  Comment


                    #10
                    Hello lakersfan,

                    Below is how you would catch the execution ID for your entry order.

                    Code:
                    protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, 
                        Cbi.MarketPosition marketPosition, string orderId, DateTime time)
                    {
                        if (Position.MarketPosition == MarketPosition.Long && execution.Order.Name == "MyEntry")
                        {
                            Print(execution.Id); // This is the Execution ID for your entry order.
                        }
                    }
                    I would like to ensure you can use SystemPerformance, though. Please reach out to me over email so we can schedule a time for a remote support session and so I can observe tests with some example scripts.

                    We look forward to assisting.
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by thrbjdhkd, Today, 06:35 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post thrbjdhkd  
                    Started by sjlrmhtbj, Today, 06:32 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post sjlrmhtbj  
                    Started by bumbledbee, Today, 04:28 AM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by Tmaninc, Today, 02:13 AM
                    3 responses
                    11 views
                    0 likes
                    Last Post Tmaninc
                    by Tmaninc
                     
                    Started by rexmie888, Yesterday, 09:37 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Working...
                    X