Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calculate difference between close prices

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

    calculate difference between close prices

    Hello,

    I would like to calculate the differce between the current close[0] and the close[2880]
    in timeframe Minute in Market-Analyzer (Pricedifference between two days) or later
    a half or one day...

    1.2.3.7 minutes are running in Marketanalyser but more, than all values 0.

    I have here posted my Code. than I hope anywhere can help.
    --------------------------------------------------------------------------------------------------
    protected override void OnBarUpdate()
    {
    myDataSeries.Set(Math.Abs(Close[0] - Close[8]));
    }

    What I need is this.
    I have tryed a sample >>>> Xvariable = Close[0] - Close[1440]
    value.Set(Xvariable);
    ---------------------------------------------------------------------------------------------------
    to calculate the difference and output in MarketAnalyzer Column.
    But it is not running - Problems with Instance?

    Can someone help me with this code

    for reply many thanks :-)

    #2
    chartvisor, any errors seen in your NT log tab as you run this script?

    How many bars are you loading up for the Market Analzyer to begin with?

    The default of 50 bars would not be enough to calculate those values...
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Bertrand,

      I have found a script in your online manual. I edit this - and it is running with an SMAdifference.
      But I would like to use the different between the Close Prices CurrentClose and Close200barsago
      The Period must be triggert on Close - not on SMA.

      I don´t know how to modify the script to make it work
      Can you help me with the modification.


      calculate difference between close prices
      Hello,

      I would like to calculate the differce between the current close[0] and the close[2880]
      in timeframe Minute in Market-Analyzer (Pricedifference between two days) or later
      a half or one day...

      1.2.3.7 minutes are running in Marketanalyser but more, than all values 0.

      I have here posted my Code. than I hope anywhere can help.
      --------------------------------------------------------------------------------------------------
      protected override void OnBarUpdate()
      {
      myDataSeries.Set(Math.Abs(Close[0] - Close[8]));
      }

      What I need is this.
      I have tryed a sample >>>> Xvariable = Close[0] - Close[1440]
      value.Set(Xvariable);
      ---------------------------------------------------------------------------------------------------
      to calculate the difference and output in MarketAnalyzer Column.
      But it is not running - Problems with Instance?

      Can someone help me with this 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 zvlt : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int sMAPeriod = 200; // Default setting for SMAPeriod
      private DataSeries myDataSeries; // Declare a DataSeries variable
      // 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(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      CalculateOnBarClose = true;
      Overlay = false;

      myDataSeries = new DataSeries(this); // this refers to the indicator/strategy itself
      // and syncs the DataSeries object to historical
      // data bars
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      myDataSeries.Set(Close[0]);

      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.

      Plot0.Set(SMA(SMAPeriod)[0] - myDataSeries[0]); // In Chart
      Value.Set(SMA(SMAPeriod)[0] - myDataSeries[0]); // In Market Analyzer


      //Plot0.Set(Close[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 SMAPeriod
      {
      get { return sMAPeriod; }
      set { sMAPeriod = 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 zvlt[] cachezvlt = null;

      private static zvlt checkzvlt = new zvlt();

      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public zvlt zvlt(int sMAPeriod)
      {
      return zvlt(Input, sMAPeriod);
      }

      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public zvlt zvlt(Data.IDataSeries input, int sMAPeriod)
      {
      if (cachezvlt != null)
      for (int idx = 0; idx < cachezvlt.Length; idx++)
      if (cachezvlt[idx].SMAPeriod == sMAPeriod && cachezvlt[idx].EqualsInput(input))
      return cachezvlt[idx];

      lock (checkzvlt)
      {
      checkzvlt.SMAPeriod = sMAPeriod;
      sMAPeriod = checkzvlt.SMAPeriod;

      if (cachezvlt != null)
      for (int idx = 0; idx < cachezvlt.Length; idx++)
      if (cachezvlt[idx].SMAPeriod == sMAPeriod && cachezvlt[idx].EqualsInput(input))
      return cachezvlt[idx];

      zvlt indicator = new zvlt();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
      indicator.Input = input;
      indicator.SMAPeriod = sMAPeriod;
      Indicators.Add(indicator);
      indicator.SetUp();

      zvlt[] tmp = new zvlt[cachezvlt == null ? 1 : cachezvlt.Length + 1];
      if (cachezvlt != null)
      cachezvlt.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cachezvlt = 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.zvlt zvlt(int sMAPeriod)
      {
      return _indicator.zvlt(Input, sMAPeriod);
      }

      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public Indicator.zvlt zvlt(Data.IDataSeries input, int sMAPeriod)
      {
      return _indicator.zvlt(input, sMAPeriod);
      }
      }
      }

      // 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.zvlt zvlt(int sMAPeriod)
      {
      return _indicator.zvlt(Input, sMAPeriod);
      }

      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public Indicator.zvlt zvlt(Data.IDataSeries input, int sMAPeriod)
      {
      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.zvlt(input, sMAPeriod);
      }
      }
      }
      #endregion






      for reply many thanks :-)

      Comment


        #4
        Hello Bertrand, (hm... the old message post togehter? - Sorry, thats a Error or my Mistake?

        I have found a script in your online manual. I edit this - and it is running with an SMAdifference.
        But I would like to use the different between the Close Prices CurrentClose and Close200barsago
        The Period must be triggert on Close - not on SMA.

        I don´t know how to modify the script to make it work
        Can you help me with the modification.


        #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 zvlt : Indicator
        {
        #region Variables
        // Wizard generated variables
        private int sMAPeriod = 200; // Default setting for SMAPeriod
        private DataSeries myDataSeries; // Declare a DataSeries variable
        // 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(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
        CalculateOnBarClose = true;
        Overlay = false;

        myDataSeries = new DataSeries(this); // this refers to the indicator/strategy itself
        // and syncs the DataSeries object to historical
        // data bars
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {

        myDataSeries.Set(Close[0]);

        // Use this method for calculating your indicator values. Assign a value to each
        // plot below by replacing 'Close[0]' with your own formula.

        Plot0.Set(SMA(SMAPeriod)[0] - myDataSeries[0]); // In Chart
        Value.Set(SMA(SMAPeriod)[0] - myDataSeries[0]); // In Market Analyzer


        //Plot0.Set(Close[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 SMAPeriod
        {
        get { return sMAPeriod; }
        set { sMAPeriod = 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 zvlt[] cachezvlt = null;

        private static zvlt checkzvlt = new zvlt();

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public zvlt zvlt(int sMAPeriod)
        {
        return zvlt(Input, sMAPeriod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public zvlt zvlt(Data.IDataSeries input, int sMAPeriod)
        {
        if (cachezvlt != null)
        for (int idx = 0; idx < cachezvlt.Length; idx++)
        if (cachezvlt[idx].SMAPeriod == sMAPeriod && cachezvlt[idx].EqualsInput(input))
        return cachezvlt[idx];

        lock (checkzvlt)
        {
        checkzvlt.SMAPeriod = sMAPeriod;
        sMAPeriod = checkzvlt.SMAPeriod;

        if (cachezvlt != null)
        for (int idx = 0; idx < cachezvlt.Length; idx++)
        if (cachezvlt[idx].SMAPeriod == sMAPeriod && cachezvlt[idx].EqualsInput(input))
        return cachezvlt[idx];

        zvlt indicator = new zvlt();
        indicator.BarsRequired = BarsRequired;
        indicator.CalculateOnBarClose = CalculateOnBarClose;
        #if NT7
        indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
        indicator.MaximumBarsLookBack = MaximumBarsLookBack;
        #endif
        indicator.Input = input;
        indicator.SMAPeriod = sMAPeriod;
        Indicators.Add(indicator);
        indicator.SetUp();

        zvlt[] tmp = new zvlt[cachezvlt == null ? 1 : cachezvlt.Length + 1];
        if (cachezvlt != null)
        cachezvlt.CopyTo(tmp, 0);
        tmp[tmp.Length - 1] = indicator;
        cachezvlt = 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.zvlt zvlt(int sMAPeriod)
        {
        return _indicator.zvlt(Input, sMAPeriod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.zvlt zvlt(Data.IDataSeries input, int sMAPeriod)
        {
        return _indicator.zvlt(input, sMAPeriod);
        }
        }
        }

        // 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.zvlt zvlt(int sMAPeriod)
        {
        return _indicator.zvlt(Input, sMAPeriod);
        }

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public Indicator.zvlt zvlt(Data.IDataSeries input, int sMAPeriod)
        {
        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.zvlt(input, sMAPeriod);
        }
        }
        }
        #endregion






        for reply many thanks :-)

        Comment


          #5
          Hello chartvisor,

          If you would like the difference of the close 200 bars ago and the current bar use:

          Value.Set(Close[200] - Close[0]);

          You will also want to make sure there are 200 bars on the chart before the indicator starts.
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello ChelseaB,

            thank you very much for your reply.
            I will try it.

            Have a nice Weekend :-)

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by warreng86, 11-10-2020, 02:04 PM
            5 responses
            1,356 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Perr0Grande, Today, 08:16 PM
            0 responses
            3 views
            0 likes
            Last Post Perr0Grande  
            Started by elderan, Today, 08:03 PM
            0 responses
            5 views
            0 likes
            Last Post elderan
            by elderan
             
            Started by algospoke, Today, 06:40 PM
            0 responses
            10 views
            0 likes
            Last Post algospoke  
            Started by maybeimnotrader, Today, 05:46 PM
            0 responses
            12 views
            0 likes
            Last Post maybeimnotrader  
            Working...
            X