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

Is it possible to monitor position details from an INDICATOR?

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

    Is it possible to monitor position details from an INDICATOR?

    Hello.

    If one wanted to monitor position from an indicator, NOT a strategy, is this possible?

    Say for example, you have positions that you manually entered, not as a part of a strategy, and you wanted to say, display the PNL, or time of entry on chart, is such a thing possible?

    Thanks

    #2
    Hello forrestang,

    Yes that is possible using the addong account: https://ninjatrader.com/support/help...ount_class.htm


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello forrestang,

      Yes that is possible using the addong account: https://ninjatrader.com/support/help...ount_class.htm


      I look forward to being of further assistance.
      Thank you, this helps.

      Is there an object that holds all of the values associated with any trade?

      I.e., when you look at the breakdown of trades taken(say in the Trade Performance add-on), the times are listed, the prices... everything. Particularly if you look at the Executions tab(see attached image).

      Is there such an object that contains everything related to each trade?
      Attached Files

      Comment


        #4
        Hello forrestang,

        That view is built from the execution information based on the selected filters. From your indicators context it would only have the base data or the executions but not paired trades. https://ninjatrader.com/support/help...executions.htm

        You could manually build a performance report but that is not documented. A user provided a small sample of what would be required to do that: https://ninjatrader.com/support/foru...ns#post1091093

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello forrestang,

          That view is built from the execution information based on the selected filters. From your indicators context it would only have the base data or the executions but not paired trades. https://ninjatrader.com/support/help...executions.htm

          You could manually build a performance report but that is not documented. A user provided a small sample of what would be required to do that: https://ninjatrader.com/support/foru...ns#post1091093

          I look forward to being of further assistance.
          Just an update, I think I mostly figured it out in the case that anyone else needs such a feature.

          As pointed out the values I was looking for are there, in the "Executions" object.

          I was able to use:
          Code:
          myAccount.Executions[myAccount.Executions.Count-1].Time
          Where myAccount is the account you lock in the setdefaults(SIM101 or whatever you want), "Executions" gives you the object that contains all of the trades taken, and index into the most RECENT transaction via "myAccount.Executions.Count-1".... with the relevant feature of "Time".

          I should be able to sort on that object to find exactly the things I need to get the values I want.

          Thanks!

          Comment


            #6
            Update.... Ok, I just realized what the other guy was talking about in the thread that was linked, whihc is that the trades shown in executions are only present until you restart NT. I noticed this as I count the number of trades, and it only shows what exists since I started NT today.

            Comment


              #7
              Originally posted by forrestang View Post
              Update.... Ok, I just realized what the other guy was talking about in the thread that was linked, whihc is that the trades shown in executions are only present until you restart NT. I noticed this as I count the number of trades, and it only shows what exists since I started NT today.
              NT indicators/strategies reset after disabling/shutdown. I have the same challenge in my ATM strategy. The only solution I know is to write to a txt file your count number using StreamWriter . And then at the start read this value with StreamReader.
              Last edited by Leeroy_Jenkins; 01-23-2021, 04:12 AM.

              Comment


                #8
                I have a question about getting the account, and making sure one is present.

                Assume I will have a user input that is the string of the account name. For this example, assume it is the SIM101 account that is the default. So a user may enter the the string "Sim101" into the input field. In the snipped below, the variable MyAccountString is that input variable that would hold the value "Sim101".

                I may have a state.configure block that looks like this:
                Code:
                private Account myAccount; //This variable will be at the class level
                
                else if (State == State.Configure)
                {
                    lock (Account.All)
                    myAccount = Account.All.FirstOrDefault(a => a.Name == MyAccountString);
                }
                The goal will eventually be to use the Executions object to get various details of the previous orders that may have recently been placed. For example, to get the number of hours since the last trade, I could use:
                Code:
                string timeSince = (DateTime.Now - myAccount.Executions[myAccount.Executions.Count-1].Time).Hours.ToString("00") //string holding # of hours of most recent trade


                So my questions....

                How do I go about checking that a valid account EXISTS, that matches the input string?
                Does that account lock I typed above need to happen in the State.Configure block, and is that where I would want to check if an account exists by the name of the input string?

                Do I need to dispose of anything, as mentioned HERE?

                Looking at the methods available on the Executions object, it has everything I need... I just need to know how to properly sync to an account(via input string) and check if it exists(imagine a user inputting the wrong name), and to know if there is anything special I need to do before calling/using the Executions object(as shown in the snippet above capturing the hours)?

                Comment


                  #9
                  Hello forrestang,

                  I would suggest to just use the account type converter here to build the account dropdown list. You could then ensure a valid account was selected because the user can't type something random in.

                  Code:
                  [TypeConverter(typeof(NinjaTrader.NinjaScript.AccountNameConverter))]
                  public string AccountName { get; set; }
                  You would then need to keep your finding logic in State.Configure or later so the users selection could be used.

                  The lock syntax is a C# feature to lock a collection so that is not changed while you are using it. Thats used just like an if condition, in that use case the line following the lock syntax is locked in that context or the finding the account line.

                  Do I need to dispose of anything, as mentioned HERE?
                  Yes if you make any subscriptions to events you will need to unsubscribe from them in state terminated.

                  Checking if the account object exists can be achieved by using a null check:

                  Code:
                  if(myAccount != null) { //do something }
                  This type of condition would be needed in terminated to make sure the account exists before trying to un subscribe as an example.


                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  167 responses
                  2,260 views
                  0 likes
                  Last Post jeronymite  
                  Started by warreng86, 11-10-2020, 02:04 PM
                  7 responses
                  1,362 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by Perr0Grande, Today, 08:16 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Perr0Grande  
                  Started by elderan, Today, 08:03 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post elderan
                  by elderan
                   
                  Started by algospoke, Today, 06:40 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post algospoke  
                  Working...
                  X