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

DVOL indicator help

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

    DVOL indicator help

    hi to all i'm newbye have spent many time to develop a simple DVol indicator but made a hole in the water anyone can help me to develop better this indicator...??

    it's simple : work on historical data with dataseries and plot difference between up and down volume reference to close candle it's similar to cumulative delta volume

    here code:

    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 DVOL1 : Indicator
        {
            #region Variables
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
      private DataSeries xvol;
            #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.Green, "DVOL1"));
       Add(new Line(Color.Black, 0, "Zero line"));
       xvol     = new DataSeries(this);
    //            CalculateOnBarClose = true;
                Overlay    = false;
                PriceTypeSupported = false;
            }
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
     
       if (Close[0] > Close[1]){ 
        xvol.Set(1);}
     
       else {
                    xvol.Set(0);}
     
     
      } 
     
     
     
            }
            #region Properties
            #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 DVOL1[] cacheDVOL1 = null;
            private static DVOL1 checkDVOL1 = new DVOL1();
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public DVOL1 DVOL1()
            {
                return DVOL1(Input);
            }
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public DVOL1 DVOL1(Data.IDataSeries input)
            {
                if (cacheDVOL1 != null)
                    for (int idx = 0; idx < cacheDVOL1.Length; idx++)
                        if (cacheDVOL1[idx].EqualsInput(input))
                            return cacheDVOL1[idx];
                DVOL1 indicator = new DVOL1();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.SetUp();
                DVOL1[] tmp = new DVOL1[cacheDVOL1 == null ? 1 : cacheDVOL1.Length + 1];
                if (cacheDVOL1 != null)
                    cacheDVOL1.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheDVOL1 = tmp;
                Indicators.Add(indicator);
                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.DVOL1 DVOL1()
            {
                return _indicator.DVOL1(Input);
            }
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.DVOL1 DVOL1(Data.IDataSeries input)
            {
                return _indicator.DVOL1(input);
            }
        }
    }
    // 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.DVOL1 DVOL1()
            {
                return _indicator.DVOL1(Input);
            }
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.DVOL1 DVOL1(Data.IDataSeries input)
            {
                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.DVOL1(input);
            }
        }
    }
    #endregion

    i think something is wrong it's no work and no plot hope i must add a for cycle or other things

    many thanks for someone helps...
    Last edited by rocket7900; 07-01-2010, 01:03 PM.

    #2
    Hello Rocket7900,

    You are most likely running into the issue described here: Make sure you have enough bars in the data series you are accessing

    To resolve, add the following lines to your OnBarUpdate() block.
    if (CurrentBar < 1)
    return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      thanks for replay i have updated my code added 2 dataseries for up volume and down volume that read historic data from now to start of charts but i have now another problem when i try to choice this indicator on a chart ninjatrader go to crash i think there is some of wrong so if someone could try this code and tell me whats is wrong

      thanks in advance

      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>
          /// Volume Up vs Volume Down
          /// </summary>
          [Description("Volume Up vs Volume Down")]
          public class Xvol : Indicator
          {
              #region Variables
              // Wizard generated variables
              // User defined variables (add any user defined variables below)
        private DataSeries     up_vol;
        private DataSeries      dw_vol;
        private double s1_vol;
        private double s2_vol;
              #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(new Pen(Color.Blue, 2), PlotStyle.Line, "up_volplot"));
         Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Line, "dw_volplot"));
         Add(new Line(Color.Black, 0, "Upper"));
       
                  up_vol     = new DataSeries(this);
         dw_vol     = new DataSeries(this);
                  CalculateOnBarClose = true;
                  Overlay    = false;
                  PriceTypeSupported = false;
              }
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
        if (CurrentBar < 2)
      {
      up_vol.Set(0);
      dw_vol.Set(0); 
      up_volplot.Set(0); 
      dw_volplot.Set(0); 
      return;
      }
        for( int i=CurrentBar-1; i>=1; i--)
        {
         if ( Close[i]>Close[i-1])
         {
          up_vol.Set(Volume[i]);
          s1_vol =up_vol[i];
         }
       
         if ( Close[i]<Close[i-1])
         {
          dw_vol.Set(Volume[i]);
          s2_vol =dw_vol[i];
         }
       
      up_volplot.Set(s1_vol);
      dw_volplot.Set(s2_vol);
       
        } 
       
       
              }
              #region Properties
      //        [Browsable(false)]
      //  [XmlIgnore()]
        public DataSeries up_volplot
        {
         get { return up_volplot; }
        }
       
        public DataSeries dw_volplot
        {
         get { return dw_volplot; }
        }
              #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 Xvol[] cacheXvol = null;
              private static Xvol checkXvol = new Xvol();
              /// <summary>
              /// Volume Up vs Volume Down
              /// </summary>
              /// <returns></returns>
              public Xvol Xvol()
              {
                  return Xvol(Input);
              }
              /// <summary>
              /// Volume Up vs Volume Down
              /// </summary>
              /// <returns></returns>
              public Xvol Xvol(Data.IDataSeries input)
              {
                  if (cacheXvol != null)
                      for (int idx = 0; idx < cacheXvol.Length; idx++)
                          if (cacheXvol[idx].EqualsInput(input))
                              return cacheXvol[idx];
                  Xvol indicator = new Xvol();
                  indicator.BarsRequired = BarsRequired;
                  indicator.CalculateOnBarClose = CalculateOnBarClose;
                  indicator.Input = input;
                  indicator.SetUp();
                  Xvol[] tmp = new Xvol[cacheXvol == null ? 1 : cacheXvol.Length + 1];
                  if (cacheXvol != null)
                      cacheXvol.CopyTo(tmp, 0);
                  tmp[tmp.Length - 1] = indicator;
                  cacheXvol = tmp;
                  Indicators.Add(indicator);
                  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>
              /// Volume Up vs Volume Down
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.Xvol Xvol()
              {
                  return _indicator.Xvol(Input);
              }
              /// <summary>
              /// Volume Up vs Volume Down
              /// </summary>
              /// <returns></returns>
              public Indicator.Xvol Xvol(Data.IDataSeries input)
              {
                  return _indicator.Xvol(input);
              }
          }
      }
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
          public partial class Strategy : StrategyBase
          {
              /// <summary>
              /// Volume Up vs Volume Down
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.Xvol Xvol()
              {
                  return _indicator.Xvol(Input);
              }
              /// <summary>
              /// Volume Up vs Volume Down
              /// </summary>
              /// <returns></returns>
              public Indicator.Xvol Xvol(Data.IDataSeries input)
              {
                  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.Xvol(input);
              }
          }
      }
      #endregion

      Comment


        #4
        rocket7900, are there any errors in the logs (right-most tab of Control Center)?
        AustinNinjaTrader Customer Service

        Comment


          #5
          after reboot program in the log there is only some raw for logging to zenfire datafeed
          i think someone try to debug this code....

          Comment


            #6
            Hello Rocket7900,

            There are issues with how your DataSeries are defined and accessed. Plots store values similar to DataSeries, but need to be defined properly in the properties region.

            See this tutorial for how to set up a Non-plottable DataSeries.

            Create an indicator through the wizard to see the proper format for plots needed in the Properties region.

            Let us know how it works once these areas have been addressed.


            Example:
            Code:
             
            [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 Up_volplot
            {
            get { return Values[0]; }
            }
            [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 Dw_volplot
            {
            get { return Values[1]; }
            }
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            57 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            20 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            9 views
            0 likes
            Last Post cre8able  
            Working...
            X