• 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

Indicator different time frame

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

    Indicator different time frame

    Hi,is it possible have an indicator with a different time frame than the chart?

    Thanks

    #2
    Hello Italianforex,

    Thank you for your post.

    Yes, you can absolutely have an indicator plotting on a different time frame from your chart.

    You could do this in one of two ways. One would be to use a secondary data series on the chart and simply have the your indicator calculate on that secondary series, but apply it to plot over your primary data series.

    Here is an example of how to plot an indicator based off of a 5 minute chart, but plotted over a 2 minute chart:

    * First create a 2 minute chart as usual (File>New>Chart...)
    * Right click within your chart window and select Data Series...
    * Add a second data series, the same instrument as your 2 minute chart, but set the parameters to be a 5 minute chart
    * You should now see two-paneled chart with 2 minute on top and 5 minute below
    * Next, right click and select Indicators... Find your indicator in the top left hand corner, and click New to add it.
    * In the parameters to the right, set your Input Series to your 5 minute data series (Close)
    * Set your Panel to 1,and click OK
    * Next, move your pointer to the right of your price axis (y-axis) on the top panel of your chart window, and right click>Maximize.

    You now should see a 2 minute chart, with an indicator plotted over it based off of a 5 minute Data series.

    Your other option would be to create your own indicator that utilizes a secondary data series.

    Here's a simple example that plots a 5 minute EMA over any other primary time frame using some best practices, including checking on the current bar, using BarsInProgress to plot on the primary data points, and using a private EMA variable to hold our EMA values from the secondary series:

    private EMA EMA1; // we create a new array of EMA values

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "EMAon5minData";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;

    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;

    AddPlot(Brushes.LightCoral, "EMAPlot");
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 5); //add our secondary 5 minute data series for calculating the EMA
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(BarsArray[1], 20); //set EMA here so we make sure it's calculated on the secondary data series
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1 || CurrentBars[1] < 20) // make sure there's at least one bar for primary series and at least 20 of the secondary series prior to processing
    return;

    if(BarsInProgress == 0) // if OnBarUpdate was called from the primary bar series, then set the current value to the latest EMA1 value
    Value[0] = EMA1[0];
    }

    Here is a link to our help guide with additional information regarding working with multiple data series/time frames in NinjaScript:
    https://ninjatrader.com/support/help...nstruments.htm

    If I may be of further assistance, please let me know.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello Kate,
      any NT7 example for the same issue ? Thanks

      Comment


        #4
        Hello gplatis,

        Thank you for your post.

        The first portion of my example, setting the chart up with two time frames and then hiding one, will work on both NT7 and NT8.

        More information about working with multi-series scripts can be found here: https://ninjatrader.com/support/help...nstruments.htm

        Here's an example for NT7:
        Code:
        protected override void Initialize()
        {    
         // adding a 10 minute series of the same instrument to the script      
        Add(PeriodType.Minute, 10);
        }  
        
        protected override void OnBarUpdate()
        {      
        
        // make sure that all series contain enough bars before beginning      
        // this is checking to see that each series contains at least one bar      
        
        if (CurrentBars[0] < 1 || CurrentBars[1] < 1)           return;      
        
        // in my example, I just want the stochastics D value of the primary series to be printed if the primary series is calling OnBarUpdate() and the stochastics D value of the secondary series to be printed if the secondary series is calling OnBarUpdate()    
        if (BarsInProgress == 0)          
        Print(Stochastics(BarsArray[0], 3, 14, 7).D[0];      
        
        if (BarsInProgress == 1)          
        Print(Stochastics(BarsArray[1], 3, 14, 7).D[0];
        }

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ArmKnuckle, Today, 07:55 PM
        0 responses
        1 view
        0 likes
        Last Post ArmKnuckle  
        Started by Nabil, Today, 07:46 PM
        0 responses
        1 view
        0 likes
        Last Post Nabil
        by Nabil
         
        Started by mohdhm, Today, 04:37 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by trader14, Yesterday, 08:23 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by bigsurftrader, 02-24-2017, 12:23 AM
        4 responses
        1,162 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X