Announcement

Collapse
No announcement yet.

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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        152 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        89 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        133 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        127 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X