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

current volume

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

    current volume

    Hi I want to place volume of current candle above current candle see attached pic
    http://imgur.com/tLRR2dc

    here are the code that I want to insert in my indicator

    HTML Code:
    DrawOnPricePanel = true; // Initialize section
    DrawText("CurrentVolume", true, Convert.ToString(Volume[0]), 0, High[0], 20, Color.Red, 
         ChartControl.Font, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);
    and the Indicator i want to use is

    HTML 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>
        /// Draws Horizontal Line or Ray at current price
        /// </summary>
        [Description("Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53")]
        public class PriceLineWH2 : Indicator
        {
            #region Variables
            // Wizard generated variables
            	private Color	  lineColor = Color.Cyan;
    			private int		  lineWidth = 2;
    			private DashStyle lineStyle = DashStyle.Dot; 
    			private bool useLine		= true; 
    			private int rayLength		= 5;
            #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()
            {
                CalculateOnBarClose	= false;
                Overlay				= true;
    			AutoScale			= false;
    			DrawOnPricePanel	= false;
    			 
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if (rayLength > 20)
    				rayLength = 20;
    			
    			if (useLine)
    				DrawHorizontalLine("Currprice", false, Input[0], lineColor, lineStyle, lineWidth);
    			else
    				if (CurrentBar > 50)
    					DrawRay("CurrRay", false, rayLength, Input[0], 0, Input[0], lineColor, lineStyle, lineWidth);
    				
    	    }
    
            #region Properties
    		
    		[Description("Use Line or Ray....True = Long Horizontal Line   ...  False = Short 'ray' with variable length")]
            [Category("Plots")]
    		[Gui.Design.DisplayName ("1. Use Line or Ray")]
            public bool UseLine
            {
                get { return useLine; }
                set { useLine = value; }
            }
    
    		
    		[Description("LineStyle for Price Line")]
            [Category("Plots")]
    		[Gui.Design.DisplayName ("2. Price Line Style")]
            public DashStyle LineStyle
            {
                get { return lineStyle; }
                set { lineStyle = value; }
            }
    		 
    	    [XmlIgnore()]
            [Description("Color of the Price Line")]
            [Category("Plots")]
    		[Gui.Design.DisplayName ("3. Price Line Color")]
            public Color LineColor
            {
                get { return lineColor; }
                set { lineColor = value; }
            }
    			[Browsable(false)]
    			public string LineColorSerialize
    			{
    				get { return NinjaTrader.Gui.Design.SerializableColor.ToString(lineColor); }//SerializableColor
    				set { lineColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
    			}	
    
    			
        	[Description("Width of the Price Line")]
        	[Category("Plots")]
    		[Gui.Design.DisplayName ("4. Price Line Width")]
            public int LineWidth
            {
                get { return lineWidth; }
    			set { lineWidth = Math.Max(1, value); }
            }
    		
         	[Description("Line length....(for Ray only)....# of bars from right edge  NOTE:  Only works if Use Line = false")]
        	[Category("Plots")]
    		[Gui.Design.DisplayName ("5. Line Length for Ray")]
            public int RayLength
            {
                get { return rayLength; }
    			set { rayLength = 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 PriceLineWH2[] cachePriceLineWH2 = null;
    
            private static PriceLineWH2 checkPriceLineWH2 = new PriceLineWH2();
    
            /// <summary>
            /// Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53
            /// </summary>
            /// <returns></returns>
            public PriceLineWH2 PriceLineWH2()
            {
                return PriceLineWH2(Input);
            }
    
            /// <summary>
            /// Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53
            /// </summary>
            /// <returns></returns>
            public PriceLineWH2 PriceLineWH2(Data.IDataSeries input)
            {
                if (cachePriceLineWH2 != null)
                    for (int idx = 0; idx < cachePriceLineWH2.Length; idx++)
                        if (cachePriceLineWH2[idx].EqualsInput(input))
                            return cachePriceLineWH2[idx];
    
                lock (checkPriceLineWH2)
                {
                    if (cachePriceLineWH2 != null)
                        for (int idx = 0; idx < cachePriceLineWH2.Length; idx++)
                            if (cachePriceLineWH2[idx].EqualsInput(input))
                                return cachePriceLineWH2[idx];
    
                    PriceLineWH2 indicator = new PriceLineWH2();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    PriceLineWH2[] tmp = new PriceLineWH2[cachePriceLineWH2 == null ? 1 : cachePriceLineWH2.Length + 1];
                    if (cachePriceLineWH2 != null)
                        cachePriceLineWH2.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cachePriceLineWH2 = 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>
            /// Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.PriceLineWH2 PriceLineWH2()
            {
                return _indicator.PriceLineWH2(Input);
            }
    
            /// <summary>
            /// Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53
            /// </summary>
            /// <returns></returns>
            public Indicator.PriceLineWH2 PriceLineWH2(Data.IDataSeries input)
            {
                return _indicator.PriceLineWH2(input);
            }
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        public partial class Strategy : StrategyBase
        {
            /// <summary>
            /// Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.PriceLineWH2 PriceLineWH2()
            {
                return _indicator.PriceLineWH2(Input);
            }
    
            /// <summary>
            /// Horizontal Line at Current Price....(Ver 2.0  09/09/2010) revised by Photog53
            /// </summary>
            /// <returns></returns>
            public Indicator.PriceLineWH2 PriceLineWH2(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.PriceLineWH2(input);
            }
        }
    }
    #endregion
    please help me compile the indicator with this code
    regards

    #2
    Hello SLASH,

    Thank you for your note.

    Attached is the script with your code added, compiled, and exported.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks
      How can I add 5 bar moving average volume below this volume

      Comment


        #4
        Hello SLASH,

        You can try and average this using code, but it may be easier to use the SMA.

        For example add the line below the already existing DrawText call in the script and then recompile:

        DrawText("CurrentVolumeAvg", true, SMA(Volume[0], 5)[0].ToString(), 0, High[0]+3*TickSize, 20, Color.Red, ChartControl.Font, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);

        This will add the new text box above the other text box (so it is not covering the data).
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello SLASH,

          You can try and average this using code, but it may be easier to use the SMA.

          For example add the line below the already existing DrawText call in the script and then recompile:

          DrawText("CurrentVolumeAvg", true, SMA(Volume, 5)[0].ToString(), 0, High[0]+3*TickSize, 20, Color.Red, ChartControl.Font, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);

          This will add the new text box above the other text box (so it is not covering the data).
          giving following error on comiple
          Argument"1" cannot convert from "double" to ninjatrader dataI Data Series
          and
          The best overload method match for"Ninja Trader Indicator SMA(Ninja Trader,DataSeries.int) has some invalid argument

          HTML 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>
              /// Draws Horizontal Line or Ray at current price
              /// </summary>
              [Description("Draws Horizontal Line or Ray at current price")]
              public class PriceLineWH2 : Indicator
              {
                  #region Variables
                  // Wizard generated variables
                  // User defined variables (add any user defined variables below)
          		private Color	  lineColor = Color.Cyan;
          		private int		  lineWidth = 2;
          		private DashStyle lineStyle = DashStyle.Dot; 
          		private bool useLine		= true; 
          		private int rayLength		= 5;
                  #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()
                  {
                      CalculateOnBarClose	= false;
                      Overlay				= true;
          			AutoScale			= false;
          			DrawOnPricePanel	= true;
                  }
          
                  /// <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.
          			DrawText("CurrentVolume", true, Convert.ToString(Volume[0]), 0, High[0], 20, Color.Red,
          					ChartControl.Font, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);
          			DrawText("CurrentVolumeAvg", true, SMA(Volume[0], 5)[0].ToString(), 0, High[0]+3*TickSize, 20, Color.Red, ChartControl.Font, StringAlignment.Near, Color.Transparent, Color.Transparent, 0);
          
          			
          			if (rayLength > 20)
          				rayLength = 20;
          			
          			if (useLine)
          				DrawHorizontalLine("Currprice", false, Input[0], lineColor, lineStyle, lineWidth);
          			
          			else if (CurrentBar > 50)
          					DrawRay("CurrRay", false, rayLength, Input[0], 0, Input[0], lineColor, lineStyle, lineWidth);
                  }
          
                  #region Properties
          		[Description("Use Line or Ray....True = Long Horizontal Line   ...  False = Short 'ray' with variable length")]
                  [Category("Plots")]
          		[Gui.Design.DisplayName ("1. Use Line or Ray")]
                  public bool UseLine
                  {
                      get { return useLine; }
                      set { useLine = value; }
                  }
          		
          		[Description("LineStyle for Price Line")]
                  [Category("Plots")]
          		[Gui.Design.DisplayName ("2. Price Line Style")]
                  public DashStyle LineStyle
                  {
                      get { return lineStyle; }
                      set { lineStyle = value; }
                  }
          		 
          	    [XmlIgnore()]
                  [Description("Color of the Price Line")]
                  [Category("Plots")]
          		[Gui.Design.DisplayName ("3. Price Line Color")]
                  public Color LineColor
                  {
                      get { return lineColor; }
                      set { lineColor = value; }
                  }
          		
          		[Browsable(false)]
          		public string LineColorSerialize
          		{
          			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(lineColor); }//SerializableColor
          			set { lineColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
          		}	
          			
              	[Description("Width of the Price Line")]
              	[Category("Plots")]
          		[Gui.Design.DisplayName ("4. Price Line Width")]
                  public int LineWidth
                  {
                      get { return lineWidth; }
          			set { lineWidth = Math.Max(1, value); }
                  }
          		
               	[Description("Line length....(for Ray only)....# of bars from right edge  NOTE:  Only works if Use Line = false")]
              	[Category("Plots")]
          		[Gui.Design.DisplayName ("5. Line Length for Ray")]
                  public int RayLength
                  {
                      get { return rayLength; }
          			set { rayLength = 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 PriceLineWH2[] cachePriceLineWH2 = null;
          
                  private static PriceLineWH2 checkPriceLineWH2 = new PriceLineWH2();
          
                  /// <summary>
                  /// Draws Horizontal Line or Ray at current price
                  /// </summary>
                  /// <returns></returns>
                  public PriceLineWH2 PriceLineWH2()
                  {
                      return PriceLineWH2(Input);
                  }
          
                  /// <summary>
                  /// Draws Horizontal Line or Ray at current price
                  /// </summary>
                  /// <returns></returns>
                  public PriceLineWH2 PriceLineWH2(Data.IDataSeries input)
                  {
                      if (cachePriceLineWH2 != null)
                          for (int idx = 0; idx < cachePriceLineWH2.Length; idx++)
                              if (cachePriceLineWH2[idx].EqualsInput(input))
                                  return cachePriceLineWH2[idx];
          
                      lock (checkPriceLineWH2)
                      {
                          if (cachePriceLineWH2 != null)
                              for (int idx = 0; idx < cachePriceLineWH2.Length; idx++)
                                  if (cachePriceLineWH2[idx].EqualsInput(input))
                                      return cachePriceLineWH2[idx];
          
                          PriceLineWH2 indicator = new PriceLineWH2();
                          indicator.BarsRequired = BarsRequired;
                          indicator.CalculateOnBarClose = CalculateOnBarClose;
          #if NT7
                          indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                          indicator.MaximumBarsLookBack = MaximumBarsLookBack;
          #endif
                          indicator.Input = input;
                          Indicators.Add(indicator);
                          indicator.SetUp();
          
                          PriceLineWH2[] tmp = new PriceLineWH2[cachePriceLineWH2 == null ? 1 : cachePriceLineWH2.Length + 1];
                          if (cachePriceLineWH2 != null)
                              cachePriceLineWH2.CopyTo(tmp, 0);
                          tmp[tmp.Length - 1] = indicator;
                          cachePriceLineWH2 = 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>
                  /// Draws Horizontal Line or Ray at current price
                  /// </summary>
                  /// <returns></returns>
                  [Gui.Design.WizardCondition("Indicator")]
                  public Indicator.PriceLineWH2 PriceLineWH2()
                  {
                      return _indicator.PriceLineWH2(Input);
                  }
          
                  /// <summary>
                  /// Draws Horizontal Line or Ray at current price
                  /// </summary>
                  /// <returns></returns>
                  public Indicator.PriceLineWH2 PriceLineWH2(Data.IDataSeries input)
                  {
                      return _indicator.PriceLineWH2(input);
                  }
              }
          }
          
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
              public partial class Strategy : StrategyBase
              {
                  /// <summary>
                  /// Draws Horizontal Line or Ray at current price
                  /// </summary>
                  /// <returns></returns>
                  [Gui.Design.WizardCondition("Indicator")]
                  public Indicator.PriceLineWH2 PriceLineWH2()
                  {
                      return _indicator.PriceLineWH2(Input);
                  }
          
                  /// <summary>
                  /// Draws Horizontal Line or Ray at current price
                  /// </summary>
                  /// <returns></returns>
                  public Indicator.PriceLineWH2 PriceLineWH2(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.PriceLineWH2(input);
                  }
              }
          }
          #endregion
          Last edited by NinjaTrader_Bertrand; 09-23-2014, 02:54 AM.

          Comment


            #6
            SMA(Volume, 5)[0] not SMA(Volume[0], 5)[0]

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X