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

ADX of Previous Bar

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

    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?

    #2
    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.
    AustinNinjaTrader Customer Service

    Comment


      #3
      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-08-2010, 12:23 AM.

      Comment


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



        Your code below likely throws an error to the log tab....
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,221 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        7 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        438 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        9 views
        0 likes
        Last Post FAQtrader  
        Working...
        X