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

running code when the trading buttons are pressed

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

    running code when the trading buttons are pressed

    How can I respond to events upon when an order is created (it is manual trading) ? are there tutorials or sample anywhere?

    What should I make? an indicator? a strategy? something else?

    let's say I just want to make a popup when I press buy market or a close existing orders button

    #2
    Hello NinjaCustomer,

    Thanks for your post.

    You could make an indicator that accomplishes this, but in general, you would be using AddOn code to monitor Account OrderUpdate, PositionUpdate and ExecutionUpdate events to meet your goal.

    We don't have any samples prepared to show you how you can identify manual submissions that are handled internally, so your best way forward would be to print out the OrderUpdate, ExecutionUpdate, and PositionUpdate events while manually submitting orders so you can see how you can properly respond to these events on your own. I spent some time analyzing OrderUpdate events to identify ATM strategies to calculate ATM strategy PnL using AddOn code. I've attached the indicator I used to monitor the Order update events, but please keep in mind that we do not document how manual submissions are handled internally and there may be changes to how this is done that you will need to correct should they change.

    I've included links for Account OrderUpdate events, PositionUpdate events and ExecutionUpdate events below. This information is publicly available.

    OrderUpdate events - https://ninjatrader.com/support/help...rderupdate.htm

    ExecutionUpdate events - https://ninjatrader.com/support/help...tionupdate.htm

    PositionUpdate events - https://ninjatrader.com/support/help...tionupdate.htm

    Please let us know if we can be of further assistance.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      thanks, how could I get a list of open positions? I'm sure there must be a sample for that somewhere, right? (manually opened not strategy opened, if that makes a difference)

      Comment


        #4
        Hello NinjaCustomer,

        You can loop through the Account's Positions collection to track this. Manual submissions can all be tracked through the account itself, so any other items in the Account class can help here.

        Account.Positions - https://ninjatrader.com/support/help...ns_account.htm

        Account - https://ninjatrader.com/support/help...ount_class.htm

        Let us know if we can be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          I just tried to create a sample addon just to see how addons work and I have a few questions

          1) where is the entry to the addon? Right now it just generated an OnStateChange() ? for me to monitor manually created positions, where should my code "start" ?

          2) how does one install an addon? I just compile it?

          Comment


            #6
            Hello NinjaCustomer,

            The AddOnFramework example from our help guide can be referenced for how an AddOn can be built.

            AddOn windows typically hook in with OnWindowCreated and check for when the Control Center is created. From there, the AddOn adds a UI item to the Control Center which then opens the window. You could use a similar entry point to have your AddOn code added once NinjaTrader starts.

            The AddOnFramework example and documentation on the AddOn framework are linked below.

            AddOn development overview - https://ninjatrader.com/support/help...t_overview.htm

            Please let us know if you have any questions.
            JimNinjaTrader Customer Service

            Comment


              #7
              ah so if I want to be windowless, then an indicator is a better choice? for this current thing.. I don't really need to know when buttons are pressed now that I think of what I want to do more, I just need to be able to access the account open / closed positions and monitor them

              Comment


                #8
                Hello NinjaCustomer,

                You can make windowless AddOns. This would be an AddOn NinjaScript that simply subscribes to the Account monitoring events and doesn't make a window. This could hook in the same way as an AddOn window adds a UI element to the Control Center.

                You could also have an indicator that implements the AddOn code.

                How you want to implement it will be up to you.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  will this OnWindowCreated be called multiple times? is there a way to detect the first time it is called? or should i just set a flag variable to prevent running my code more than once?

                  Comment


                    #10
                    Hello NinjaCustomer,

                    You can use the output window to see how often OnWindowCreated gets called. It will be created once for the Control Center when opening NinjaTrader, and you can reference the AddOnFramework example for how this is done.

                    Using the output window with an AddOn - https://ninjatrader.com/support/help...g_concepts.htm

                    Let us know if you have any questions using the debug output.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      I don't understand the sample code "AddOnFramework.cs"

                      it casts window as ControlCenter in OnWindowCreated()

                      but how does it know that it is the control center window and not some other window?

                      I did a simple addon that shows a messagebox in onwindowcreated.. and the messagebox is shown maybe 6 times upon startup of NT8

                      so I think it is calling it for every window created, not just the control center - either that or calling the control center many times

                      Comment


                        #12
                        would locking Account Positions have any affect upon the ability to enter new positions or close existing ones manually?

                        would there be any problems not locking it and just reading it? I don't want to change any positions
                        Last edited by NinjaCustomer; 12-12-2018, 01:35 AM.

                        Comment


                          #13
                          I added a parameter for the addon via the wizard... but I don't understand where to set the parameter? You just assign the variable in the code? or is there some UI way to modify a setting of an addon?

                          Comment


                            #14
                            what is the max C# version supported in the Ninjascript editor?

                            Comment


                              #15
                              Hello NinjaCustomer,

                              When the AddOnFramework window opens, it adds a UI element, and checks if the UI element exists so it doesn't add twice. The same approach can be used with a bool to do something once.

                              Locking a collection prevents issues when reading when it may be modified externally by another thread when you are looping through that collection.

                              An AddOn window would not have a config window to set parameters. You would make a form yourself where you can add inputs.

                              NinjaTrader 8 uses .NET 4.5 and C# 5.0.

                              AddOn code is reserved for advanced NinjaScript programmers that want to make custom tools externally to strategies and indicators. If the approach is too difficult, I may recommend creating an indicator that uses this code similar to the example I shared in post 2.

                              Let us know if we can be of further assistance.
                              JimNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              180 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X