• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 quantera, Today, 05:38 PM
        0 responses
        3 views
        0 likes
        Last Post quantera  
        Started by ciro1963, Today, 03:58 PM
        0 responses
        2 views
        0 likes
        Last Post ciro1963  
        Started by swcooke, Today, 02:48 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by SOFI777, Today, 01:03 PM
        5 responses
        30 views
        0 likes
        Last Post SOFI777
        by SOFI777
         
        Started by Gerard111, 09-23-2015, 07:25 AM
        2 responses
        1,207 views
        0 likes
        Last Post NinjaTrader_ChristopherD  
        Working...
        X