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 Newbie DrawLine problem

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

    Simple Newbie DrawLine problem

    Tried making my first indicator ... and ran into trouble. I'm just drawing some simple lines on the price chart. Played around and it was working fine Saturday. But it wasn't working on 'replay' data.

    And now, it's not showing up at all. I may have made some small change trying to make it work that messed it up ... not sure what it is. My C++ skills are brand new; learned Fortran on a mainframe and quit most programming when Visual Basic moved to .Net ....

    Thanks for any light you can shine on this ...

    ST
    Attached Files

    #2
    Hello Slipstream,

    Thanks for your post and welcome to the forums!

    Regrettable the image you posted is not visible.

    Can you post your code so that we might see what you are doing?

    Alternatively you can write in to Platformsupport[at]Ninjatrader[dot]com and attach your source file to the e-mail along with attaching your screenshot. In the subject line please put Atten: Paul and Simple Newbie DrawLine problem. Note that we used [at] to represent "@" and [dot] to represent "." to deter the spambots that look for e-mail addresses.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      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>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      [Description("Puts a small line on matching reversal candles for possible reauction")]
      public class stTriggerLine : Indicator
      {
      #region Variables
      // Wizard generated variables
      private bool triggerLineShow = true; // Default setting for TriggerLineShow
      // 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"));
      Overlay = true;

      }

      /// <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.
      // Plot0.Set(Close[0]);
      if ((
      (Close[1] >= Open[1] && Close[2] <= Open[2]) ||
      (Close[1] <= Open[1] && Close[2] >= Open[2]))
      && (Close[1] == Open[2] ))

      { DrawLine("TriggerLine" + CurrentBar,false,5,Close[1],0,Close[1],Color.Fuchsia,DashStyle.Solid,1);

      }

      else if ((
      (Close[1] >= Open[1] && Close[2] <= Open[2]) ||
      (Close[1] <= Open[1] && Close[2] >= Open[2]))
      && (Close[2] == Open[1] ))

      { DrawLine("TriggerLine" + CurrentBar,false,5,Open[1],0,Open[1],Color.Fuchsia,DashStyle.Solid,1);

      }

      }



      #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


      [Description("Show trigger line; on off")]
      [GridCategory("Parameters")]
      public bool TriggerLineShow
      {
      get { return triggerLineShow; }
      set { triggerLineShow = 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 stTriggerLine[] cachestTriggerLine = null;

      private static stTriggerLine checkstTriggerLine = new stTriggerLine();

      /// <summary>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      /// <returns></returns>
      public stTriggerLine stTriggerLine(bool triggerLineShow)
      {
      return stTriggerLine(Input, triggerLineShow);
      }

      /// <summary>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      /// <returns></returns>
      public stTriggerLine stTriggerLine(Data.IDataSeries input, bool triggerLineShow)
      {
      if (cachestTriggerLine != null)
      for (int idx = 0; idx < cachestTriggerLine.Length; idx++)
      if (cachestTriggerLine[idx].TriggerLineShow == triggerLineShow && cachestTriggerLine[idx].EqualsInput(input))
      return cachestTriggerLine[idx];

      lock (checkstTriggerLine)
      {
      checkstTriggerLine.TriggerLineShow = triggerLineShow;
      triggerLineShow = checkstTriggerLine.TriggerLineShow;

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

      stTriggerLine indicator = new stTriggerLine();
      indicator.BarsRequired = BarsRequired;
      indicator.CalculateOnBarClose = CalculateOnBarClose;
      #if NT7
      indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
      indicator.MaximumBarsLookBack = MaximumBarsLookBack;
      #endif
      indicator.Input = input;
      indicator.TriggerLineShow = triggerLineShow;
      Indicators.Add(indicator);
      indicator.SetUp();

      stTriggerLine[] tmp = new stTriggerLine[cachestTriggerLine == null ? 1 : cachestTriggerLine.Length + 1];
      if (cachestTriggerLine != null)
      cachestTriggerLine.CopyTo(tmp, 0);
      tmp[tmp.Length - 1] = indicator;
      cachestTriggerLine = 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>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.stTriggerLine stTriggerLine(bool triggerLineShow)
      {
      return _indicator.stTriggerLine(Input, triggerLineShow);
      }

      /// <summary>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      /// <returns></returns>
      public Indicator.stTriggerLine stTriggerLine(Data.IDataSeries input, bool triggerLineShow)
      {
      return _indicator.stTriggerLine(input, triggerLineShow);
      }
      }
      }

      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      public partial class Strategy : StrategyBase
      {
      /// <summary>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      /// <returns></returns>
      [Gui.Design.WizardCondition("Indicator")]
      public Indicator.stTriggerLine stTriggerLine(bool triggerLineShow)
      {
      return _indicator.stTriggerLine(Input, triggerLineShow);
      }

      /// <summary>
      /// Puts a small line on matching reversal candles for possible reauction
      /// </summary>
      /// <returns></returns>
      public Indicator.stTriggerLine stTriggerLine(Data.IDataSeries input, bool triggerLineShow)
      {
      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.stTriggerLine(input, triggerLineShow);
      }
      }
      }
      #endregion

      Comment


        #4
        Hello Slipstream,

        Thanks for posting your code.

        If you check the "log" tab of the control center you will see error messages indicating an error with the "OnBarUpdateMethod on bar 0. StartBatsAgo out of valid range 0 through 0, was 5". The error message is produced because when an indicator loads it processes the data from the very beginning which starts at bar 0 of the data that is loaded on the chart. So in this case your drawline statement is trying to use the 5th bar ago on the very first bar which (5th bar ago) does not yet exist.

        To resolve this, in the code below the OnBarUpdate() method, please add this line:

        if (CurrentBar < 5) return; // return if not enough bars to process.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Got it

          thanks, i understand completely. Working now!

          ST

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          6 responses
          24 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X