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

Accessing all charts from an indicator

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

    Accessing all charts from an indicator

    Hello,

    Let's say I have 4 charts opened. One each of them I have an indicator (doesn't matter which one) and I'd like to make another indicator (on one chart only) that will read data from all other indicators on all charts.

    Is such access possible or is it limited to current chart only ?

    Regards,
    Darek

    #2
    Technically this is possible, but you should NOT do that this way.

    Instead you need to create one indicator which will use all instruments you need (via AddDataSeries) and then create all required indicators based on loaded DataSeries, for example if you have 3 loaded instruments (including main one), here is example how to create 3 simple moving averages:

    SMA(BarsArray[0], 14); //main instrument
    SMA(BarsArray[1], 14); //another loaded instrument
    SMA(BarsArray[2], 14); //another loaded instrument
    Last edited by login_dejavu; 02-18-2019, 01:34 AM.

    Comment


      #3
      There are reasons I'm looking for this solution:

      1) The indicator is VERY rosource-heavy and I don't want to load it again.
      2) I need to keep it on separate charts because one will be used as a strategy for automatic trading, other will be for manual trading - so I need to keep it on separate charts.

      I'd be interested in seeing how the not recommended way would look like.

      Comment


        #4
        Hello dariuszszyc,

        Thanks for your post.

        login_dejavu is correct that the supported way would be to have the script add the data series so it can be used in a synchronized fashion.

        If you are referring to NinjaTrader 7, this would be done with Add() which is parallel to AddDataSeries(). I'll include information for both NinjaTrader 7 and NinjaTrader 8 for the threads reference as more may be possible through what NinjaScript we have documented for NinjaTrader 8. Since the data is not synchronized when accessing in this fashion, it would not be supported and would be a Use At Your Own Risk type of application.

        NinjaTrader 7

        This goal may be possible with MySharedMethods and static variables in your own namespace. I'll include reference documentation and an example snippet below.

        User Defined Methods:

        Code:
        namespace NinjaTrader.Indicator
        {
            /// <summary>
            /// This file holds all user defined indicator methods.
            /// </summary>
            partial class Indicator
            {
                public double GetSharedDouble()
                {
                    return NinjaTrader.NinjaScript.MyCustomSpace.MySharedMethods.SharedDouble;
                }
        
                public void SetSharedDouble(double dbl)
                {
                    NinjaTrader.NinjaScript.MyCustomSpace.MySharedMethods.SharedDouble = dbl;
                }
            }
        }
        
        namespace NinjaTrader.NinjaScript.MyCustomSpace
        {
            public partial class MySharedMethods
            {
                public static double SharedDouble
                { get; set; }
            }
        }
        Getting/Setting
        Code:
        protected override void OnBarUpdate()
        {
            SetSharedDouble(Close[0]);
            Print(GetSharedDouble());
        }
        User Defined methods documentation - https://ninjatrader.com/support/help...ed_methods.htm

        NinjaTrader 8

        If you want to look into accessing the a data series externally, this would involve finding the data series from a particular ChartBars object in a chart's ChartObjects collection. The following snippet should be helpful to get you started.

        Code:
        Chart chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;
        foreach (NinjaTrader.Gui.Chart.ChartPanel panel in chartWindow.ActiveChartControl.ChartPanels)
        {
            foreach (Gui.NinjaScript.IChartObject thisObject in panel.ChartObjects)
            {
                if (thisObject is ChartBars)
                {
                    ChartBars myFoundChartBars = thisObject as ChartBars;
                    if (myFoundChartBars.Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Minute
                        && myFoundChartBars.Bars.BarsPeriod.Value == 1)
                        Print("1 Minute Data Series found");
                }
            }
        }
        Similar to NinjaTrader 7's approach detailed above, another idea would be to have your NinjaScripts use static variables in the AddOn namespace to implement intercommunication between your scripts. You would then have your resource intensive indicator write to the static variables so other scripts may access them. I'll include a link to a thread which discusses using this sort of approach below.

        http://ninjatrader.com/support/forum...104#post457104

        Keep in mind, these approaches are not the advised and supported way to access data in NinjaTrader, and will involve some additional effort to get that sort of approach working.

        Let us know if you have any additional questions.
        Last edited by NinjaTrader_Jim; 02-18-2019, 09:36 AM.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Working...
        X