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

how to draw a vertical line in subwindows

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

    how to draw a vertical line in subwindows

    I want to draw a vertical line in my indicator which is in the subpanel. but the vertical line is only drawn to the main panel. Here is the simplest code to see this

    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 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)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
                if(10<CurrentBar)
                Draw.VerticalLine(this, "tag1", 10, Brushes.Black);
            }
        }
    }
    
    #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
    ​

    #2
    Have you tried changing DrawOnPricePanel to false?
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Originally posted by alanlopen View Post
      I want to draw a vertical line in my indicator which is in the subpanel. but the vertical line is only drawn to the main panel.
      Hi alanlopen,

      I have been using this from NinjaTrader_Jim​. It seems to work well.


      Robotman

      Comment


        #4
        Hello alanlopen,

        Indicators by default draw objects in the price panel, you can toggle where drawing objects show up by setting DrawOnPricePanel to true or false and then remove the script from the chart and reapply the script so the new default is seen.




        JesseNinjaTrader Customer Service

        Comment


          #5
          okay I didnt know about DrawOnPricePanel

          Comment


            #6
            Originally posted by NinjaTrader_Jesse View Post
            Hello alanlopen,

            Indicators by default draw objects in the price panel, you can toggle where drawing objects show up by setting DrawOnPricePanel to true or false and then remove the script from the chart and reapply the script so the new default is seen.



            so this works for drawing a line. But I also draw a region and the region keeps being printed on the main window, instead of the subwindow.

            How do I force the region on the subwindow ?

            Comment


              #7
              If you set DrawOnPricePanel to false, or if you use the overloads of the draw methods that let you specify it by the individual drawing tool instance and set it to false there, then it will appear on the same subpanel as the indicator plots. What you cannot do is have an indicator in subpanel 2 and put drawing tools in subpanel 3 - it's either in the subpanel the indicator is in or on the price subpanel.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Hello alanlopen,

                If you set DrawOnPricePanel = false, and your indicator is in a sub window that will allow its drawing objects to be drawn in that sub window. To make the indicator always use a sub window you can set IsOverlay=false as well.



                Make sure that you remove and reapply the indicator after making these changes. If you make changes to SetDefaults and just hit f5 to reload you won't see those changes happen, you physically need to re apply the script for those type of changes.


                JesseNinjaTrader Customer Service

                Comment


                  #9
                  okay I get it now. i need both
                  IsOverlay=false;

                  DrawOnPricePanel=false;​

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by warreng86, 11-10-2020, 02:04 PM
                  4 responses
                  1,355 views
                  0 likes
                  Last Post mathewlo  
                  Started by Perr0Grande, Today, 08:16 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Perr0Grande  
                  Started by elderan, Today, 08:03 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post elderan
                  by elderan
                   
                  Started by algospoke, Today, 06:40 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post algospoke  
                  Started by maybeimnotrader, Today, 05:46 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post maybeimnotrader  
                  Working...
                  X