Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TickRange

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

    #16
    OK, another code snippet.
    I tried to do it in OnBarUpdate.
    Works well only for DrawHorizontalLine(). DrawLine draws nothing.
    Code:
    #region Variables
            // Wizard generated variables
                private int barsBack = 5; // Default setting for BarsBack
                private int barsForw = 0; // Default setting for BarsForw
            // User defined variables (add any user defined variables below)
                private double nextOpenHigh = 0;
                private double nextOpenLow = 0;
            
                private bool isRangeDerivate = false;
                private bool rangeDerivateChecked = false;
            #endregion
    Code:
            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;
    
                // Cenu open zjistime jako low + hodnota RB v ticich + 1 tick navic nebo analogicky pro high
                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;
                    
                // THIS DOESN'T WORK AT ALL, BUT IS DESIRED TO. I need only short line near last bar, not across all display
    //            DrawLine("highOpen",barsBack,nextOpenHigh,barsForw,nextOpenHigh,Color.Green,DashStyle.Solid,1);
    //            DrawLine("lowOpen",barsBack,nextOpenLow,barsForw,nextOpenLow,Color.Red,DashStyle.Dash,1);
                //THIS WORKS WELL, BUT DRAW LINE ACROSS ALL DISPLAY.
                DrawHorizontalLine("highOpen",nextOpenHigh,Color.Green,DashStyle.Dot,1);
                DrawHorizontalLine("lowOpen",nextOpenLow,Color.Red,DashStyle.Dash,1);
            }
    Any idea?
    Thanks a lot.

    Comment


      #17
      Lucinek,

      It doesn't work because of this: http://www.ninjatrader-support.com/v...ead.php?t=3170

      You need to add an if (CurrentBar < ____) condition based on how many bars back you are trying to draw.

      Please see your Control Center logs tab for errors.
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Hi, thanks a lot, it was the reason. I didn't know, that it is necessary, when chart is full of bars O:-)
        Now it's working well. But - is any way how to draw line forward? Minimum value for endBarsAgo is 0, but i want to draw e.g. 5 bars forward actual price .... is it possible?

        Comment


          #19
          Unfortunately you cannot draw lines forward.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Thank you a lot for your assistance.
            The last problem, i hope. I'd like to write actual price level over/below these two lines. But this code also doesn't work and I have no clue why.
            Any idea?

            Code:
            #region Variables
            private int barsBack = 10; // Default setting for BarsBack
            private int shiftPrice = 0; // Default setting for ShiftPrice
             private double nextOpenHigh = 0;
            private double nextOpenLow = 0;
            private string strHO;
            private string strLO;
            #endregion
            Code:
            protected override void OnBarUpdate()
            {
               if (CurrentBar < barsBack) return;
               if(Close[0] != High[0] && Close[0] != Low[0]) return;
            
                        nextOpenHigh = Low[0] + (Bars.Period.Value * Bars.Instrument.MasterInstrument.TickSize) +  ((shiftPrice+1) * Bars.Instrument.MasterInstrument.TickSize);
                        nextOpenLow = High[0] - (Bars.Period.Value * Bars.Instrument.MasterInstrument.TickSize) - ((shiftPrice+1) * Bars.Instrument.MasterInstrument.TickSize);
            
                        strHO = "HO: " + nextOpenHigh;
                        strLO = "LO: " + nextOpenLow;
                        if(barsBack > 0)
                        {
            // DrawLine works well, DrawText is not working at all ... 
                            DrawLine("highOpen",barsBack,nextOpenHigh,0,nextOpenHigh,Color.Green,DashStyle.Dot,2);
                            DrawText("highOpenValue",strHO,0,nextOpenHigh,Color.Green);
                            DrawLine("lowOpen",barsBack,nextOpenLow,0,nextOpenLow,Color.Red,DashStyle.Dot,2);
                            DrawText("lowOpenValue",strLO,0,nextOpenLow,Color.Red);
                        }
                        else 
                        {
            // DrawHorizontalLine works well, DrawText is not working at all ... 
                            DrawHorizontalLine("highOpen",nextOpenHigh,Color.Green,DashStyle.Dot,2);
                            DrawText("highOpenValue",strHO,0,nextOpenHigh+(10* Bars.Instrument.MasterInstrument.TickSize),Color.Green);
                            DrawHorizontalLine("lowOpen",nextOpenLow,Color.Red,DashStyle.Dot,2);
                            DrawText("lowOpenValue",strLO,0,nextOpenLow-(10* Bars.Instrument.MasterInstrument.TickSize),Color.Red);
                        }
            
            }

            Comment


              #21
              Check your Control Center logs for errors. Remember if you do not use unique names for your draw objects they will be continually modified if your conditions evaluate to true later on in the chart. That means your objects will be moved.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              579 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X