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

How to get entry from indicator?

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

    How to get entry from indicator?

    I want to get cross information form MACD indicator. eg, when slow line up fast line get current bar number from indicator. If slow line up fast line return current bar information(current bar is 55,return 55). I can use this information in my strategy.
    I try to use data series, but I got error "index was outside the bounds of the array."

    I mean I get output like 0,0,0,0,...55,0,0....,89,0,0,0,0,105,0
    If slow line = fast line return current bar number, other wise return 0.

    Sample code,many thanks!
    Last edited by thomson; 09-08-2013, 01:14 PM.

    #2
    Hello thomson,

    Thank you for your post.

    Can you provide the crosses you are using? I can then provide the pull of the current bar.

    Comment


      #3
      Please see my attached code below,

      //
      // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
      // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
      //

      #region Using declarations
      using System;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.ComponentModel;
      using System.Xml.Serialization;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      #endregion

      // This namespace holds all indicators and is required. Do not change it.
      namespace NinjaTrader.Indicator
      {
      /// <summary>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      [Description("The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
      public class MACD : Indicator
      {
      #region Variables
      private int fast = 12;
      private int slow = 26;
      private int smooth = 9;
      private DataSeries fastEma;
      private DataSeries slowEma;
      #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, "Macd"));
      Add(new Plot(Color.DarkViolet, "Avg"));
      Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff"));

      Add(new Line(Color.DarkGray, 0, "Zero line"));

      fastEma = new DataSeries(this);
      slowEma = new DataSeries(this);
      }

      /// <summary>
      /// Calculates the indicator value(s) at the current index.
      /// </summary>
      protected override void OnBarUpdate()
      {
      if (CurrentBar == 0)
      {
      fastEma.Set(Input[0]);
      slowEma.Set(Input[0]);
      Value.Set(0);
      Avg.Set(0);
      Diff.Set(0);
      }
      else
      {
      fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
      slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);

      double macd = fastEma[0] - slowEma[0];
      double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];

      Value.Set(macd);
      Avg.Set(macdAvg);
      Diff.Set(macd - macdAvg);
      }
      }

      #region Properties
      /// <summary>
      /// </summary>
      [Browsable(false)]
      [XmlIgnore()]
      public DataSeries Avg
      {
      get { return Values[1]; }
      }

      /// <summary>
      /// </summary>
      [Browsable(false)]
      [XmlIgnore()]
      public DataSeries Default
      {
      get { return Values[0]; }
      }

      /// <summary>
      /// </summary>
      [Browsable(false)]
      [XmlIgnore()]
      public DataSeries Diff
      {
      get { return Values[2]; }
      }

      /// <summary>
      /// </summary>
      [Description("Number of bars for fast EMA")]
      [GridCategory("Parameters")]
      public int Fast
      {
      get { return fast; }
      set { fast = Math.Max(1, value); }
      }

      /// <summary>
      /// </summary>
      [Description("Number of bars for slow EMA")]
      [GridCategory("Parameters")]
      public int Slow
      {
      get { return slow; }
      set { slow = Math.Max(1, value); }
      }

      /// <summary>
      /// </summary>
      [Description("Number of bars for smoothing")]
      [GridCategory("Parameters")]
      public int Smooth
      {
      get { return smooth; }
      set { smooth = 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 MACD[] cacheMACD = null;

      private static MACD checkMACD = new MACD();

      /// <summary>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      /// <returns></returns>
      public MACD MACD(int fast, int slow, int smooth)
      {
      return MACD(Input, fast, slow, smooth);
      }

      /// <summary>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      /// <returns></returns>
      public MACD MACD(Data.IDataSeries input, int fast, int slow, int smooth)
      {
      if (cacheMACD != null)
      for (int idx = 0; idx < cacheMACD.Length; idx++)
      if (cacheMACD[idx].Fast == fast && cacheMACD[idx].Slow == slow && cacheMACD[idx].Smooth == smooth && cacheMACD[idx].EqualsInput(input))
      return cacheMACD[idx];

      lock (checkMACD)
      {
      checkMACD.Fast = fast;
      fast = checkMACD.Fast;
      checkMACD.Slow = slow;
      slow = checkMACD.Slow;
      checkMACD.Smooth = smooth;
      smooth = checkMACD.Smooth;

      if (cacheMACD != null)
      for (int idx = 0; idx < cacheMACD.Length; idx++)
      if (cacheMACD[idx].Fast == fast && cacheMACD[idx].Slow == slow && cacheMACD[idx].Smooth == smooth && cacheMACD[idx].EqualsInput(input))
      return cacheMACD[idx];

      MACD indicator = new MACD();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
      indicator.Input = input;
      indicator.Fast = fast;
      indicator.Slow = slow;
      indicator.Smooth = smooth;
      Indicators.Add(indicator);
      indicator.SetUp();

      MACD[] tmp = new MACD[cacheMACD == null ? 1 : cacheMACD.Length + 1];
      if (cacheMACD != null)
      cacheMACD.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cacheMACD = 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>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.MACD MACD(int fast, int slow, int smooth)
      {
      return _indicator.MACD(Input, fast, slow, smooth);
      }

      /// <summary>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      /// <returns></returns>
      public Indicator.MACD MACD(Data.IDataSeries input, int fast, int slow, int smooth)
      {
      return _indicator.MACD(input, fast, slow, smooth);
      }
      }
      }

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      public partial class Strategy : StrategyBase
      {
      /// <summary>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.MACD MACD(int fast, int slow, int smooth)
      {
      return _indicator.MACD(Input, fast, slow, smooth);
      }

      /// <summary>
      /// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
      /// </summary>
      /// <returns></returns>
      public Indicator.MACD MACD(Data.IDataSeries input, int fast, int slow, int smooth)
      {
      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.MACD(input, fast, slow, smooth);
      }
      }
      }
      #endregion

      I want to record the current bar, when the macd is crossing.
      Data Series like 0,0,0,...55,0,0,...,88,...

      Many thanks,PatrickH.
      Thomson

      Comment


        #4
        Hello thomson,

        Thank you for your response.

        Below is an example of a cross for the fast and slow EMA use in MACD and printing the bar number it occurs on in Output Window (Tools > Output Window):
        Code:
        		protected override void OnBarUpdate()
        		{
        			if (CurrentBar == 0)
        			{
        				fastEma.Set(Input[0]);
        				slowEma.Set(Input[0]);
        				Value.Set(0);
        				Avg.Set(0);
        				Diff.Set(0);
        			}
        			else
        			{
        				fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
        				slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
        
        				double macd		= fastEma[0] - slowEma[0];
        				double macdAvg	= (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];
        				
        				Value.Set(macd);
        				Avg.Set(macdAvg);
        				Diff.Set(macd - macdAvg);
        				
        [B]				if(CrossAbove(slowEma, fastEma, 1))
        				{
        					Print("Slow cross above Fast on bar number " + CurrentBar);
        				}[/B]
        			}
        I recommend right clicking in the MACD NinjaScript Editor and selecting Save As > give the indicator a new name and then making your changes to the new indicator.

        Please let me know if you have any questions.

        Comment


          #5
          Thanks for your information,PatrickH. I want to put the current bar information to data series, which I can use it for my strategy. I got an error as below, 'OnBarUpdate' method for indicator 'testMACD' on bar 0: Index was outside the bounds of the array.
          Please see my attached code as below,
          //
          // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
          //

          #region Using declarations
          using System;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.ComponentModel;
          using System.Xml.Serialization;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion

          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          [Description("The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
          public class testMACD : Indicator
          {
          #region Variables
          private int fast = 12;
          private int slow = 26;
          private int smooth = 9;
          private DataSeries fastEma;
          private DataSeries slowEma;
          #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, "testMACD"));
          Add(new Plot(Color.DarkViolet, "Avg"));
          Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff"));

          Add(new Line(Color.DarkGray, 0, "Zero line"));

          fastEma = new DataSeries(this);
          slowEma = new DataSeries(this);
          }

          /// <summary>
          /// Calculates the indicator value(s) at the current index.
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (CurrentBar == 0)
          {
          fastEma.Set(Input[0]);
          slowEma.Set(Input[0]);
          Value.Set(0);
          Avg.Set(0);
          Diff.Set(0);
          StartBar.Set(0);
          }
          else
          {
          fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
          slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);

          double testMACD = fastEma[0] - slowEma[0];
          double testMACDAvg = (2.0 / (1 + Smooth)) * testMACD + (1 - (2.0 / (1 + Smooth))) * Avg[1];

          Value.Set(testMACD);
          Avg.Set(testMACDAvg);
          Diff.Set(testMACD - testMACDAvg);
          if(CrossAbove(slowEma, fastEma, 1))
          {
          Print("Slow cross above Fast on bar number " + CurrentBar);
          }
          StartBar.Set(0);

          }
          }

          #region Properties
          /// <summary>
          /// </summary>
          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries Avg
          {
          get { return Values[1]; }
          }

          /// <summary>
          /// </summary>
          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries Default
          {
          get { return Values[0]; }
          }

          /// <summary>
          /// </summary>
          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries Diff
          {
          get { return Values[2]; }
          }

          /// <summary>
          /// </summary>
          [Browsable(false)]
          [XmlIgnore()]
          public DataSeries StartBar
          {
          get { return Values[3]; }
          }

          /// <summary>
          /// </summary>
          [Description("Number of bars for fast EMA")]
          [GridCategory("Parameters")]
          public int Fast
          {
          get { return fast; }
          set { fast = Math.Max(1, value); }
          }

          /// <summary>
          /// </summary>
          [Description("Number of bars for slow EMA")]
          [GridCategory("Parameters")]
          public int Slow
          {
          get { return slow; }
          set { slow = Math.Max(1, value); }
          }

          /// <summary>
          /// </summary>
          [Description("Number of bars for smoothing")]
          [GridCategory("Parameters")]
          public int Smooth
          {
          get { return smooth; }
          set { smooth = 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 testMACD[] cachetestMACD = null;

          private static testMACD checktestMACD = new testMACD();

          /// <summary>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          /// <returns></returns>
          public testMACD testMACD(int fast, int slow, int smooth)
          {
          return testMACD(Input, fast, slow, smooth);
          }

          /// <summary>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          /// <returns></returns>
          public testMACD testMACD(Data.IDataSeries input, int fast, int slow, int smooth)
          {
          if (cachetestMACD != null)
          for (int idx = 0; idx < cachetestMACD.Length; idx++)
          if (cachetestMACD[idx].Fast == fast && cachetestMACD[idx].Slow == slow && cachetestMACD[idx].Smooth == smooth && cachetestMACD[idx].EqualsInput(input))
          return cachetestMACD[idx];

          lock (checktestMACD)
          {
          checktestMACD.Fast = fast;
          fast = checktestMACD.Fast;
          checktestMACD.Slow = slow;
          slow = checktestMACD.Slow;
          checktestMACD.Smooth = smooth;
          smooth = checktestMACD.Smooth;

          if (cachetestMACD != null)
          for (int idx = 0; idx < cachetestMACD.Length; idx++)
          if (cachetestMACD[idx].Fast == fast && cachetestMACD[idx].Slow == slow && cachetestMACD[idx].Smooth == smooth && cachetestMACD[idx].EqualsInput(input))
          return cachetestMACD[idx];

          testMACD indicator = new testMACD();
          indicator.BarsRequired = BarsRequired;
          indicator.CalculateOnBarClose = CalculateOnBarClose;
          #if NT7
          indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
          indicator.MaximumBarsLookBack = MaximumBarsLookBack;
          #endif
          indicator.Input = input;
          indicator.Fast = fast;
          indicator.Slow = slow;
          indicator.Smooth = smooth;
          Indicators.Add(indicator);
          indicator.SetUp();

          testMACD[] tmp = new testMACD[cachetestMACD == null ? 1 : cachetestMACD.Length + 1];
          if (cachetestMACD != null)
          cachetestMACD.CopyTo(tmp, 0);
          tmp[tmp.Length - 1] = indicator;
          cachetestMACD = 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>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.testMACD testMACD(int fast, int slow, int smooth)
          {
          return _indicator.testMACD(Input, fast, slow, smooth);
          }

          /// <summary>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          /// <returns></returns>
          public Indicator.testMACD testMACD(Data.IDataSeries input, int fast, int slow, int smooth)
          {
          return _indicator.testMACD(input, fast, slow, smooth);
          }
          }
          }

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          public partial class Strategy : StrategyBase
          {
          /// <summary>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.testMACD testMACD(int fast, int slow, int smooth)
          {
          return _indicator.testMACD(Input, fast, slow, smooth);
          }

          /// <summary>
          /// The testMACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
          /// </summary>
          /// <returns></returns>
          public Indicator.testMACD testMACD(Data.IDataSeries input, int fast, int slow, int smooth)
          {
          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.testMACD(input, fast, slow, smooth);
          }
          }
          }
          #endregion
          Please advise.
          Many thanks,
          Thomson

          Comment


            #6
            Hello thomson,

            Thank you for your response.

            Can you attach the .cs file for the indicator to your response?

            You will find the indicator in the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom\Indicator

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

            Comment


              #7
              Please see my attached cs file. Thanks PatrickH.
              Attached Files

              Comment


                #8
                Please see my attached .cs file. Change snap code as below,

                if(CrossAbove(slowEma, fastEma, 1))
                {
                Print("Slow cross above Fast on bar number " + CurrentBar);
                StartBar.Set(CurrentBar);
                }

                I want to get data series StartBar as output.

                Please advice how to fix the error 'OnBarUpdate' method for indicator 'testMACD' on bar 0: Index was outside the bounds of the array.

                Thanks,
                Thomson

                Comment


                  #9
                  Hello thomson,

                  Thank you for your response.

                  The startBar DataSeries needs to be created before set in the code. Please review the code below for information on this:
                  Code:
                  #region Variables
                  ...
                  [B]private IntSeries startBar;[/B]
                  #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()
                  {
                  ...
                  [B]startBar = new IntSeries(this);[/B]
                  }
                  
                  /// <summary>
                  /// Calculates the indicator value(s) at the current index.
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  if (CurrentBar == 0)
                  {
                  fastEma.Set(Input[0]);
                  slowEma.Set(Input[0]);
                  Value.Set(0);
                  Avg.Set(0);
                  Diff.Set(0);
                  [B]startBar.Set(0);[/B]
                  }
                  else
                  {
                  fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
                  slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
                  
                  double testMACD	 = fastEma[0] - slowEma[0];
                  double testMACDAvg	= (2.0 / (1 + Smooth)) * testMACD + (1 - (2.0 / (1 + Smooth))) * Avg[1];
                  
                  Value.Set(testMACD);
                  Avg.Set(testMACDAvg);
                  Diff.Set(testMACD - testMACDAvg);
                  	if(CrossAbove(slowEma, fastEma, 1))
                  				{
                  					Print("Slow cross above Fast on bar number " + CurrentBar);
                  				}
                  				[B]startBar.Set(CurrentBar);[/B]
                  				
                  }
                  }
                  For information on IntSeries please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm

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

                  Comment


                    #10
                    Thanks PatrickH. May I ask one more question? I saw some indicator have Properties like code as below,

                    What is the Values[0]'s means? By default if I am not set value to Values[0],what's the value is? How to set Values[0]'s value.

                    public DataSeries StopDot
                    {
                    get { return Values[0]; }
                    }

                    Many thanks,
                    Thomson

                    Comment


                      #11
                      How can I get start bar's open and close price as data series out put?
                      I try to do the code as below,
                      Code:
                      #region Variables
                      ...
                      private IntSeries startBar;
                      #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()
                      {
                      ...
                      startBar = new IntSeries(this);
                      }
                      
                      /// <summary>
                      /// Calculates the indicator value(s) at the current index.
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      if (CurrentBar == 0)
                      {
                      fastEma.Set(Input[0]);
                      slowEma.Set(Input[0]);
                      Value.Set(0);
                      Avg.Set(0);
                      Diff.Set(0);
                      startBar.Set(0);
                      }
                      else
                      {
                      fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
                      slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
                      
                      double testMACD     = fastEma[0] - slowEma[0];
                      double testMACDAvg    = (2.0 / (1 + Smooth)) * testMACD + (1 - (2.0 / (1 + Smooth))) * Avg[1];
                      
                      Value.Set(testMACD);
                      Avg.Set(testMACDAvg);
                      Diff.Set(testMACD - testMACDAvg);
                          if(CrossAbove(slowEma, fastEma, 1))
                         {         Print("Slow cross above Fast on bar number " + CurrentBar);
                                      startBar.Set(CurrentBar);
                      
                      ClosePrice.Set(Close[0]);
                      OpenPrice.Set([Open[0]);
                       }                                   } }
                      
                      [Browsable(false)]
                      [XmlIgnore()]
                      public DataSeries OpenPrice
                      {
                      get { return Values[3]; }
                      }
                      
                      /// <summary>
                      /// </summary>
                      [Browsable(false)]
                      [XmlIgnore()]
                      public DataSeries ClosePrice
                      {
                      get { return Values[4]; }
                      }
                      Same error, Is anything wrong here?
                      Thanks,
                      Thomson
                      Last edited by thomson; 09-11-2013, 09:17 AM.

                      Comment


                        #12
                        Hello,

                        Thank you for your response.

                        Have you set this in the variables as well as the Initialize() method?
                        Code:
                        #region Variables
                        private DataSeries myDataSeries; // Define a DataSeries variable
                        #endregion
                         
                        // Create a DataSeries object and assign it to the variable
                        protected override void Initialize() 
                        { 
                            myDataSeries = new DataSeries(this);
                        Taken from our Help Guide in the DataSeries Class section: http://www.ninjatrader.com/support/h...ries_class.htm

                        Please let me know if this resolves the matter.

                        Comment


                          #13
                          Thanks for your answer.
                          Final question, if I am not set the value to my data series, what the default value?
                          I mean I have if ..else statement.
                          If condition { startBar.set(CurrentBar); OpenPrice.Set[Open[0];}
                          else { doing nothing}
                          what is the default value of doing nothing part of my data series?
                          Thanks for your help!
                          Thomson

                          Comment


                            #14
                            Hello tomson,

                            Thank you for your response.

                            It's up to you on that point, whether you want to set them to 0 or something else.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by bortz, 11-06-2023, 08:04 AM
                            47 responses
                            1,603 views
                            0 likes
                            Last Post aligator  
                            Started by jaybedreamin, Today, 05:56 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post jaybedreamin  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            6 responses
                            18 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Started by Jon17, Today, 04:33 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post Jon17
                            by Jon17
                             
                            Started by Javierw.ok, Today, 04:12 PM
                            0 responses
                            12 views
                            0 likes
                            Last Post Javierw.ok  
                            Working...
                            X