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

Higher Time Period Updating each tick

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

    Higher Time Period Updating each tick

    Dear Sir,

    Is it possible with NinjaTrader to plot:

    a 4000 tick Pivot0.Set((High[0] + Low[0] + Close[0] ) / 3);

    on an 800 tick chart please?

    I am trying to plot Pivot0.Set on the 800 tick chart with each change of the 4000 tick High[0] + Low[0] + Close[0]

    Could please help me with the code to get this to work? Thank you in advance.

    TX

    #2
    Hello tradethebonds,

    Thanks for your note.

    Is Pivot0 a custom data series that you have created? Or is to be a reference to an indicator that you would like to set?

    Is the script you are working on a strategy or an indicator?

    Below are two links to the help guide on how to add a plot and how to set a plot value.

    Add a plot - http://www.ninjatrader.com/support/h...es/nt7/add.htm

    How to set a plot - http://www.ninjatrader.com/support/h...nt7/values.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry,

      Thanks for the links...but I need help to create an indicator plot (High[0] + Low[0] + Close[0] ) / 3) from

      4000 tick on an 800 tick chart please?

      I am trying to get the 800 tick plot to update with each and every change of tick.

      Is there a simple way please?

      Comment


        #4
        Hi tradethebonds,

        Thanks for the clarification.

        The typical bar type (instead of high low close open or last) is this calculation that you are trying to make.

        Using an SMA with a period of 1 would plot this value as is (as in not an average because it is only use 1 bar to calculate).

        I have created a quick video how to accomplish this without any programming necessary.
        http://screencast.com/t/b1CDZpLJmui5

        Please let me know if you have questions about this video.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Appreciate your help very much, thank you!

          The only concern with this solution (which I did know about previously) was that the bars are not equidistantly plotted. They are not evenly plotted.

          Is there a way to achieve this please?

          Comment


            #6
            Hi tradethebonds,

            Try the following code:
            Code:
            protected override void Initialize()
            {
            Add(PeriodType.Tick, 4000);
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
            Overlay				= true;
            }
            
            protected override void OnBarUpdate()
            {
            if (BarsInProgress != 0 || CurrentBars[1] < 1)
            return;
            
            Plot0.Set(Typicals[1][0]);
            }
            Apply this to a 800 tick chart.

            Let me know if this does not work for you.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_ChelseaB, Thank you very much! This was EXACTLY what I have been trying to create!

              I appreciate this support very much, have a great evening!!!!!!!!!!!!!!!!!!!!!!!!

              TX

              Comment


                #8
                Hi tradethebonds,

                Thanks for letting me know this is what you were looking for.

                Please do not hesitate to contact us for any other NinjaTrader inquiries you may have.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Live Plotting of Typicals

                  NinjaTrader_ChelseaB,

                  The code below works extremely well and much APPRECIATED!

                  QUESTION PLEASE:

                  Is there a way to keep the live tick by tick values plotted on the chart please?


                  When I refresh the chart, the LIVE plotting
                  of the TYPICALS returns back
                  to the "END OF BAR CLOSE" values
                  rather than the live tick by tick values
                  created as the chart plots naturally.

                  Please see forty-four(44) second movie to clarify.
                  Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                  Code:
                   protected override void Initialize()
                  {
                  Add(PeriodType.Tick, 4000);
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                  Overlay                = true;
                  }
                  
                  protected override void OnBarUpdate()
                  {
                  if (BarsInProgress != 0 || CurrentBars[1] < 1)
                  return;
                  
                  Plot0.Set(Typicals[1][0]);
                  }

                  Comment


                    #10
                    Hello tradethebonds,

                    To do this set CalculateOnBarClose to false.

                    For example:
                    Code:
                    protected override void Initialize()
                    {
                    Add(PeriodType.Tick, 4000);
                    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                    Overlay                = true;
                    CalculateOnBarClose = false;
                    }
                    Below is a link to the help guide on CalculateOnBarClose.
                    http://www.ninjatrader.com/support/h...onbarclose.htm

                    As well as to a few considerations when using CalculateOnBarClose. In this refer to the section 'How Bar Data is Referenced'.
                    http://www.ninjatrader.com/support/h...nstruments.htm
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks,

                      I did already have this in the code, but it still will disappear with a refresh. But I am reading over the 'How Bar Data is Referenced' and have a question please?

                      Since you suggested the following;

                      if (BarsInProgress != 0 || CurrentBars[1] < 1) return
                      What does the exclamation mark in BarsInProgress mean? ie. BarsInProgress !=0

                      I cannot seem to understand how to keep the live plotting on the chart...every time I load or refresh the chart the live plotting disappears?

                      Comment


                        #12
                        Hi tradethebonds,

                        This is expected. All historical data will be processed as CalculateOnBarClose true. This cannot be changed.

                        Please see the following:
                        http://www.ninjatrader.com/support/h...onbarclose.htm

                        If you would like this to work on each tick in the historical data you will need to add a tick granularity to the script.

                        i.e.
                        Code:
                        protected override void Initialize()
                        {
                        Add(PeriodType.Tick, 4000);
                        Add(PeriodType.Tick, 1);
                        Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                        Overlay                = true;
                        CalculateOnBarClose = false;
                        }
                        
                        protected override void OnBarUpdate()
                        {
                        if (BarsInProgress == 2 || CurrentBars[1] < 1)
                        return;
                        
                        Plot0.Set(Typicals[1][0]);
                        }
                        The BarsInProgress != 0 means that I do not want this to trigger while the first data series with index of 0 is processing.

                        Really it would be better as "if (BarsInProgress == 1)".

                        Below is a link to the help guide on BarsInProgress.
                        http://www.ninjatrader.com/support/h...inprogress.htm
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks,

                          Tried your suggestion; " Really it would be better as "if (BarsInProgress == 1)". "

                          But it has not made the difference.

                          I guess the tick granularity and saving historically is what is needed...but I cannot seem to get.

                          Here is my indicator thus far, if you can take a peek please?

                          Code:
                          #region Using declarations
                          using System;
                          using System.ComponentModel;
                          using System.Diagnostics;
                          using System.Drawing;
                          using System.Drawing.Drawing2D;
                          using System.Xml.Serialization;
                          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>
                              /// Enter the description of your new custom indicator here
                              /// </summary>
                              [Description("Enter the description of your new custom indicator here")]
                              public class DrummondPivotCUSTOM : Indicator
                              {
                                  #region Variables
                                  // Wizard generated variables
                                      private int myInput0 = 1; // Default setting for MyInput0
                                  // User defined variables (add any user defined variables below)
                                  #endregion
                          
                                  /// <summary>
                                  /// This method is used to configure the indicator and is called once before any bar data is loaded.
                                  /// </summary>
                                 protected override void Initialize()
                          {
                          
                              Add(PeriodType.Tick, 4000);
                              Add(PeriodType.Tick, 1);
                          
                          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                          Overlay                = true;
                          CalculateOnBarClose = false;
                          }
                          
                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress == 2 || CurrentBars[1] < 1)
                          return;
                          
                          Plot0.Set(Typicals[1][0]);
                          }
                          
                                  #region Properties
                                  [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                                  [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                                  public DataSeries Plot0
                                  {
                                      get { return Values[0]; }
                                  }
                          
                                  [Description("")]
                                  [GridCategory("Parameters")]
                                  public int MyInput0
                                  {
                                      get { return myInput0; }
                                      set { myInput0 = Math.Max(1, value); }
                                  }
                                  #endregion
                              }
                          }
                          
                          #region NinjaScript generated code. Neither change nor remove.
                          // This namespace holds all indicators and is required. Do not change it.
                          namespace NinjaTrader.Indicator
                          {
                              public partial class Indicator : IndicatorBase
                              {
                                  private DrummondPivotCUSTOM[] cacheDrummondPivotCUSTOM = null;
                          
                                  private static DrummondPivotCUSTOM checkDrummondPivotCUSTOM = new DrummondPivotCUSTOM();
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public DrummondPivotCUSTOM DrummondPivotCUSTOM(int myInput0)
                                  {
                                      return DrummondPivotCUSTOM(Input, myInput0);
                                  }
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public DrummondPivotCUSTOM DrummondPivotCUSTOM(Data.IDataSeries input, int myInput0)
                                  {
                                      if (cacheDrummondPivotCUSTOM != null)
                                          for (int idx = 0; idx < cacheDrummondPivotCUSTOM.Length; idx++)
                                              if (cacheDrummondPivotCUSTOM[idx].MyInput0 == myInput0 && cacheDrummondPivotCUSTOM[idx].EqualsInput(input))
                                                  return cacheDrummondPivotCUSTOM[idx];
                          
                                      lock (checkDrummondPivotCUSTOM)
                                      {
                                          checkDrummondPivotCUSTOM.MyInput0 = myInput0;
                                          myInput0 = checkDrummondPivotCUSTOM.MyInput0;
                          
                                          if (cacheDrummondPivotCUSTOM != null)
                                              for (int idx = 0; idx < cacheDrummondPivotCUSTOM.Length; idx++)
                                                  if (cacheDrummondPivotCUSTOM[idx].MyInput0 == myInput0 && cacheDrummondPivotCUSTOM[idx].EqualsInput(input))
                                                      return cacheDrummondPivotCUSTOM[idx];
                          
                                          DrummondPivotCUSTOM indicator = new DrummondPivotCUSTOM();
                                          indicator.BarsRequired = BarsRequired;
                                          indicator.CalculateOnBarClose = CalculateOnBarClose;
                          #if NT7
                                          indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                                          indicator.MaximumBarsLookBack = MaximumBarsLookBack;
                          #endif
                                          indicator.Input = input;
                                          indicator.MyInput0 = myInput0;
                                          Indicators.Add(indicator);
                                          indicator.SetUp();
                          
                                          DrummondPivotCUSTOM[] tmp = new DrummondPivotCUSTOM[cacheDrummondPivotCUSTOM == null ? 1 : cacheDrummondPivotCUSTOM.Length + 1];
                                          if (cacheDrummondPivotCUSTOM != null)
                                              cacheDrummondPivotCUSTOM.CopyTo(tmp, 0);
                                          tmp[tmp.Length - 1] = indicator;
                                          cacheDrummondPivotCUSTOM = tmp;
                                          return indicator;
                                      }
                                  }
                              }
                          }
                          
                          // This namespace holds all market analyzer column definitions and is required. Do not change it.
                          namespace NinjaTrader.MarketAnalyzer
                          {
                              public partial class Column : ColumnBase
                              {
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  [Gui.Design.WizardCondition("Indicator")]
                                  public Indicator.DrummondPivotCUSTOM DrummondPivotCUSTOM(int myInput0)
                                  {
                                      return _indicator.DrummondPivotCUSTOM(Input, myInput0);
                                  }
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public Indicator.DrummondPivotCUSTOM DrummondPivotCUSTOM(Data.IDataSeries input, int myInput0)
                                  {
                                      return _indicator.DrummondPivotCUSTOM(input, myInput0);
                                  }
                              }
                          }
                          
                          // This namespace holds all strategies and is required. Do not change it.
                          namespace NinjaTrader.Strategy
                          {
                              public partial class Strategy : StrategyBase
                              {
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  [Gui.Design.WizardCondition("Indicator")]
                                  public Indicator.DrummondPivotCUSTOM DrummondPivotCUSTOM(int myInput0)
                                  {
                                      return _indicator.DrummondPivotCUSTOM(Input, myInput0);
                                  }
                          
                                  /// <summary>
                                  /// Enter the description of your new custom indicator here
                                  /// </summary>
                                  /// <returns></returns>
                                  public Indicator.DrummondPivotCUSTOM DrummondPivotCUSTOM(Data.IDataSeries input, int myInput0)
                                  {
                                      if (InInitialize && input == null)
                                          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
                          
                                      return _indicator.DrummondPivotCUSTOM(input, myInput0);
                                  }
                              }
                          }
                          #endregion

                          Comment


                            #14
                            Hi tradethebonds,

                            Change the BarsInProgress check to == 1 will not cause historical data to process with CalculateOnBarClose as false. This cannot be changed.

                            if (BarsInProgress == 0)
                            and
                            if (BarsInProgress < 1)

                            These two checks mean the same thing. 0 is the only number less than one so if 0 this would be true.

                            Better programming would be to use BarsInProgress == 0 because this could be easily changed to a different BarsInProgress such as in the edit I made with a tick granularity which uses BarsInProgress == 2.

                            What this means is the new code will process on every tick even if CalculateOnBarClose is set to true. This is because we have added a tick data series and are setting the plot when this tick data series is processing.


                            Please let me know if this does not resolve your inquiry.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks,

                              Please see sixty-six (66) second video please.

                              Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                              Best,

                              TX

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              1 response
                              17 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by benmarkal, Yesterday, 12:52 PM
                              3 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              20 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              244 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Working...
                              X