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

Differential Indicator, is possible?

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

    Differential Indicator, is possible?

    Hello.
    Sorry,but I' don't find any solution to a my (probably silly) question.
    I want to program such indicator:

    Plot0.Set((Close[0]-Close[10])/(Vol[0]-Vol[10]))

    /*CalculateOnBarClose = false;*/


    In all my attempts compilation OK, but no plot.
    Can anyone suggest me the right direction?

    Thanks

    Paolo

    #2
    Originally posted by paolfili View Post
    Hello.
    Sorry,but I' don't find any solution to a my (probably silly) question.
    I want to program such indicator:

    Plot0.Set((Close[0]-Close[10])/(Vol[0]-Vol[10]))

    /*CalculateOnBarClose = false;*/


    In all my attempts compilation OK, but no plot.
    Can anyone suggest me the right direction?

    Thanks

    Paolo
    Hello,

    try this:

    Code:
    if ( CurrentBar < 10 ) return;
    Plot0.Set((Close[0]-Close[10])/(Vol[0]-Vol[10]))
    Regards

    Comment


      #3
      Thanks.
      No way ....


      ------------------------
      This is the 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>
      /// Difference in Price
      /// </summary>
      [Description("Difference in Price")]
      public class DiffPrice : 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()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.SlateGray), PlotStyle.Line, "Plot0"));
      CalculateOnBarClose = false;
      Overlay = false;
      PriceTypeSupported = 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.
      if ( CurrentBar < 10 ) return;
      Plot0.Set((Close[0]-Close[10])/(Volume[0]-Volume[10]));
      }

      #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]; }
      }

      #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 DiffPrice[] cacheDiffPrice = null;

      private static DiffPrice checkDiffPrice = new DiffPrice();

      /// <summary>
      /// Difference in Price
      /// </summary>
      /// <returns></returns>
      public DiffPrice DiffPrice()
      {
      return DiffPrice(Input);
      }

      /// <summary>
      /// Difference in Price
      /// </summary>
      /// <returns></returns>
      public DiffPrice DiffPrice(Data.IDataSeries input)
      {

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

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

      DiffPrice[] tmp = new DiffPrice[cacheDiffPrice == null ? 1 : cacheDiffPrice.Length + 1];
      if (cacheDiffPrice != null)
      cacheDiffPrice.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cacheDiffPrice = 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>
      /// Difference in Price
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.DiffPrice DiffPrice()
      {
      return _indicator.DiffPrice(Input);
      }

      /// <summary>
      /// Difference in Price
      /// </summary>
      /// <returns></returns>
      public Indicator.DiffPrice DiffPrice(Data.IDataSeries input)
      {
      return _indicator.DiffPrice(input);
      }

      }
      }

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      public partial class Strategy : StrategyBase
      {
      /// <summary>
      /// Difference in Price
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.DiffPrice DiffPrice()
      {
      return _indicator.DiffPrice(Input);
      }

      /// <summary>
      /// Difference in Price
      /// </summary>
      /// <returns></returns>
      public Indicator.DiffPrice DiffPrice(Data.IDataSeries input)
      {
      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.DiffPrice(input);
      }

      }
      }
      #endregion



      Originally posted by cls71 View Post
      Hello,

      try this:

      Code:
      if ( CurrentBar < 10 ) return;
      Plot0.Set((Close[0]-Close[10])/(Vol[0]-Vol[10]))
      Regards

      Comment


        #4
        paolfili, any errors in the log tab when this indicator is applied to the chart? You probably run into divide by 0 / overflow issues with this guide -

        You can check into the default 'Stochastics' indicator (K.Set piece) to see how you can guard agains this.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pechtri, 06-22-2023, 02:31 AM
        9 responses
        122 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by frankthearm, 04-18-2024, 09:08 AM
        16 responses
        66 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by habeebft, Today, 01:18 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by benmarkal, Today, 12:52 PM
        2 responses
        13 views
        0 likes
        Last Post benmarkal  
        Started by f.saeidi, Today, 01:38 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X