• 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

Recognizing market position

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

    Recognizing market position

    Hello,

    I want to ask please if it is possible in a script to recognize the marketposition of an instrument. Eg if an entry is done on DOM or chart trader the script should detect the marketposition and if its not flat then managing the trade from the script.

    Thank you!
    Tony

    #2
    Hello Tony,

    To check the Account Position of an instrument outside of a NinjaScript Strategy would require unsupported code to check the account in NinjaTrader 7.

    Below is a link to a forum post with some example unsupported / undocumented code.
    https://ninjatrader.com/support/foru...604#post751604
    https://ninjatrader.com/support/foru...455#post448455

    (edited, had to correct the first link)
    Last edited by NinjaTrader_ChelseaB; 06-12-2019, 03:33 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. From this code I get OnPosition. Is it possible to get the information if the position is short or long? And is it also possible to get the instrument which is in a trade?

      Thank you!
      Tony
      Last edited by tonynt; 06-10-2019, 07:30 AM. Reason: translation error

      Comment


        #4
        Hello Tony,

        Yes, the argument Position.MarketPostion is the Position. A Position.MarketPosition is an enum that will have a value of Long, Short, or Flat.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you for your reply. OK, but how can this be added in the script here?

          private void OnPosition(object sender, PositionUpdateEventArgs e)
          {
          if(Position.MarketPosition==MarktetPosition.Long) EnterLong(1);
          // Print("OnPosition: " + e.Position.ToString());
          }

          Thank you!
          Tony

          Comment


            #6
            Hello tonynt,

            You would need to type the code into the method?

            In the example the argument of the method is e.

            e.Position.MarketPosition

            You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              I see a lot of replies from support in the forum with helping traders by more than a word!

              Can´t you give me the one line please?

              With if (e.Position.MarketPosition==MarketPosition.Long) EnterLong(1);

              it also triggers the EnterLong(1) when the position on the account is short. Whats wrong here please?

              Thank you!
              Tony

              Comment


                #8
                Hello tonynt,

                Are you 100% certain that other traders are getting assistance with items that our support has stated are not supported by the NinjaScript Support team?

                Because this code is not supported, there is no guarantee it will work.

                May I confirm that there is only one position open on the account?

                If you print the e.Position.MarketPosition to the output window are you seeing the positions appear as the positions change?

                If you were using NinjaTrader 8, there are documented methods of accessing the account position that I am able to assist with and provide examples for.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea,

                  thank you for your reply. I have to use NT7 because a fellow needs it in NT7. I attach a screenshot where you can see:

                  * in upper left corner the entry with chart trader on sim101
                  * in lower left corner another instrument with the script that should do an entry long from the script if there is a long trade
                  * upper right you see the short from the instrument with short entry from chart trader and the long entry from script (that should not be)
                  * below the code you see the printing statements.

                  Thank you for your support!
                  Tony
                  Attached Files

                  Comment


                    #10
                    Hello tonynt,

                    I'm not able to assist with unsupported code, but this thread will remain open for any community members that would to assist.
                    This is not supported for NinjaTrader 7. This is supported for NinjaTrader 8.

                    That said, there are 2 open positions.
                    Do you have code written to identify which position you are interested in?
                    Are you wanting to place an order anytime there is a long position with any instrument no matter if there is a short position for any other instrument?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      thank you for your reply. The problem is now that english is not my language and I really dont understand your first question and thats making all even more difficult for me.
                      I have in the code as you see to check if there is a position and if this is a position long. If it is a position long then I´m going to exitshorts and enterlongs on instruments I have to add then.
                      I had not thought that there will be a problem when checking the marketposition.

                      when I do an entry long from charttrader then it should trigger longs for the instruments we will add in the script.
                      when I do an entry short from charttrader then it should trigger shorts for the instruments we will add in the script.

                      (if the entries would be from the script then it would not be a problem because then I could check in the code if marketposition is long or short and derive from this the entries.But we have to do the entry with DOM or chart-trader to have it visible in the group and therefore check for the account if there is a long position or a short position. thats all)


                      Thank you!
                      Tony

                      Comment


                        #12
                        Hello Tony,

                        I am seeing there are two positions in the screenshot you have provided.

                        There is a position of 1000 short on $EURJPY.
                        There is a position of 1 long on $AUDJPY.

                        The account.PositionUpdate is going to trigger for all positions for all instruments that are opened on this account.

                        Your code will need to track all of the positions and ensure it is triggering for the correct instrument.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea,

                          I have one step to resolve but couldnt get it. Please, how can I get the Position.Flat from this example here above.

                          With if (e.Position.MarketPosition==MarketPosition.Flat) doitonce=true; the bool persists false even when the position from the chart trader is flat.

                          I can not finish a project working for several weeks only because of this step. I cant find anything in helpguide or forum.

                          Thank you!
                          Tony
                          Last edited by tonynt; 06-12-2019, 02:02 PM. Reason: explanation

                          Comment


                            #14
                            Hello Tony,

                            This is going to require custom unsupported logic that I'm not going to write.

                            I'm showing there are multiple positions. Close all of the other positions.
                            If you have only one position open, that position should be the position that updates the account.PositionUpdate event.

                            Otherwise you will need some way of identifying which position is updating.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Chelsea,

                              I have no idea what this means. Can´t you give me an hint so that I can find out?

                              Thank you!
                              Tony

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Miguel_88, Today, 06:41 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Miguel_88  
                              Started by spikeruk, Today, 01:49 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by Yandychang, Today, 02:16 PM
                              5 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by priceisking, Today, 01:16 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post priceisking  
                              Started by kashyapjdave, 03-23-2017, 12:12 AM
                              11 responses
                              1,959 views
                              0 likes
                              Last Post forextrader2003  
                              Working...
                              X