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

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:


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

    Comment


      #3
      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


        #4
        Originally posted by NinjaTrader_Kate View Post
        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:


        If I may be of further assistance, please let me know.
        It seems like I followed the instructions above on trying to add a second data series to my chart. However, the second data series candles are showing up and I don know how to hide the candles themselvs.

        Comment


          #5
          Hello sashol3,

          Thanks for your notes.

          If you followed the first set of instructions, you could consider setting the candle color properties for the second data series candles to Transparent to 'hide' those candles.

          Right-click on the chart window, select 'Data series', select the second data series on the left side of the Data Series window, use the 'Color for up bars' drop-down menu in the Properties section on the right to set the color to 'Transparent', use the 'Color for down bars' drop-down menu in the Properties section to set the color to 'Transparent', and click OK.

          See the 'How to edit Data Series parameters' section of this help guide page for more information: https://ninjatrader.com/support/help...price_data.htm
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by geotrades1, Today, 10:02 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by ender_wiggum, Today, 09:50 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by rajendrasubedi2023, Today, 09:50 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by bmartz, Today, 09:30 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          3 responses
          26 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X