• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volume Coding Indicator

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

  • ginx10k
    replied
    Thanks a lot buddy. We'll Do.

    Leave a comment:


  • koganam
    replied
    Originally posted by ginx10k View Post
    Okay, this doesn't make sense, sometimes it works, other times I keep getting this error.

    http://screencast.com/t/cHcUpG9nqj

    Here's the FULL 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 CustomVolume : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int myInput0 = 1; // Default setting for MyInput0
                private string InstrumentName = " ";
                private string contract = " ";
                
            // User defined variables (add any user defined variables below)
                private bool useFutures = true; //Ask User if they want to use Futures Volume for FOREX
            #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 ()
            {
                //Adding Volume per instruments
                InstrumentName = (Instrument.FullName.ToString());
                if(InstrumentName == "$USDJPY") {contract = "6J 06-14";}
                
                
                Add (new Plot (new Pen (Color.Red, 3), PlotStyle.Line, "VolumePlot"));
                Add ( "6J 06-14", PeriodType.Minute, 5);
                
                Overlay = false;
            }
    
            protected override void OnBarUpdate ()
            {
                if (CurrentBar < BarsRequired)
                    return;
                
                if (Volumes [0] [0] > Volumes [1][0])
                    VolumePlot.Set(Volumes [1][0]);
                Print ("The current bar's volume price is greater");
            }
    
            #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 VolumePlot 
            {
                get { return Values [0]; }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            
            [Description("Use Futures Volume For FOREX")]
            [GridCategory("Parameters")]
            public bool UseFuturesVolume
            {
                get { return useFutures; }
                set { useFutures = 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 CustomVolume[] cacheCustomVolume = null;
    
            private static CustomVolume checkCustomVolume = new CustomVolume();
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public CustomVolume CustomVolume(int myInput0, bool useFuturesVolume)
            {
                return CustomVolume(Input, myInput0, useFuturesVolume);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public CustomVolume CustomVolume(Data.IDataSeries input, int myInput0, bool useFuturesVolume)
            {
                if (cacheCustomVolume != null)
                    for (int idx = 0; idx < cacheCustomVolume.Length; idx++)
                        if (cacheCustomVolume[idx].MyInput0 == myInput0 && cacheCustomVolume[idx].UseFuturesVolume == useFuturesVolume && cacheCustomVolume[idx].EqualsInput(input))
                            return cacheCustomVolume[idx];
    
                lock (checkCustomVolume)
                {
                    checkCustomVolume.MyInput0 = myInput0;
                    myInput0 = checkCustomVolume.MyInput0;
                    checkCustomVolume.UseFuturesVolume = useFuturesVolume;
                    useFuturesVolume = checkCustomVolume.UseFuturesVolume;
    
                    if (cacheCustomVolume != null)
                        for (int idx = 0; idx < cacheCustomVolume.Length; idx++)
                            if (cacheCustomVolume[idx].MyInput0 == myInput0 && cacheCustomVolume[idx].UseFuturesVolume == useFuturesVolume && cacheCustomVolume[idx].EqualsInput(input))
                                return cacheCustomVolume[idx];
    
                    CustomVolume indicator = new CustomVolume();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    indicator.MyInput0 = myInput0;
                    indicator.UseFuturesVolume = useFuturesVolume;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    CustomVolume[] tmp = new CustomVolume[cacheCustomVolume == null ? 1 : cacheCustomVolume.Length + 1];
                    if (cacheCustomVolume != null)
                        cacheCustomVolume.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheCustomVolume = 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.CustomVolume CustomVolume(int myInput0, bool useFuturesVolume)
            {
                return _indicator.CustomVolume(Input, myInput0, useFuturesVolume);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.CustomVolume CustomVolume(Data.IDataSeries input, int myInput0, bool useFuturesVolume)
            {
                return _indicator.CustomVolume(input, myInput0, useFuturesVolume);
            }
        }
    }
    
    // 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.CustomVolume CustomVolume(int myInput0, bool useFuturesVolume)
            {
                return _indicator.CustomVolume(Input, myInput0, useFuturesVolume);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.CustomVolume CustomVolume(Data.IDataSeries input, int myInput0, bool useFuturesVolume)
            {
                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.CustomVolume(input, myInput0, useFuturesVolume);
            }
        }
    }
    #endregion
    As you can see I'm trying to to get the indicator to know which Chart it's on so it knows which FUTURES contract to use. I typed Conditional statements in the void Initialize() area, I don't know if that causes problems.

    Can someone please help fix this error.
    Contract "6J 06-14" comes into existence on a specific date. Before that date, as the contact does not exist, your second price DataSeries will not be created, so any reference to it will be out of the bounds of any array that references it.

    You will have to make some kind of arrangement to make sure that you are referencing existing contracts. One way might be to reverse your logic, and run on the 6J contract, calling $USDJPY, as the latter is an invariant string. Other ways would be more complex, as you would have to determine the date, so that you can use the correct contract.

    Leave a comment:


  • ginx10k
    replied
    Reoccurring error

    Okay, this doesn't make sense, sometimes it works, other times I keep getting this error.

    http://screencast.com/t/cHcUpG9nqj

    Here's the FULL 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 CustomVolume : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int myInput0 = 1; // Default setting for MyInput0
    			private string InstrumentName = " ";
    			private string contract = " ";
    			
            // User defined variables (add any user defined variables below)
    			private bool useFutures = true; //Ask User if they want to use Futures Volume for FOREX
            #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 ()
    		{
    			//Adding Volume per instruments
    			InstrumentName = (Instrument.FullName.ToString());
    			if(InstrumentName == "$USDJPY") {contract = "6J 06-14";}
    			
    			
    			Add (new Plot (new Pen (Color.Red, 3), PlotStyle.Line, "VolumePlot"));
    			Add ( "6J 06-14", PeriodType.Minute, 5);
    			
    			Overlay = false;
    		}
    
    		protected override void OnBarUpdate ()
    		{
    			if (CurrentBar < BarsRequired)
    				return;
    			
    			if (Volumes [0] [0] > Volumes [1][0])
    				VolumePlot.Set(Volumes [1][0]);
    			Print ("The current bar's volume price is greater");
    		}
    
            #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 VolumePlot 
    		{
    			get { return Values [0]; }
    		}
    
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
    		
    		[Description("Use Futures Volume For FOREX")]
    		[GridCategory("Parameters")]
    		public bool UseFuturesVolume
            {
                get { return useFutures; }
                set { useFutures = 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 CustomVolume[] cacheCustomVolume = null;
    
            private static CustomVolume checkCustomVolume = new CustomVolume();
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public CustomVolume CustomVolume(int myInput0, bool useFuturesVolume)
            {
                return CustomVolume(Input, myInput0, useFuturesVolume);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public CustomVolume CustomVolume(Data.IDataSeries input, int myInput0, bool useFuturesVolume)
            {
                if (cacheCustomVolume != null)
                    for (int idx = 0; idx < cacheCustomVolume.Length; idx++)
                        if (cacheCustomVolume[idx].MyInput0 == myInput0 && cacheCustomVolume[idx].UseFuturesVolume == useFuturesVolume && cacheCustomVolume[idx].EqualsInput(input))
                            return cacheCustomVolume[idx];
    
                lock (checkCustomVolume)
                {
                    checkCustomVolume.MyInput0 = myInput0;
                    myInput0 = checkCustomVolume.MyInput0;
                    checkCustomVolume.UseFuturesVolume = useFuturesVolume;
                    useFuturesVolume = checkCustomVolume.UseFuturesVolume;
    
                    if (cacheCustomVolume != null)
                        for (int idx = 0; idx < cacheCustomVolume.Length; idx++)
                            if (cacheCustomVolume[idx].MyInput0 == myInput0 && cacheCustomVolume[idx].UseFuturesVolume == useFuturesVolume && cacheCustomVolume[idx].EqualsInput(input))
                                return cacheCustomVolume[idx];
    
                    CustomVolume indicator = new CustomVolume();
                    indicator.BarsRequired = BarsRequired;
                    indicator.CalculateOnBarClose = CalculateOnBarClose;
    #if NT7
                    indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                    indicator.MaximumBarsLookBack = MaximumBarsLookBack;
    #endif
                    indicator.Input = input;
                    indicator.MyInput0 = myInput0;
                    indicator.UseFuturesVolume = useFuturesVolume;
                    Indicators.Add(indicator);
                    indicator.SetUp();
    
                    CustomVolume[] tmp = new CustomVolume[cacheCustomVolume == null ? 1 : cacheCustomVolume.Length + 1];
                    if (cacheCustomVolume != null)
                        cacheCustomVolume.CopyTo(tmp, 0);
                    tmp[tmp.Length - 1] = indicator;
                    cacheCustomVolume = 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.CustomVolume CustomVolume(int myInput0, bool useFuturesVolume)
            {
                return _indicator.CustomVolume(Input, myInput0, useFuturesVolume);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.CustomVolume CustomVolume(Data.IDataSeries input, int myInput0, bool useFuturesVolume)
            {
                return _indicator.CustomVolume(input, myInput0, useFuturesVolume);
            }
        }
    }
    
    // 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.CustomVolume CustomVolume(int myInput0, bool useFuturesVolume)
            {
                return _indicator.CustomVolume(Input, myInput0, useFuturesVolume);
            }
    
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            /// <returns></returns>
            public Indicator.CustomVolume CustomVolume(Data.IDataSeries input, int myInput0, bool useFuturesVolume)
            {
                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.CustomVolume(input, myInput0, useFuturesVolume);
            }
        }
    }
    #endregion
    As you can see I'm trying to to get the indicator to know which Chart it's on so it knows which FUTURES contract to use. I typed Conditional statements in the void Initialize() area, I don't know if that causes problems.

    Can someone please help fix this error.

    Leave a comment:


  • ginx10k
    replied
    Nevermind Got iT!

    Nevermind that last post. I got it.

    Code:
     myVariable = (Instrument.FullName.ToString());
    Cheers!!

    Leave a comment:


  • ginx10k
    replied
    Adding Instrument Type

    Ok another question. How do I get the indicator to determine what Instrument it's on, so that I can use that Value and place it in a Variable or Conditional Statement.

    For instance.

    if InstrumentType. == USD/JPY {DO something}

    something like that?

    what's the actual code to do this??
    Last edited by ginx10k; 05-19-2014, 04:07 PM.

    Leave a comment:


  • ginx10k
    replied
    It works

    It works. it was just a dataseries issue. I had 3 days set to load.. thanks!! Works fine now.
    Last edited by ginx10k; 05-19-2014, 03:56 PM.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello ginx10k,

    Try commenting out the following line
    Code:
    if (Volumes [0] [0] < Volumes [1] [0])
    It looks like the Volume on index 0 is not less than the volume on index 1 so nothing is being displayed. the print statement in your image would still work though as that is not part of this if statement.

    I commented that line out and everything popped back up when using the code in your image.

    Please let me know if I may be of additional assistance.

    Leave a comment:


  • ginx10k
    replied
    Small ERROR

    Hey Jesse, yea the BarsRequired solved the Plotting issue. Indicators works great on One Dataseries.

    But When I tried to add 6J to the chart, without changing anything else, the Indicator Won't Load. I'm thinking it's cause adding the new Dataseries changes the Index[] value. So what change do I have to do on the Code so that the Indicator can display when more than One dataseries are present.

    http://screencast.com/t/pCPlRHyhpWHl


    i.e. I tried Volumes[2][0] but that didn't work. and I have NO way of finding the Actual Index value of anything?

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello ginx10k,

    Please excuse my prior post and thank you koganam for clearing that up. Here is a sample of a working Volume indicator based of the index of the added series.

    The reason you are getting the error is it is checking before there are bars to check. I added the code below to resolve this.
    Code:
    if(CurrentBar < BarsRequired)
    				return;
    Here is the complete code.
    Code:
    		protected override void Initialize ()
    		{
    			Add (new Plot (new Pen (Color.Red, 3), PlotStyle.Line, "VolumePlot"));
    			Add ("6J 06-14", PeriodType.Minute, 5);
    			Overlay = false;
    		}
    
    		protected override void OnBarUpdate ()
    		{
    			if (CurrentBar < BarsRequired)
    				return;
    			if (Volumes [0] [0] > Volumes [1] [0])
    				VolumePlot.Set (Volumes [1] [0]);
    			Print ("The current bar's volume price is greater");
    		}
    
    		#region Properties
    
    		[Browsable (false)]	
    		[XmlIgnore ()]		
    		public DataSeries VolumePlot {
    			get { return Values [0]; }
    		}
    
    		#endregion
    	}
    }
    Please let me know if I may be of additional assistance.
    Last edited by NinjaTrader_Jesse; 05-19-2014, 03:23 PM.

    Leave a comment:


  • ginx10k
    replied
    Ok I think the error was that I didn't Use the " " marks. So I changed the code
    Code:
            protected override void Initialize()
            {
                Add("6J 6-14", PeriodType.Minute, 5);
               
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                //Compare Volume of current bar to 5 minute
             if (Volumes[0][0] < Volumes[1][0])
             Print("The current bar's volume price is Smaller");
            };
    and it compiled successfully. However, I'm still not showing any Volume values on the Panel. And it's NOT displaying anything to the OUTput window. What am I missing.

    P.S. I'm testing on Market replay with all Data available, so Data isn't the problem. just trying to figure out what I'm missing NOW. why won't it compare the Volumes or show anything. Thank you!!
    Last edited by ginx10k; 05-19-2014, 03:14 PM.

    Leave a comment:


  • ginx10k
    replied
    Not working!!

    Ok so I can't Add the VOL() to the indicator. But when I ADD to indicator this is what I get. http://screencast.com/t/S6ePz4MZZ



    Code:
       /// <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(6J 06-14, PeriodType.Minute, 5);
                Overlay = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                //Compare Volume of current bar to 5 minute
             if (Volumes[0][0] > Volumes[1][0])
             Print("The current bar's volume price is greater");
            }
    Last edited by ginx10k; 05-19-2014, 03:17 PM.

    Leave a comment:


  • koganam
    replied
    Originally posted by ginx10k View Post
    Now we're talking. so for instrument, I can add 6J?? or is there other syntax. 2nd. This example is for Strategies. I know the Add() doesn't work on Indicator code.

    How would I go about adding this to an indicator? Basically what would the Code look like.
    Or do I need to use the VOL() call function.

    Still trying to figure all this coding stuff out. reading the Help guides does help, but sometimes its more confusing.
    Not quite correct. You can Add() price data series to both indicators or strategies: you cannot Add() indicators to other indicators; only to strategies.

    For futures, you must add the full contract designation: not just "6J", but "6J 05-14".

    Then you refer to its volume with Volumes[1][0].

    Leave a comment:


  • ginx10k
    replied
    Now we're talking. so for instrument, I can add 6J?? or is there other syntax. 2nd. This example is for Strategies. I know the Add() doesn't work on Indicator code.

    How would I go about adding this to an indicator? Basically what would the Code look like.
    Or do I need to use the VOL() call function. If I do need the VOL(), how would I add the Dataseries for other instruments??

    Still trying to figure all this coding stuff out. reading the Help guides does help, but sometimes its more confusing.


    I tried
    Code:
     protected override void Initialize()
            {
    Add(6J, PeriodType.Minute, 5);
    }
    Getting errors.
    Last edited by ginx10k; 05-19-2014, 02:53 PM.

    Leave a comment:


  • koganam
    replied
    Originally posted by ginx10k View Post
    I think you misunderstood my question so I'll repost. First I wanna say thanks for taking the time to answer me and for the video. But I already know how to add Other Data series and indicators to charts.

    The Question is For "INDICATOR DEVELOPMENT ONLY"


    HOW Do I add the Volume from another Dataseries to my current Indicator Code?

    i.e. IF (VOLUME from 6J )....I don't know the syntax or the coding method. it's just an example.
    The NT Help is a great resource, but only if we use it. The example in the guide answers the question that you asked.

    Add the instrument to the indicator and query the Volumes array.

    ref: http://www.ninjatrader.com/support/h...t7/volumes.htm

    Leave a comment:


  • ginx10k
    replied
    Not for Charting for Indicator Development!

    I think you misunderstood my question so I'll repost. First I wanna say thanks for taking the time to answer me and for the video. But I already know how to add Other Data series and indicators to charts.

    The Question is For "INDICATOR DEVELOPMENT ONLY"


    HOW Do I add the Volume from another Dataseries to my current Indicator Code?

    i.e. IF (VOLUME from 6J )....I don't know the syntax or the coding method. it's just an example.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by jjanguda, 05-19-2015, 01:13 PM
15 responses
1,372 views
0 likes
Last Post Eric M.
by Eric M.
 
Started by morrnel, Today, 01:13 PM
1 response
10 views
0 likes
Last Post NinjaTrader_Jim  
Started by babouin77, Today, 12:41 PM
8 responses
18 views
0 likes
Last Post babouin77  
Started by punkiy2111, Today, 12:17 PM
1 response
9 views
0 likes
Last Post NinjaTrader_Tabor  
Started by GLFX005, Today, 11:22 AM
8 responses
38 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X