Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Vertical Line

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

    Draw Vertical Line

    Hi Everyone

    I am starting with strategies and I cannot plot nothing

    protected override void OnBarUpdate()
    {

    DrawVerticalLine("tag1",DateTime.Now, Color.Black,DashStyle.Solid,2);

    What I am doing wrong?

    Thanks for your answers in advice

    #2
    Hello PauetValencia,

    Thank you for your post.

    The issue is that you're trying to use DateTime.Now for the Time when that may be different from the bar Time.

    This should plot a vertical line on the most recently closed bar if run using Calculate On Each Tick = false or on the currently forming bar if run On Each Tick:

    protected override void OnBarUpdate()
    {
    DrawVerticalLine("tag1",Time[0], Color.Black,DashStyle.Solid,2);
    DrawTextFixed("myText", "DateTime.Now = " + DateTime.Now + " | Time[0]: " + Time[0], TextPosition.BottomRight);
    }

    It will also print the current values for DateTime.Now and Time[0] so you can see where those may differ.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thanks Kate for you answer,

      I put the code and in the chart area not show nothing. I put also a log to see if execute each BarUpdate and the log is ok but not draw nothing.

      What could be the problem?

      Thanks

      Comment


        #4
        Hello PauetValencia,

        Thank you for your reply.

        Could you provide your current code for the indicator? This should execute in either real time or historical, so I want to see if something's amiss in your code.

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Hello PauetValencia,

          Just wanted to check in to see if you had a chance to provide your current code or if you've resolved your inquiry. Can you confirm?

          Thanks in advance; I look forward to assisting you further.

          Comment


            #6
            Hi Kate,

            It is my code:

            protected override void Initialize()
            {
            CalculateOnBarClose = true;


            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            Log("Ejecutamos OnBarUpdate en Niveles Volumen" + Time[0] , LogLevel.Information);
            DrawTextFixed("uno","hola",TextPosition.BottomLeft );
            DrawVerticalLine("tag1",Time[0], Color.Black,DashStyle.Solid,2);
            DrawTextFixed("myText", "DateTime.Now = " + DateTime.Now + " | Time[0]: " + Time[0], TextPosition.BottomRight);

            // Condition set 1
            if (VOL()[0] >= Nivel_1)
            {
            PrintWithTimeStamp("Valor > 500");
            Log("Alcanzan los 500", LogLevel.Information);
            }

            // Condition set 2
            if (VOL()[0] >= Nivel_2)
            {
            DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.DarkOrchid);
            }

            // Condition set 3
            if (VOL()[0] >= Nivel_3)
            {
            DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Orange);
            }
            }

            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public int Nivel_1
            {
            get { return nivel_1; }
            set { nivel_1 = Math.Max(1, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int Nivel_2
            {
            get { return nivel_2; }
            set { nivel_2 = Math.Max(1, value); }
            }

            [Description("")]
            [GridCategory("Parameters")]
            public int Nivel_3
            {
            get { return nivel_3; }
            set { nivel_3 = Math.Max(1, value); }
            }
            #endregion
            }

            Comment


              #7
              Hello PauetValencia,

              Thank you for your reply. The following works for me:

              Code:
                  public class TestPauet : Indicator
                  {
                      #region Variables
                      private int nivel_1 = 500;
                      private int nivel_2 = 1000;
                      private int nivel_3 = 2000;
                      #endregion
              
                  protected override void Initialize()
                  {
                      CalculateOnBarClose = true;
                      Overlay = true;
                  }
              
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                       Log("Ejecutamos OnBarUpdate en Niveles Volumen" + Time[0] ,
              LogLevel.Information);
                      DrawTextFixed("uno","hola",TextPosition.BottomLeft);
                      DrawVerticalLine("tag1",Time[0],
              Color.Black,DashStyle.Solid,2);
                      DrawTextFixed("myText", "DateTime.Now = " + DateTime.Now + " |Time[0]: " + Time[0], TextPosition.BottomRight);
              
                      // Condition set 1
                      if (VOL()[0] >= Nivel_1)
                      {
                          Print("Valor > 500 :" + Time[0]);
                          Log("Alcanzan los 500", LogLevel.Information);
                      }
              
                      // Condition set 2
                      if (VOL()[0] >= Nivel_2)
                      {
                          DrawVerticalLine("My vertical line" + CurrentBar, 0,
              Color.DarkOrchid);
                      }
              
                      // Condition set 3
                      if (VOL()[0] >= Nivel_3)
                      {
                          DrawVerticalLine("My vertical line" + CurrentBar, 0,
              Color.Orange);
                      }
                  }
              
                  #region Properties
                  [Description("")]
                  [GridCategory("Parameters")]
                  public int Nivel_1
                  {
                      get { return nivel_1; }
                      set { nivel_1 = Math.Max(1, value); }
                  }
              
                  [Description("")]
                  [GridCategory("Parameters")]
                  public int Nivel_2
                  {
                      get { return nivel_2; }
                      set { nivel_2 = Math.Max(1, value); }
                  }
              
                  [Description("")]
                  [GridCategory("Parameters")]
                  public int Nivel_3
                  {
                      get { return nivel_3; }
                      set { nivel_3 = Math.Max(1, value); }
                  }
                  #endregion
                  }
              I think your issue may have been the PrintWithTimeStamp("Valor > 500"); line - there is not a PrintWithTimeStamp() method in NinjaTrader. You would have to specify the timestamp within the print.

              Please let us know if we may be of further assistance to you.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              563 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              329 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
              547 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              548 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X