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

Referencing DataSeries with multi timeframe indicators

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

    Referencing DataSeries with multi timeframe indicators

    Hello everyone,

    I have read every single existing thread on this topic but I still have not found a solution to my problem.

    Here it is: I have created a multi-timeframe indicator called ContextAnalyzer. This indicator performs an analysis of two timeframes and populates a DataSeries object (myContextSeries) with the results of the analysis (a single value for each bar of the primary data series). I have completely tested this indicator and it works like a charm when applied to a chart. I have even done as far as printing the CurrentBar and myContextSeries[0] for each bar of the primary series to verify the logic. So far, so good....

    myContextSeries is exposed publicly via the following code:

    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries ContextMOM
    {
    get { return myContextSeries; }
    }

    So far I assume that all is good...

    I would now like to use the values of the DataSeries referenced above in another indicator, let's call it ContextConsumer. Here is my test code for this:

    Code:
        public class ContextConsumer: Indicator
        {
            private ContextAnalyzer myContext;
    
            protected override void Initialize()
            {
                Overlay                = true;
            }
    
            protected override void OnStartUp()
            {
                myContext = ContextAnalyzer(PeriodType.Minute,3);
            }
            protected override void OnBarUpdate()
            {
    
                double dContext = myContext.ContextMOM[0];
    
                if (dContext == -2) BarColor = Color.Red;
                if (dContext == -1) BarColor = Color.Magenta;
                if (dContext == 1) BarColor = Color.LightBlue ;
                if (dContext == 2) BarColor = Color.Blue ;
    
            }
    The problem with all this is that the values returned by dContext are completely out of whack with the values produced by ContextAnalyzer. I can't quite diagnose the problem and have no idea as to what is going on.

    Any help is greatly appreciated.

    #2
    Hello,

    Thanks for your forum post.

    When using multi series and data series objects. You must sync the data series to the object it will be tracking. Please see this guide:

    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


    Let me know if I can be of further assistance.

    Comment


      #3
      Hi Brett,

      I have already read that post several times and my code is in line with it.

      The DataSeries myContextSeries is correctly synchronized to the primary series in ContextAnalyzer. I didn't create a secondary series for the other timeframe since I didn't have any use for it.

      Is any synchronization required in the calling indicator "ContextConsumer" required?

      David

      Comment


        #4
        David,

        Not exactly sure what you are doing. We do not support this "ContextAnalyzer" object you are calling nor would have any idea what it is. DataSeries are only able to sync to DataSeries as outlined in the reference sample. You can do one of the following:

        1. In Initialize() you call someDataSeries = new DataSeries(this);
        The "this" reference syncs it to the primary bars.

        2. In OnBarUpdate() you can sync to a secondary bars series.
        someDataSeries = new DataSeries(SMA(BarsArray[1], 50));
        The BarsArray[1] is what the someDataSeries is synced to.

        You are doing neither of the above.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh - there is a similar thread here: http://www.ninjatrader.com/support/f...622#post213622

          ContextAnalyzer is simply my indicator, mentioned in this thread as an example. This indicator uses a second timeframe to perform an analysis and saves the results of this analysis in a DataSeries object. This works perfectly fine. The problem that I am facing however, is when trying to use this DataSeries from yet another indicator that only has primary bars. When doing this, the values returned by the DataSeries of ContextAnalyzer are all wrong. In the other thread, snaphook seems to be experiencing the exact same problem. I do not believe that the example that you provide with the secondary dataseries that is synced in OnBarUpdate() has any bearing on this problem.

          Comment


            #6
            Trader,

            Just so that I understand correctly. Your trying to use variables from another indicator in another indicator or strategy? Therefor your trying to do communication between strategies/indicators?

            I look forward to assisting you further.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by traderqz, Yesterday, 09:06 AM
            3 responses
            21 views
            0 likes
            Last Post NinjaTrader_ThomasC  
            Started by f.saeidi, Today, 10:19 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by kujista, Today, 06:23 AM
            5 responses
            17 views
            0 likes
            Last Post kujista
            by kujista
             
            Started by traderqz, Today, 12:06 AM
            3 responses
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by RideMe, 04-07-2024, 04:54 PM
            5 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X