NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-06-2010, 04:51 AM   #1
NinjaCustomer
Senior Member
 
Join Date: Jan 2008
Posts: 130
Thanks: 0
Thanked 0 times in 0 posts
Default ADX of Previous Bar

Hi,

if i do ADX(Input, 14) then I will get the ADX of the current bar.

How do I get the ADX of the previous bar?
NinjaCustomer is offline  
Reply With Quote
Old 02-06-2010, 10:28 AM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

NinjaCustomer, this code will get you the ADX of the current bar:
Code:
double current_ADX = ADX(Input, 14)[0];
and this code will get you the ADX of the previous bar:
Code:
double prev_ADX = ADX(Input, 14)[1];
As you can see, it is simply a matter of changing the number in the square brackets to go even further back if you wish.
NinjaTrader_Austin is offline  
Reply With Quote
Old 02-07-2010, 11:21 PM   #3
NinjaCustomer
Senior Member
 
Join Date: Jan 2008
Posts: 130
Thanks: 0
Thanked 0 times in 0 posts
Default Doesn't work

Here is the whole of my indicator (that I made to illustrate the problem):

The code that displays the fixed text "right" does not get executed

I'm using 6.5

Code:
// 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 TestIndicator : Indicator
    {
        #region Variables
        // Wizard generated variables
        // 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()
        {
            CalculateOnBarClose	= false;
            Overlay				= true;
            PriceTypeSupported	= true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			DrawTextFixed("abc", "left", TextPosition.TopLeft);	
			
			double curWMA = WMA(Input, 100)[0];
			double prevWMA = WMA(Input, 100)[1];
		
			DrawTextFixed("def", "right", TextPosition.TopRight);	
        }

        #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 TestIndicator[] cacheTestIndicator = null;

        private static TestIndicator checkTestIndicator = new TestIndicator();

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

        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        /// <returns></returns>
        public TestIndicator TestIndicator(Data.IDataSeries input)
        {

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

            TestIndicator indicator = new TestIndicator();
            indicator.BarsRequired = BarsRequired;
            indicator.CalculateOnBarClose = CalculateOnBarClose;
            indicator.Input = input;
            indicator.SetUp();

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

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

    }
}
Last edited by NinjaCustomer; 02-07-2010 at 11:23 PM.
NinjaCustomer is offline  
Reply With Quote
Old 02-08-2010, 06:24 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

You would need to make sure to not access any undefined bars at the OnBarUpdate() start -

http://www.ninjatrader-support2.com/...ead.php?t=3170

Your code below likely throws an error to the log tab....
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
if Target Profit reached on previous bar, dont trade current bar paschall Strategy Development 4 09-02-2009 10:34 PM
Current Bar Open Equals Previous Bar Close ramacan Charting 6 05-23-2009 11:07 AM
High and Low of previous bar and actual bar Fernando Miscellaneous Support 1 03-18-2009 10:54 AM
Highest Bar of e.g. ADX Tobias1985 Strategy Development 4 02-26-2009 02:04 PM
CrossBelow previous bar and omit current bar ct General Programming 1 06-03-2007 02:54 AM


All times are GMT -6. The time now is 02:36 PM.