• 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

Moving average on Multiple time frame Charts

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

    Moving average on Multiple time frame Charts

    In NT7 a Horizontally drawn line can be set to appear on Multiple charts of the same Symbol. What is the simplest way from within an indicator to do the same thing with
    Example: a Moving Average. Lets say Rather than add a moving average on a very Short timeframe chart I could get that value to appear from a Longer time frame chart. The only way I can think of doing this is to make the moving average on the Long Time frame chart a public value and then go thru updating an plotting it on the shorter time frame.

    Is there a simpler way. I am rusty at doing this. If this is the only way is there some sample code you could point to. Some where I seem to remember plot values where public to begin with.

    addendum - I started trying to work thru this and what I don't quite get is how to specify the specific indicator on a specific time frame chart especially if there are multiple indicators and multiple charts.

    example: an Ema Dataseries value on one time frame chart versus and Ema data series value on a different time frame chart.

    Thanks for any guidance.
    Jerry
    Last edited by JerryWar; 05-22-2016, 03:43 PM.

    #2
    Hello Jerry, and thank you for your question.

    Since I can think of a few ways to do what you are describing, if this does not answer your question, would it be possible to provide some pictures of what you are describing working in NT7? Any code samples you are comfortable providing would be helpful as well.

    That said, I can definitely let you know how to enter variables into a publicly accessible scope so they can be used between indicators and strategies in NT8.

    To recap, for NinjaTrader 7, this is very easy. We provide the file (My) Documents\NinjaTrader 7\bin\Custom\UserDefinedMethods.cs . You can store global variables that will be included for all Indicators in this file. Make sure they are part of the Indicator class. For example,


    partial class Indicator
    {
    /// <summary>all the plots from all the indicators</summary>
    public static Plot[][] allThePlots;
    }



    NinjaTrader 8 will not have a similar file. I am including a publicly available link from the MSDN C# documentation which will guide you toward putting together a global scope file in NT8.

    https://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx


    Please let us know if there are any other ways we can help
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Jessica,
      Thanks - Did you mean (My) Documents\NinjaTrader 7\bin\Custom\indicator \UserDefinedMethods.cs ?

      I am a bit confused, So do I have to add that partial class to each indicator and what happens with the naming ?
      example: Builtin EMA has a plot based on the Dataseries Value[0]. If that is global and the EMA is on 3 charts. How do you know which is which to access the right one.
      Or in the partial class definition am I defining it Plot[0][1] etc

      Thanks
      Jerry.

      Comment


        #4
        I did in fact mean (My) Documents\NinjaTrader 7\bin\Custom\Indicator\UserDefinedMethods.cs and (My) Documents\NinjaTrader 7\bin\Custom\Strategy\UserDefinedMethods.cs .

        Anything you put in here will be visible and available to any Indicator without your including anything extra.

        One great way to tell plots apart is with an enum containing named indices. Here is one possible complete implementation which will allow you to dynamically add and reference plots between indicators.

        Code:
        #region Using declarations
        using System;
        using System.ComponentModel;
        using System.Drawing;
        using System.Collections.Generic;
        using NinjaTrader.Cbi;
        using NinjaTrader.Data;
        using NinjaTrader.Gui.Chart;
        #endregion
        
        // This namespace holds all indicators and is required. Do not change it.
        namespace NinjaTrader.Indicator
        {
        
            /// <summary>
            /// This file holds all user defined indicator methods.
            /// </summary>
            partial class Indicator
            {
                /// <summary> Named indices for Indicators in allThePlots </summary>
                enum MyIndicators {Example1, Example2, Example3};
        
                /// <summary>memory for all the plots</summary>
                private static List<Plot[]> allThePlots;
        
                /// <summary>
                /// Adds the passed in plot to the global list
                /// </summary>
                /// <param name=toadd>Plot to add to the global list</param>
                /// <return>index of the newly added plot, or -1 on error</return>
                public int addGlobalPlot(Plot[] toadd)
                {
                  if (allThePlots == null)
                  {
                      allThePlots = new List<Plot[]>();
                  }
                  allThePlots.Add(toadd);
                  return allThePlots.LastIndexOf(toadd);
                }
        
                public Plot[] getPlotsByIndex(int index)
                {
                  if ( (allThePlots == null) || (index >= allThePlots.Count) || (index < 0) )
                  {
                      return null;
                  }
                  return allThePlots[index];
                }
            }
        }
        You can then use (int) MyIndicators.Example1 to refer to the plot from your Example1 indicator. You can customize your naming scheme in your enum to allow for multiple plots per indicator; for example, the 2nd plot in Example 1 could be called Example1b .

        Note that in this simple naive example you would need to ensure you added indicators to your chart in the same hard coded order as in your code. A version where indicators can be added dynamically is easily possible, relying on (int) MyIndicators.Example3 in the provided example. If you went this approach, I would recommend naming your last member of MyIndicators NumberOfIndicators and using this value in addGlobalPlot.
        Last edited by NinjaTrader_JessicaP; 05-23-2016, 11:31 AM.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Jessica
          Thanks for the detailed explanation

          Jerry

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by dshalom9, Today, 08:36 AM
          9 responses
          8 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by stock_wizard_49, 07-11-2020, 06:57 PM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by asmmbillah, Yesterday, 03:03 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by AspenHiker, Today, 08:37 AM
          0 responses
          5 views
          0 likes
          Last Post AspenHiker  
          Started by StarTrader, 07-11-2020, 11:27 AM
          2 responses
          19 views
          0 likes
          Last Post StarTrader  
          Working...
          X