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

  • JerryWar
    replied
    Jessica
    Thanks for the detailed explanation

    Jerry

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    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, 10:31 AM.

    Leave a comment:


  • JerryWar
    replied
    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.

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    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

    Leave a comment:


  • JerryWar
    started a topic Moving average on Multiple time frame Charts

    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, 02:43 PM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by slimcactus, Today, 10:26 AM
0 responses
2 views
0 likes
Last Post slimcactus  
Started by d122y, Today, 10:20 AM
0 responses
2 views
0 likes
Last Post d122y
by d122y
 
Started by trader3000a, Today, 09:23 AM
2 responses
7 views
0 likes
Last Post trader3000a  
Started by CharlieBoy, Today, 08:37 AM
1 response
5 views
0 likes
Last Post NinjaTrader_JustinD  
Started by srbdoc, Today, 08:41 AM
1 response
6 views
0 likes
Last Post NinjaTrader_RyanS  
Working...
X