Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

B5 & B6 - Draw Objects "jump to the left"

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

    B5 & B6 - Draw Objects "jump to the left"

    The following issue applies to (all?) draw objects (at least Text) that are created

    a) by program (indicator)
    b) with a DateTime and not a barsAgo parameter in the constructor call
    c) in state DataLoaded

    Description:

    After a draw object is drawn on the indicator by program remove the lock property and move the draw object. When done for the first time by mouse the draw object disappears on the left side of the chartpanel, while you keep the mouse pressed and move it to the right, the draw object appears again from the left panel border and moves with the mouse and offset now.

    After the first move the object behaves normally and there is no isssue on draw objects that were created by user on the indicator directly.

    Cause:

    After debugging it seems to me that this is an anchor problem.

    The anchor is created in the Draw class of the draw object(DateTime variant constructor). Later in the OnMouseMove method the anchor x coordinate is ruined after the Anchor.MoveAnchor method was called for the first time.

    The only difference between anchors created as described and the rest seems to be that the odd ones have - the first time - property value DrawnOnBar "-1" - and afterwards like user created anchors - "-2147483648". Maybe this helps you locating the problem.

    See the example screencast in the attached archive.

    Cheers,
    patapata
    Attached Files
    Last edited by patapata; 11-02-2015, 04:08 PM.

    #2
    Hello,

    Thank you for reporting this to us. Since this appears to be a very specific scenario, do you have a code sample that you can share which will reproduce this scenario?
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Specific scenario? Okay?!
      Place this in your custom indicator:

      protected override void OnStateChange()
      {
      if (State == State.DataLoaded)
      {
      Text MyText = Draw.Text(this, "Tag", true, "Text", DateTime.Now, 2100d, 0, Brushes.Black, new Gui.Tools.SimpleFont("Arial", 36), TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      }
      }

      2100d is the price and should be modified depending on your instrument, fine for S&P500 today.

      Remove the lock property of the text draw object and move it with the mouse pressed.
      See what happens.

      Here is the complete indicator, works perfectly wrong ;-)

      #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.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 MyCustomIndicator : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "MyCustomIndicator";
      Calculate = Calculate.OnBarClose;
      IsOverlay = false;
      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;
      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      Text MyText = Draw.Text(this, "Tag", true, "Text", DateTime.Now, 2100d, 0, Brushes.Black, new Gui.Tools.SimpleFont("Arial", 36), TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      }
      }

      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here.
      }
      }
      }

      #region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private MyCustomIndicator[] cacheMyCustomIndicator;
      public MyCustomIndicator MyCustomIndicator()
      {
      return MyCustomIndicator(Input);
      }

      public MyCustomIndicator MyCustomIndicator(ISeries<double> input)
      {
      if (cacheMyCustomIndicator != null)
      for (int idx = 0; idx < cacheMyCustomIndicator.Length; idx++)
      if (cacheMyCustomIndicator[idx] != null && cacheMyCustomIndicator[idx].EqualsInput(input))
      return cacheMyCustomIndicator[idx];
      return CacheIndicator<MyCustomIndicator>(new MyCustomIndicator(), input, ref cacheMyCustomIndicator);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.MyCustomIndicator MyCustomIndicator()
      {
      return indicator.MyCustomIndicator(Input);
      }

      public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input )
      {
      return indicator.MyCustomIndicator(input);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.MyCustomIndicator MyCustomIndicator()
      {
      return indicator.MyCustomIndicator(Input);
      }

      public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input )
      {
      return indicator.MyCustomIndicator(input);
      }
      }
      }

      #endregion
      Last edited by patapata; 11-02-2015, 05:40 PM.

      Comment


        #4
        Thank you for that. I will jump on this and try to reproduce on my end as soon as possible, and I will post back on this thread with any updates or a bug report ID.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          You can fix it by setting anchor.DrawnOnBar = -2147483648, although this is just a workaround.

          Example for Text.cs:

          ...
          // dont nuke existing anchor refs
          ChartAnchor anchor = null;
          if (barsAgo > int.MinValue)
          anchor = new ChartAnchor(barsAgo, y, currentBar, chartControl);
          else if (time > Core.Globals.MinDate)
          // anchor = new ChartAnchor(time, y, currentBar, chartControl); // Delete
          { // Insert
          anchor = new ChartAnchor(time, y, currentBar, chartControl); // Insert
          anchor.DrawnOnBar = -2147483648; // Insert
          } // Insert

          anchor.CopyDataValues(txt.Anchor);
          ...

          Comment


            #6
            After playing with the script this morning, I can definitely see the issue that you reported. The drawing object anchor on the Time Axis seems to be setting itself to the first bar loaded in the data series the first time it is manually moved (but then appears to move as expected after that).

            After discussing this with our developers, this kind of behavior can be expected when calling a drawing method within State.DataLoaded. The drawing methods were only intended to be called within OnBarUpdate(), since this ensures that bars are actually being processed when the methods are called.
            Dave I.NinjaTrader Product Management

            Comment


              #7
              Thank you for this information.

              Imho it makes sometimes sense to draw (better create) objects that are not bar dependent outside onbarupdate to improve performance. User drawn objects are also not created onbarupdate afaik.

              In addition to that the draw object is drawn with time information on the x axis so no bar is needed (what about future, where no bars are available), and it is nowhere written, that draw objects only work properly, when created onbarupdate. This is why a draw object can be created with bar or time information, right?

              Please consider this and check again with your development team.

              Anyway you can solve this in the anchor constructor easily as described in my last post. You set the value DrawnOnBar to -2147483648 in the anchor when created with time information and it works properly.

              Status quo is not a feature ;-).
              Last edited by patapata; 11-03-2015, 11:24 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by nandhumca, Today, 03:41 PM
              0 responses
              3 views
              0 likes
              Last Post nandhumca  
              Started by The_Sec, Today, 03:37 PM
              0 responses
              3 views
              0 likes
              Last Post The_Sec
              by The_Sec
               
              Started by GwFutures1988, Today, 02:48 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by ScottWalsh, 04-16-2024, 04:29 PM
              6 responses
              33 views
              0 likes
              Last Post ScottWalsh  
              Started by frankthearm, Today, 09:08 AM
              10 responses
              36 views
              0 likes
              Last Post frankthearm  
              Working...
              X