Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get current price Info from addon

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

    Get current price Info from addon

    Hello,

    I'm making my first addon for Ninjatrader and I want to control the charttrader buymarket and sellmarket buttons so that before launching a trade it validates a list of things

    I have managed to intercept the click event and if it doesn't meet my conditions I can cancel the execution of the trade

    I need help to access from the button event to the active chart of the window to which the button that launched the event belongs, I need to read the asset that is on the chart and know if it has exceeded the maximum/minimum of the previous day. If the price has not reached the maximum/minimum of the previous day, I do not allow launching a market trade

    I have managed to access the Chart object, parent of the button object that launches the event, but I don't know how to access the chart and read the last quote and the maximum and minimum values ​​of the previous day

    Can anyone help me?

    Thanks​

    #2
    Hello Powerbucker,

    Welcome to the NinjaTrader forums!

    Please note, any script that disables or modifies the intended functionality of NinjaTrader is not supported.

    I would recommend instead adding a separate panel with your own custom buttons.

    The SampleWPFModifications reference sample in the help guide provides a demonstration of both adding a panel and locating ChartTrader buttons.


    If the script is an indicator, getting the current market price and previous day's high and low is straight forward.
    The current market price would be the Close[0] (or GetCurrentAsk() / GetCurrentBi()), while the previous day high and low can be retrieved by calling PreviousDayOHLC().PriorHigh[0] / PriorDayOHLC().PriorLow[0].



    From an addon window you would need to do a BarsRequest to request data.

    Below is a link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the answer.

      I'm in an addon and I need a custom button that checks the following:

      If the current price of the asset in the charttrader is above or below yesterday's maximum or minimum.

      My question is: is it better to check this through a BarsRequest every time you press the button?

      Or is it better to check it by means of an indicator and from the addon access the indicator in some way? What is more optimal?

      Any better idea?

      Thank you​

      Comment


        #4
        Hello Powerbucker,

        As you are needing something from the chart, an indicator might be a better to go as this would be applied to the chart.

        From an addon you would need undocumented code to loop through all windows, find the window you want, and get the chart trader UIElements.

        This forum post has some sample code of this, but note, this is not officially supported.


        Further, in an indicator you can use the PriorDayOHLC indicator instead of having to load data from a BarsRequest and using custom logic to determine the high and low of the previous day.

        "My question is: is it better to check this through a BarsRequest every time you press the button?"

        From an addon you could save the values to variables after performing logic to determine the previous days high and low instead of running a new bars request on every button click, as the values from yesterday are not going to be changing. But you would need custom logic that determines when the new session starts to reset these variables.

        "Or is it better to check it by means of an indicator and from the addon access the indicator in some way? What is more optimal?"

        There isn't a documented approach of accessing an indicator on a chart from an addon, but using an indicator would be easier.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply,

          Since I want to avoid entering an order if the conditions are not met, I'm thinking of doing it another way. Is there an event that goes off before entering a trade? For example, there is the OnExecutionUpdate event for the account when an order is entered, is there a way to cancel it? For example, if I enter an order through the chartrader (buttons) or through the menu (limit/stop orders), I can control through a "BeforeOrdeExecution" event that the conditions are met, and if they are not met, cancel the execution of the orders.

          Is this possible?

          Thanks​

          Comment


            #6
            Hello Powerbucker,

            You could add your own custom button that when clicked runs logic to decide to submit an order or not submit an order.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi,

              Thanks for your answers, I've already managed to orient myself on what I need my addon to do.

              But, I'm making this addon to control a list of things when I place an order on the market. Is there a way to protect the addon so that at that time I can't change the source code and can't delete it from ninja? That to modify it I have to do it in another context. That when creating an operation, I can't modify the addon, or it's not easy to do so at that time.

              Thanks​

              Comment


                #8
                Hello Powerbucker,

                It's not possible to prevent an open source script from being edited, but you can export as a closed source assembly and then re-import it and delete the original open source script.
                (I would recommend you export the script as open source as well so that you can keep the open source code should you want to work on it again)

                Also, it would not be possible to prevent a script from being removed.

                To export your script as an assembly do the following:
                1. Click Tools -> Export -> NinjaScript
                2. Click the 'add' link -> check the box(es) for the script(s) you want to include -> click OK
                3. Check the option labelled 'Export as compiled assembly'
                4. If you have Agile.NET installed and would like to use this, check the box labelled Protect compiled assembly
                5. Click Export -> enter a unique name for the file in the Dialog window
                6. Choose a save location -> click Save
                7. Click OK to clear the export location message
                By default your exported file will be in the following location:
                • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                Below is a link to the help guide on Exporting NinjaScripts.
                https://ninjatrader.com/support/help...nt8/export.htm
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  ok !!

                  I need to check also:

                  - when the chartTrader is activated -> the OnWindowCreated event tells me when a window is opened, but not if the user opens a new tab. Is there a way to detect a new active charttrader? I need to know this in order to customize the buttons
                  - check if for an account, today I have lost more than X quantity
                  - check if for an account, today there has been any operation where more than X has been lost

                  Thanks​ !!

                  Comment


                    #10
                    Hello Powerbucker,

                    "when the chartTrader is activated -> the OnWindowCreated event tells me when a window is opened, but not if the user opens a new tab. Is there a way to detect a new active charttrader? I need to know this in order to customize the buttons"

                    The ChartTrader is a grid that is either visible or not visible and is not a window.


                    The visibility shouldn't be necessary to add buttons. Have a look at the SampleWPFModifications which adds buttons.


                    "check if for an account, today I have lost more than X quantity"

                    Loop through the <Account>.Executions and add up the quantity of each execution.



                    "check if for an account, today there has been any operation where more than X has been lost"

                    This would require some advance logic to pair up orders based on first in first out.
                    But you would still be looping through the <Account>.Executions collection and comparing the prices of each execution.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi,

                      Regarding the charttrader, what I really need to know is when a new chart window is opened, in order to customize the charttrader for that window. When it is opened from the menu, I detect it with the OnWindowCreated event, but if it is opened by adding a new tab to an existing window, I cannot detect it
                      Can I subscribe to some event to detect new tabs?

                      I understand that the structure is a tab, which contains a window, which contains a chart and so on. Given a tab, how do I get to the charttrader?

                      Any documentation on the window hierarchy?

                      In the end, I need, for each opened chart window, to know which account is active and which asset is selected. (I am now getting it from the charttrader object -> chartTrader.Instrument and chartTrader.Account)

                      Thanks​

                      Comment


                        #12
                        Hello Powerbucker,

                        There is not a separate chart trader grid for every tab. There is only one and it's created when the window is opened.

                        When new tabs are created and/or switched to the instrument selector changes it's value to match what's loaded in that tab.

                        There is no documentation on the window hierarchy. A few common automation ids are provided.


                        The chart trader account selector does not change when changing / creating tabs.
                        However, you can attach an event handler to the SelectionChanged event when the user manually changes this.

                        "Given a tab, how do I get to the charttrader"
                        The chart trader is not per tab, there is only one.

                        To get the ChartTrader grid use the code from the sample in the article linked above.
                        "​Finding the ChartTrader grid

                        ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                        {
                        Grid chartTraderGrid = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartWindowChartTraderControl") as ChartTrader).Content as Grid;
                        }));​"

                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Your help has been greatly appreciated.

                          I need to know something else. From an addon, is it possible to access an element of a chart? For example, an area marked with a horizontal line?

                          I need to control from an addon that I do not enter the market if the price has not exceeded an area that I have marked on the chart. How can I do this?

                          Thanks​

                          Comment


                            #14
                            Hello Powerbucker,

                            There are not any supported tools for getting this in an addon.

                            The ListChartsIndicatorsExample​ linked in my prior post has some unsupported code for getting objects from charts.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Ok,

                              Can I save values ​​to global variables from an indicator so I can read them from the addon?

                              For example, I make an indicator that reads the horizontal lines of the chart and saves the values ​​to global variables, and then I can read them from the addon to check if the input meets the requirements.​

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              577 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              334 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              553 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              551 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X