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

zOrder, Putting Indicators behind Price.

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

    #16
    Have seen system indicators that set ZOrder to -1; so there is a range of values that ZOrder can take. Can I set it to -2?

    Do you think it is possible to save Zorder settings with chart templates as well? Finally it is a property of the chart and not of the workspace?

    Comment


      #17
      Yes, but negative values would just mean to put it behind price...I believe for chart templates it's expected not to save ZOrder, as then you easily run into conflicts of ordering and priorities...
      BertrandNinjaTrader Customer Service

      Comment


        #18
        Thanks Bertrand, that will do.

        Comment


          #19
          Thanks a lot guys, for the ZOrder hint. I wished since a long time that NT implements the possibility to paint graphics behind the chart-bars programmatically. But it is there already, not documented, but used by some of the system indicators.

          Regards
          Ralph

          Comment


            #20
            DrawArrowDown behind plot

            Guys, is there a way to draw an arrow behind a plot within the same indicator?

            As far as I can tell the arrow is always on top, regardless of the order in which the arrow and plot are drawn, and regardless of applying the "SeparateZOrder=true" command to the arrow.

            Thanks for the help,

            Light

            Comment


              #21
              Light, works for me here for the IDrawObjects the arrows offer as well - setting SeparateZOrder to true just offers defining the ZOrder for the draw object to be separate, you would then to change it via Shift and the mousewheel as those objects are drawn on the chart by the indicator.
              BertrandNinjaTrader Customer Service

              Comment


                #22
                Not yet working for me...

                Thanks Bertrand. I hope you're doing well.

                I am trying to get an arrow and a plotted line to both be over the chart bars, with the arrow behind the line (within the same indicator). I am using (essenially) the following code in attempt to accomplish this:

                Code:
                 
                private IDrawObject Arrow;
                 
                //Plot some line, then under some condition do...
                 
                Arrow=DrawArrowUp("Arw"+(CurrentBar-1).ToString(),true,1,Value[1],Color.Lime); 
                Arrow.SeparateZOrder=true;
                I can highlight an arrow and set its ZOrder. But doing so also sets the ZOrder of the accompanying line, so that either both are over the chart bars or both are behind them. The attached image shows both behind them.

                Is there a way to get the arrows behind the line with the line and arrows above the bars? (Actually, I haven't been able to get the arrow behind the line at all -- even if both are behind the bars.)

                Thanks again for your help.

                Light
                Attached Files

                Comment


                  #23
                  Light, could you please share the complete code you use, if I have an SMA in the indicator and an Arrow for example on the SMA and then I assign a seprate ZOrder to the Arrow, I get 3 ZOrder levels and could also set them as needed manually.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #24
                    Slightly modified WMA code...

                    Thanks Bertrand. This is the code I used to produce the image in my previous post. It modifies NT's WMA only by adding lines 19 and 47-51 to plot Arrows at changes in slope. (I also added a shiftArrow variable to manually draw the arrows in the same region as the WMA for demonstration, but it has no other role.) Here is the full code:

                    Code:
                     
                    #region Using declarations
                    using System;
                    using System.Diagnostics;
                    using System.Drawing;
                    using System.Drawing.Drawing2D;
                    using System.ComponentModel;
                    using System.Xml.Serialization;
                    using NinjaTrader.Data;
                    using NinjaTrader.Gui.Chart;
                    #endregion
                    namespace NinjaTrader.Indicator
                    {
                    public class WMAwithArrows : NinjaTrader.Indicator.Indicator
                    {
                    #region Variables
                     
                    //Relevant part next line:
                    private IDrawObject Arrow;
                    private int period = 14;
                    private double arrowShift = 0.5;
                    #endregion
                    protected override void Initialize()
                    {
                    Add(new Plot(Color.Orange, Name));
                    Overlay = true;
                    }
                    protected override void OnBarUpdate()
                    {
                    if (CurrentBar == 0)
                    Value.Set(Input[0]);
                    else
                    {
                    int back = Math.Min(Period - 1, CurrentBar);
                    double val = 0;
                    int weight = 0;
                    for (int idx = back; idx >=0; idx--)
                    {
                    val += (idx + 1) * Input[back - idx];
                    weight += (idx + 1);
                    }
                    Value.Set(val / weight);
                     
                    //Relevant part in next few lines:
                    if (CurrentBar>5) {
                    if (Value[1]<Value[2] && Value[1]<Value[0]) 
                    {Arrow=DrawArrowUp("Arw"+(CurrentBar-1).ToString(),true,1,Value[1]+ArrowShift*TickSize,Color.Lime); Arrow.SeparateZOrder=true;} else
                    if (Value[1]>Value[2] && Value[1]>Value[0]) 
                    {Arrow=DrawArrowDown("Arw"+(CurrentBar-1).ToString(),true,1,Value[1]-ArrowShift*TickSize,Color.Red); 
                    Arrow.SeparateZOrder=true;}
                    }
                    }
                    }
                    #region Properties
                    [Description("Numbers of bars used for calculations")]
                    [GridCategory("Parameters")]
                    public int Period
                    {
                    get { return period; }
                    set { period = Math.Max(1, value); }
                    }
                     
                    [Description("Arrow Shift")]
                    [GridCategory("Parameters")]
                    public double ArrowShift
                    {
                    get { return arrowShift; }
                    set { arrowShift = value; }
                    }
                    #endregion
                    }
                    }
                    I have tried various permutations, but I am still seeing only two levels of ZOrder, one is the chart bars and one is the WMA and the Arrows together. I must be missing something...

                    Thanks again for the help.

                    Best wishes,

                    Light

                    Comment


                      #25
                      Light, please try two separate IDraw objects for each arrow used. Right now they share one.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #26
                        Thanks Bertrand. I tried that earlier by removing one of the arrows entirely, but had the same result. I have since tried it again, this time by inserting "UArrow" and "DArrow" as separate IDrawObject variables, with corresponding changes to the DrawArrowUP and DrawArrowDown section. But I still have only two levels of ZOrder, with no independent control of the arrows compared to the WMA line. Full code here:

                        Code:
                         
                        #region Using declarations
                        using System;
                        using System.Diagnostics;
                        using System.Drawing;
                        using System.Drawing.Drawing2D;
                        using System.ComponentModel;
                        using System.Xml.Serialization;
                        using NinjaTrader.Data;
                        using NinjaTrader.Gui.Chart;
                        #endregion
                        namespace NinjaTrader.Indicator
                        {
                        public class WMAwithArrows : NinjaTrader.Indicator.Indicator
                        {
                        #region Variables
                        private IDrawObject DArrow;
                        private IDrawObject UArrow;
                        private int period = 14;
                        private double arrowShift = 0.5;
                        #endregion
                        protected override void Initialize()
                        {
                        Add(new Plot(Color.Orange, Name));
                        Overlay = true;
                        }
                        protected override void OnBarUpdate()
                        {
                        if (CurrentBar == 0)
                        Value.Set(Input[0]);
                        else
                        {
                        int back = Math.Min(Period - 1, CurrentBar);
                        double val = 0;
                        int weight = 0;
                        for (int idx = back; idx >=0; idx--)
                        {
                        val += (idx + 1) * Input[back - idx];
                        weight += (idx + 1);
                        }
                        Value.Set(val / weight);
                        if (CurrentBar>5) {
                        if (Value[1]<Value[2] && Value[1]<Value[0]) 
                        {UArrow=DrawArrowUp("UArw"+(CurrentBar-1).ToString(),true,1,Value[1]+ArrowShift*TickSize,Color.Lime); UArrow.SeparateZOrder=true;} else
                        if (Value[1]>Value[2] && Value[1]>Value[0]) 
                        {DArrow=DrawArrowDown("DArw"+(CurrentBar-1).ToString(),true,1,Value[1]-ArrowShift*TickSize,Color.Red); DArrow.SeparateZOrder=true;}
                        }
                        }
                        }
                        #region Properties
                        [Description("Numbers of bars used for calculations")]
                        [GridCategory("Parameters")]
                        public int Period
                        {
                        get { return period; }
                        set { period = Math.Max(1, value); }
                        }
                         
                        [Description("Arrow Shift")]
                        [GridCategory("Parameters")]
                        public double ArrowShift
                        {
                        get { return arrowShift; }
                        set { arrowShift = value; }
                        }
                        #endregion
                        }
                        }

                        Are you able to produce a Plot line (e.g. a moving average) with arrows that appear beneath the line (assuming corresponding choice of ZOrder) within one indicator? If so, could you post your code?

                        Thanks again for your help.

                        Light

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Christopher_R, Today, 12:29 AM
                        0 responses
                        9 views
                        0 likes
                        Last Post Christopher_R  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        166 responses
                        2,235 views
                        0 likes
                        Last Post sidlercom80  
                        Started by thread, Yesterday, 11:58 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post thread
                        by thread
                         
                        Started by jclose, Yesterday, 09:37 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post jclose
                        by jclose
                         
                        Started by WeyldFalcon, 08-07-2020, 06:13 AM
                        10 responses
                        1,415 views
                        0 likes
                        Last Post Traderontheroad  
                        Working...
                        X