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

indicator no work

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

    indicator no work

    hellow
    I try to write a indicator for my nj7, It no work.would you like help me? thank you.

    Advol.Set(SUM((Close[0]-Low[0])-(High[0]-Close[0]))*Volume[0]/10000/(High[0]-Low[0])[0]);

    Plot0.Set(Advol[0]);
    Plot1.Set(EMA(Advol[0],30)[0]);
    Plot2.Set(EMA(EMA(Advol[0],30)[0])[0]);



    #2
    Hello zhaofangoo,

    Are you using Add(new Plot()) to add a plot?

    Do you have Advol, Plot0, Plot1, and Plot2, set to return Values[0], Values[1], Values[2], and Values[3]?

    Are you able to print this calculated value?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes,I using to add a plot. thanks!


      // 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 ADVOL : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int advol = 1; // Default setting for Advol
      // 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()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
      Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "Plot2"));
      Advol= new DataSeries(this);
      Overlay = false;
      }

      /// <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.

      Advol.Set(SUM((Close[0]-Low[0])-(High[0]-Close[0]))*Volume[0]/10000/(High[0]-Low[0])[0]);

      Plot0.Set(Advol[0]);
      Plot1.Set(EMA(Advol[0],30)[0]);
      Plot2.Set(EMA(EMA(Advol[0],30)[0])[0]);


      #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 Plot0
      {
      get { return Values[0]; }
      }

      [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 Plot1
      {
      get { return Values[1]; }
      }

      [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 Plot2
      {
      get { return Values[2]; }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int Advol
      {
      get { return advol; }
      set { advol = 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 ADVOL[] cacheADVOL = null;

      private static ADVOL checkADVOL = new ADVOL();

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

      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public ADVOL ADVOL(Data.IDataSeries input, int advol)
      {
      if (cacheADVOL != null)
      for (int idx = 0; idx < cacheADVOL.Length; idx++)
      if (cacheADVOL[idx].Advol == advol && cacheADVOL[idx].EqualsInput(input))
      return cacheADVOL[idx];

      lock (checkADVOL)
      {
      checkADVOL.Advol = advol;
      advol = checkADVOL.Advol;

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

      ADVOL indicator = new ADVOL();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
      indicator.Input = input;
      indicator.Advol = advol;
      Indicators.Add(indicator);
      indicator.SetUp();

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

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

      // 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.ADVOL ADVOL(int advol)
      {
      return _indicator.ADVOL(Input, advol);
      }

      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public Indicator.ADVOL ADVOL(Data.IDataSeries input, int advol)
      {
      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.ADVOL(input, advol);
      }
      }
      }
      #endregion

      Comment


        #4
        Hello zhaofangoo,

        To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message
        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
        Below is a link to the help guide on Exporting NinjaScripts.



        From the code you have shown, Advol is not a plot. This is an integer. This means that .Set() cannot be used on Advol as this is not a plot, its an it.


        What is printing in the NinjaScript Output window when you print the calculation?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I try to rewrite the indicator from other software for my nj7,The original program was :

          A:=SUM(((CLOSE-LOW)-(HIGH-CLOSE))*VOL/10000/(HIGH-LOW),0);
          ADVOL:A;
          MA1:MA(A,30);
          MA2:MA(MA1,100);

          A assignment: ((closing price - the lowest price) - (the highest price-closing price)) * volume / 10000 / (the highest price - lowest price) the cumulative sum

          Output Advol :A

          Output MA1:A's 30-day simple moving average

          Output MA2 :MA1's 100-day simple moving average


          Would you like help me?thanks!
          Last edited by zhaofangoo; 07-28-2020, 03:06 PM.

          Comment


            #6
            Hello zhaofangoo,

            Is Advol mean to be plot?

            Use Add(new Plot()).


            Set the Values[0][0] for the plot.




            In your code, it looks like you already have a plot for this.
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));

            And there is a public Series declaration for the Values[0].
            [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 Plot0
            {
            get { return Values[0]; }
            }

            It seems like this is where you are trying to set the value.
            Print(SUM((Close[0]-Low[0])-(High[0]-Close[0]))*Volume[0]/10000/(High[0]-Low[0])[0]);
            Plot0.Set(SUM((Close[0]-Low[0])-(High[0]-Close[0]))*Volume[0]/10000/(High[0]-Low[0])[0]);
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,789 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X