Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling Indicator from Stategy?

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

    Calling Indicator from Stategy?

    I want to call an Indicator I created (DailyPlot) from a Strategy, Here is the code in the Strategy:

    double DLYH=Highs[0][2];
    double DLYL=Lows[0][2];
    double DLYO=Opens[0][2];
    DailyPlot(DLYH,DLYL,DLYO);

    The plot does not appear, what am I doing wrong?

    #2
    Hello,

    Are you trying to use multiple time frames? The second set of brakets call on a different instrument/timeframe:


    Also, what is DailyPlot() doing? We need to see more of your code to understand what you are doing.
    DenNinjaTrader Customer Service

    Comment


      #3
      oops!, yeah I switched them in a desperate attempt to get results... Dailyplot is a simple plot inicator, here is the code for it:

      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>
      /// Enter the description of your new custom indicator here
      /// </summary>
      [Description("Enter the description of your new custom indicator here")]
      public class DailyPlot : Indicator
      {
      #region Variables
      // Wizard generated variables
      private double high = 0; // Default setting for High
      private double low = 0; // Default setting for Low
      private double open = 0; // Default setting for Open
      // 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.Red), PlotStyle.Line, "DailyHigh"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "DailyLow"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "DailyOpen"));
      CalculateOnBarClose = false;
      Overlay = true;
      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.
      DailyHigh.Set(High);
      DailyLow.Set(Low);
      DailyOpen.Set(Open);
      }
      #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 DailyHigh
      {
      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 DailyLow
      {
      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 DailyOpen
      {
      get { return Values[2]; }
      }
      [Description("")]
      [Category("Parameters")]
      public double High
      {
      get { return high; }
      set { high = Math.Max(0, value); }
      }
      [Description("")]
      [Category("Parameters")]
      public double Low
      {
      get { return low; }
      set { low = Math.Max(0, value); }
      }
      [Description("")]
      [Category("Parameters")]
      public double Open
      {
      get { return open; }
      set { open = Math.Max(0, 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 DailyPlot[] cacheDailyPlot = null;
      private static DailyPlot checkDailyPlot = new DailyPlot();
      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public DailyPlot DailyPlot(double high, double low, double open)
      {
      return DailyPlot(Input, high, low, open);
      }
      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public DailyPlot DailyPlot(Data.IDataSeries input, double high, double low, double open)
      {
      checkDailyPlot.High = high;
      high = checkDailyPlot.High;
      checkDailyPlot.Low = low;
      low = checkDailyPlot.Low;
      checkDailyPlot.Open = open;
      open = checkDailyPlot.Open;
      if (cacheDailyPlot != null)
      for (int idx = 0; idx < cacheDailyPlot.Length; idx++)
      if (Math.Abs(cacheDailyPlot[idx].High - high) <= double.Epsilon && Math.Abs(cacheDailyPlot[idx].Low - low) <= double.Epsilon && Math.Abs(cacheDailyPlot[idx].Open - open) <= double.Epsilon && cacheDailyPlot[idx].EqualsInput(input))
      return cacheDailyPlot[idx];
      DailyPlot indicator = new DailyPlot();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      indicator.Input = input;
      indicator.High = high;
      indicator.Low = low;
      indicator.Open = open;
      indicator.SetUp();
      DailyPlot[] tmp = new DailyPlot[cacheDailyPlot == null ? 1 : cacheDailyPlot.Length + 1];
      if (cacheDailyPlot != null)
      cacheDailyPlot.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cacheDailyPlot = 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.DailyPlot DailyPlot(double high, double low, double open)
      {
      return _indicator.DailyPlot(Input, high, low, open);
      }
      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public Indicator.DailyPlot DailyPlot(Data.IDataSeries input, double high, double low, double open)
      {
      return _indicator.DailyPlot(input, high, low, open);
      }
      }
      }
      // 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.DailyPlot DailyPlot(double high, double low, double open)
      {
      return _indicator.DailyPlot(Input, high, low, open);
      }
      /// <summary>
      /// Enter the description of your new custom indicator here
      /// </summary>
      /// <returns></returns>
      public Indicator.DailyPlot DailyPlot(Data.IDataSeries input, double high, double low, double open)
      {
      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.DailyPlot(input, high, low, open);
      }
      }
      }
      #endregion

      Comment


        #4
        Hello,

        After looking at it briefly, it looks like your variables are named the same as some reserved names: high, low, open, close

        Try using variable names that are not reserved like: myhigh, mylow, etc.

        There are some words that are already used in the language and you should avoid using them in your code.
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X