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

TickRange

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

    TickRange

    Hello,
    I'm trying to use the modified RangeValue indicator to show a current high to low value (computeonclose=false). After the bar closes and if it's a certain value (i.e. less than 7 ticks) I want to plot a vertical line at that position.

    Please help with the additional item(s) I need to add to the code. Up to now, I'm waiting for bar close or re-applying the indicators...

    Thanks in Advance,

    Kirk
    Attached Files

    #2
    Hi Kirk,

    If you want your indicator to run on bar close you will want to use CalculateOnBarClose = true.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      CalculateOnBarClose

      Josh,

      Yes, I think I understand that for printing the vertical line but I also want the current bar tick range in the right indicator value flag window to give me an up to the moment value for the tickrange.

      Does that make sense? or do I create a second indicator for this?

      Kirk

      Comment


        #4
        Hi Kirk,

        What you want is possible within one indicator. To do this you will want to segregate your OnBarUpdate() method into having one section that calculates every tick and another that just calculates once per bar.

        In the Initialize() method please use CalculateOnBarClose = false. To segregate your OnBarUpdate() you can do this:
        Code:
        if (FirstTickOfBar)
        {
             // add what you want to do here;
        }
        Anything outside of this condition will run every tick and anything inside this if-statement will run only once at the start of a new bar. The start of a new bar is the same event as the close of the previous bar. Since you want to draw on the bar that just closed and you will need to tweak all your [] indexing one back. So for instance, if you had Value[0] you will want to change that to Value[1]. Also for your DrawLine() logic, you will want to plot it one bar back too.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thx

          Great, Josh,

          Thanks,

          kz

          Comment


            #6
            Hi Josh,

            Not having much luck getting output...
            Initialize has
            Code:
             
            CalculateOnBarClose = false;

            Here's the snippet...

            Code:
             
            protectedoverridevoid OnBarUpdate()
            { 
            if (FirstTickOfBar)
            {
            Value.Set(High[0] - Low[0]);
            if (Value[1] <= 10*TickSize) 
            { 
            DrawLine("10Ticksorless", false,1, High[1] + 100 * TickSize, 1, Low[1] - 100 * TickSize, Color.Blue,DashStyle.Dash,2);
            }
            elseif (Value[1] <= 7*TickSize) 
            { 
            DrawLine("7Ticksorless", false,1, High[1] + 100 * TickSize, 1, Low[1] - 100 * TickSize, Color.Red,DashStyle.Dash,2);
            }
            }
             
            Value.Set(High[0] - Low[0]);
             
            }

            Anything simple pop out? Do I need to create a unique instance of Value for the one outside the if statement?
            Thanks for your help.
            Kirk

            Comment


              #7
              In indicators you need to watch out for this: http://www.ninjatrader-support.com/v...ead.php?t=3170
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Got It Now

                Thanks for pointing me the right direction Josh!
                kz

                Comment


                  #9
                  Hello,
                  I created very similar indicator, I call it RangeNextOpen.
                  It works that way, that i count next open price on RangeBar chart to short and to long and should increase or decrease this values by "Displacement" property value.
                  It means, that on RB9 chart actual price is e.g. on value 600.0, high of this candleis on 600.1 and low is on 599.5. So my indicator write on chart window, that next open price to long is 600.4 and open to short is 599.2. If Displacement is 1, next long open will be 600.5 and short open 599.1.
                  It works very well, but i need new feature - i need to draw horizontal lines on level of NextLongOpen and NextShortOpen price, because watching text with prices is too slow in this volatile days.
                  Any idea how to do this ... ?
                  I wrote some code snippets based on DrawLine, but didn't work at all ...

                  Comment


                    #10
                    DrawLine() or DrawHorizontalLine() should work for you. Please post up the code that did not work and any errors involved with that code.

                    The idea is you just want to draw a line at whatever price point you wanted. You can decide how many bars back you want this line to extend to.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      OK, I will show code.
                      When no DrawLine function is in Plot method, everything is OK. When DrawLine present, neither line, nor price appeared. I don't know, where problem should be.
                      Original source code is RangeCounter indicator, which I just modified ...
                      Thanx for your reply ...
                      Lucinek

                      Code:
                              #region Variables
                              // Wizard generated variables
                              // User defined variables (add any user defined variables below)
                              private bool            isRangeDerivate        = false;
                              private bool            rangeDerivateChecked= false;
                              private StringFormat    stringFormat        = new StringFormat();
                              private SolidBrush        textBrush            = new SolidBrush(Color.Black);
                              private Font            textFont            = new Font("Arial", 40, System.Drawing.FontStyle.Bold);
                              private float            textWidth            = 0;
                              private float            textHeight            = 0;
                              private string            noRangeMessage        = "Range Counter only works on Range bars.";
                              private float            noRangeTextWidth    = 0;
                              private float            noRangeTextHeight    = 0;
                              private double nextOpenHigh = 0;
                              private double nextOpenLow = 0;
                              
                              #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()
                              {
                                  CalculateOnBarClose    = false;
                                  Overlay                = true;
                                  ChartOnly            = true;
                                  PriceTypeSupported    = false;
                              }
                      
                              /// <summary>
                              /// Called on each bar update event (incoming tick)
                              /// </summary>
                              protected override void OnBarUpdate()
                              {
                                  if (false == rangeDerivateChecked)
                                  {
                                      if (ChartControl == null || ChartControl.Bars == null || ChartControl.Bars.Length == 0)
                                          return;
                                      if (Data.BarsType.GetInstance(ChartControl.Bars[0].Period.Id).BuiltFrom == Data.PeriodType.Tick && ChartControl.Bars[0].Period.ToString().IndexOf("Range") >= 0)
                                          isRangeDerivate = true;
                                      rangeDerivateChecked = true;
                                  }
                                  if(false == isRangeDerivate) return;
                              }
                              public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
                              {
                                  if (Bars == null)return;
                      
                                  // Recalculate the proper string size should the chart control object font and axis color change
                                  if (textBrush.Color != ChartControl.AxisColor || textFont != ChartControl.Font)
                                  {
                                      textBrush.Color = ChartControl.AxisColor;
                                      textFont = ChartControl.Font;
                      
                                      SizeF size = graphics.MeasureString("OpenLong = %"  + High[0] + "\r\nOpenShort = %"  + High[0] + "\r\nCountDown = %" + Bars.Period.Value, textFont);
                                      textWidth        = size.Width + 40;
                                      textHeight        = size.Height + 5;
                      
                                      SizeF noTickSize = graphics.MeasureString(noRangeMessage, textFont);
                                      noRangeTextWidth = noTickSize.Width + 5;
                                      noRangeTextHeight = noTickSize.Height + 5;
                                  }
                      
                                  // Plot the range count message to the lower right hand corner of the chart
                                  if (Bars.Period.Id == PeriodType.Range || isRangeDerivate)
                                  {
                                      // Open price is: low + RB scale (in ticks) + 1 extra tick, the same for high open
                                      nextOpenHigh = Low[0] + (Bars.Period.Value * Bars.Instrument.MasterInstrument.TickSize) +  ((Displacement+1) * Bars.Instrument.MasterInstrument.TickSize);
                                      nextOpenLow = High[0] - (Bars.Period.Value * Bars.Instrument.MasterInstrument.TickSize) - ((Displacement+1) * Bars.Instrument.MasterInstrument.TickSize);
                                      int    actualRange    = (int) Math.Round(Math.Max(Close[0] - Low[0], High[0] - Close[0]) / Bars.Instrument.MasterInstrument.TickSize);
                                      int    rangeCount    = Bars.Period.Value - actualRange;
                                      
                                      graphics.DrawString("OpenLong = "  + nextOpenHigh + "\r\nOpenShort = "  + nextOpenLow + "\r\nCountDown = " + rangeCount,
                                          ChartControl.Font, textBrush, bounds.X + bounds.Width - textWidth, bounds.Y + bounds.Height - textHeight, stringFormat);
                      //HERE IS PROBLEM, THIS DOESN'T WORK AT ALL:                DrawLine("highOpen",0,nextOpenHigh,-2,nextOpenHigh,Color.Red,DashStyle.Solid,1);
                                      DrawLine("lowOpen",0,nextOpenLow,-2,nextOpenLow,Color.Red,DashStyle.Solid,1);
                                  }
                                  else
                                      graphics.DrawString(noRangeMessage, ChartControl.Font, textBrush, bounds.X + bounds.Width - noRangeTextWidth, bounds.Y + bounds.Height - noRangeTextHeight, stringFormat);
                              }

                      Comment


                        #12
                        Hi Lucinek,

                        The Plot() method is not supported. The DrawLine() method as well as all other draw objects are for the OnBarUpdate() method. If you are trying to use custom plotting you will need to do it via C#. Unfortunately we cannot assist you in that case.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          I just used existing indicator RangeCounter and modified code. I also tryied to put DrawLine into OnBarUpdate, but with the same result. Of course, I dont know, if the original code is not too complicated for my purpose ... ?

                          Comment


                            #14
                            In fact, I don't know difference between Plot and OnBarUpdate method at all

                            Comment


                              #15
                              Plot() method is not supported and we cannot provide any assistance in using it. Please review the Help Guide article for how to use DrawLine(). http://www.ninjatrader-support.com/H.../DrawLine.html

                              Remember if you are trying to draw 10 bars back you will need to have at least 10 bars of data before such a call. Please see this tip on this issue: http://www.ninjatrader-support.com/v...ead.php?t=3170
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kaywai, 09-01-2023, 08:44 PM
                              5 responses
                              601 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              6 responses
                              22 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Pattontje, Yesterday, 02:10 PM
                              2 responses
                              17 views
                              0 likes
                              Last Post Pattontje  
                              Started by flybuzz, 04-21-2024, 04:07 PM
                              17 responses
                              230 views
                              0 likes
                              Last Post TradingLoss  
                              Started by agclub, 04-21-2024, 08:57 PM
                              3 responses
                              17 views
                              0 likes
                              Last Post TradingLoss  
                              Working...
                              X