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

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.

    The C# namespace alias qualifier `::` is used to access a member of an aliased namespace. The `::` operator is often used with the `global` alias, an alias for the global namespace



    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:
        [FONT=Courier New]#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];
                }
            }
        }[/FONT]
        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 love2code2trade, Yesterday, 01:45 PM
          4 responses
          27 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          26 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Working...
          X