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

Simple Indicator Question

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

    Simple Indicator Question

    Hello To All,

    How can I program a simple indicator that does two things
    1). Shows the calculated value in the Data Bax
    2). Does not plot anything to the chart nor does it affect the charts price scale

    Thank you for your Time
    Scott

    #2
    Hello kingmordecai,

    Welcome to the NinjaTrader forums!

    To show a value in the DataBox, it is necessary to set a plot value.
    I'm trying to expose my variables to the strategy builder so everyone can have better use of the WaveTrend indicator (it has a lot of code). Explain this to me like I am 5 because this isnt the first time I've tried to figure it out and hit a wall. What is Series? I know its like an array that stores bars. Why not just call it



    To prevent a set plot from appearing on the chart, override OnRender() and do not call base.OnRender().


    To prevent the indicator from affecting the scaling, set IsAutoScale to false.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ok I think I have followed your suggestions, but I am just not getting it
      Here is the code
      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class TestBars : Indicator
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "TestBars";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = true;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = true;
                      DrawHorizontalGridLines                        = true;
                      DrawVerticalGridLines                        = true;
                      PaintPriceMarkers                            = true;
                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
                      IsAutoScale                                 = true;
                      AddPlot(Brushes.Transparent, "BarsShowInDataBox");
                  }
                  else if (State == State.Configure)
                  {
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  //Add your custom indicator logic here.
                  BarsShowInDataBox[0] = CurrentBar;
              }
      
              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {
                  if (Bars == null || ChartControl == null)
                      return;
                  //return;
              }
      
              #region Properties
      
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> BarsShowInDataBox
              {
                  get { return Values[0]; }
              }
              #endregion
      
          }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
              private TestBars[] cacheTestBars;
              public TestBars TestBars()
              {
                  return TestBars(Input);
              }
      
              public TestBars TestBars(ISeries<double> input)
              {
                  if (cacheTestBars != null)
                      for (int idx = 0; idx < cacheTestBars.Length; idx++)
                          if (cacheTestBars[idx] != null &&  cacheTestBars[idx].EqualsInput(input))
                              return cacheTestBars[idx];
                  return CacheIndicator<TestBars>(new TestBars(), input, ref cacheTestBars);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
              public Indicators.TestBars TestBars()
              {
                  return indicator.TestBars(Input);
              }
      
              public Indicators.TestBars TestBars(ISeries<double> input )
              {
                  return indicator.TestBars(input);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
              public Indicators.TestBars TestBars()
              {
                  return indicator.TestBars(Input);
              }
      
              public Indicators.TestBars TestBars(ISeries<double> input )
              {
                  return indicator.TestBars(input);
              }
          }
      }
      
      #endregion
      ​
      When I have the Plot set to a color and not transparent, I can see the bar numbers in the data box, but it also plots on the chart which is what I don't want.
      When I set the Plot to use the transparent color, it doesn't plot on the screen but it also doesn't show in the Data Box.
      Click image for larger version

Name:	NoPlotNoDataBox.png
Views:	204
Size:	30.9 KB
ID:	1229282
      Click image for larger version

Name:	PlotDataBox.png
Views:	100
Size:	25.8 KB
ID:	1229283

      Comment


        #4
        Hello kingmordecai,

        The screenshots you have provided are very low quality and have a lot of white space on the bottom and right, so hard to see whats in the databox in the second screenshot.

        However, the plot should be added with a color. Do not use transparent, try Brushes.Blue. By not rendering, the plot line is not drawn at all so not visible. By not including with auto scale, the scaling should not be affected.

        Regarding the IsAutoScale, if you are setting this in State.SetDefaults, remove the script instance and add a new instance to pull the defaults. Othewise, set IsAutoScale to false in State.Configure.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ahh I got it thank you for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Max238, Today, 01:28 AM
          1 response
          22 views
          0 likes
          Last Post CactusMan  
          Started by giulyko00, Yesterday, 12:03 PM
          2 responses
          10 views
          0 likes
          Last Post giulyko00  
          Started by r68cervera, Today, 05:29 AM
          0 responses
          4 views
          0 likes
          Last Post r68cervera  
          Started by geddyisodin, Today, 05:20 AM
          0 responses
          6 views
          0 likes
          Last Post geddyisodin  
          Started by JonesJoker, 04-22-2024, 12:23 PM
          6 responses
          38 views
          0 likes
          Last Post JonesJoker  
          Working...
          X