Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing instrument on charts changes strategy instrument

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

    Changing instrument on charts changes strategy instrument

    Hi,

    I would like to submit my strategies from the chart, but once submitted, I would like my strategy to be locked to that specific instrument.


    When I change the instrument with the market analyzer color link, my strategy gets applied to the new charted instrument. This behavior does not occur if I launch my strategy from the control center strategy tab, but I would like to start my strategies from the charts.

    Thanks for your help!

    #2
    Hello RT001,

    Thanks for your post.

    You could hard code the data series into the strategy and skip processing for BarsInProgress == 0, but keep in mind, if you change the instrument on the chart, the strategy will restart and recalculate.

    You would be best off starting from the Control Center or from a separate chart so the strategy does not restart with each instrument change on the chart.

    For more information on programming a multi time frame/multi series script, please see below.

    https://ninjatrader.com/support/help...nstruments.htm

    Please let us know if you have any questions.

    Comment


      #3
      Hi Jim,

      thank you very much for your reply - it describes well the behavior of my script.

      Indeed, I am trying to avoid at all cost that my strategy changes ticker, restarts, etc

      It's ok for me to launch it from the control center, however I am not able to draw horizontalLines on my charts (I need to see some price informations related to my strategy), which are crucial in my strategy. How can I draw my lines on all charts showing the instrument of the strategy if I start the strategy from the control center?

      Thanks for your help and patience.

      Comment


        #4
        Hello RT001,

        I would suggest having separate charts open for each strategy, or to have the strategy applied to different chart tabs. Switching instruments on the chart will cause the strategy to restart, which may not be desired when you want to leave the strategy to place trades.

        Comment


          #5
          Is there any way to interact with the charts with the strategy instrument if the strategy is launched from the control center? I am really looking to dig further in that part of the API.


          I tried to look into the IDrawingTool (i.e. IsGlobalDrawingTool) interface to interact with all charts opened with instrument, but I am not too sure how to implement this. My draw object is
          Code:
          Draw.HorizontalLine(this, @"slxLine", true, slxStop, Brushes.OrangeRed, DashStyleHelper.Solid, 2);
          As you can guess, I have implemented a custom stop mode (slxStop) and I need to see somewhere where my exit price since it's not showing that update in the control center (and I cannot look at the output window all the time for this).

          I am well advanced in my ninja script and I would really avoid as much as possible to open many charts, I have quite a few opened already.

          Thank you!

          Comment


            #6
            Hello RT001,

            If the strategy is added to the Control Center, it would not have access to a chart. Supported NinjaScript would involve having the strategy added to the chart so you can interact with the chart.

            If you want to have a strategy find a drawing object on a chart when it is added from the Control Center, you may be able to find a work around by looping through windows and finding a a drawing object in the DrawObjects collection. Keep in mind, this sort of approach would begin to escape what would be supported NinjaScript, but you may be able to navigate that with the direction here.

            DrawObjects collection - https://ninjatrader.com/support/help...rawobjects.htm

            An example for looping through charts to find a chart whose primary data series is the same as the script running, please see below.
            Code:
            foreach (var window in NinjaTrader.Core.Globals.AllWindows)
            {
                // check if the found window is a Chart window, if not continue looking
                if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
            
                window.Dispatcher.InvokeAsync(new Action(() =>
                {
                    // try to cast as a Chart, if it fails it will be null
                    var foundChart = window as NinjaTrader.Gui.Chart.Chart;
            
                    // make sure we found a chart
                    if (foundChart == null) return;
            
                    if (foundChart.ActiveChartControl.Instrument == Instrument)
                        Print("Found");
                }));
            }
            If you are looking for a way to draw on a chart from a strategy added from the Control Center, you will at the very least need a script (like an indicator) added to the chart so you can draw on that chart programmatically. You could consider finding a custom indicator on a specific chart, that has public methods that allow you to trigger drawing from external scripts. This also would escape what we would consider supported NinjaScript, but you may find the work in the attached script helpful.

            We will not be able to assist further with the items mentioned here that escape supported NinjaScript, but we hope this information is helpful to you.
            Attached Files

            Comment


              #7
              Very helpful Jim, knowing these precise limits will save me dozens of hours. Thanks for your help again!

              Comment


                #8
                Yep this idea is brilliant, I could have a placeholder indicator in the templates of my charts and activate / update it with my strategy if the instrument matches. Thanks again

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                48 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                66 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X