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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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.
          Kate W.NinjaTrader Customer Service

          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.
              Kate W.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by pmachiraju, 11-01-2023, 04:46 AM
              8 responses
              148 views
              0 likes
              Last Post rehmans
              by rehmans
               
              Started by mattbsea, Today, 05:44 PM
              0 responses
              5 views
              0 likes
              Last Post mattbsea  
              Started by RideMe, 04-07-2024, 04:54 PM
              6 responses
              33 views
              0 likes
              Last Post RideMe
              by RideMe
               
              Started by tkaboris, Today, 05:13 PM
              0 responses
              5 views
              0 likes
              Last Post tkaboris  
              Started by GussJ, 03-04-2020, 03:11 PM
              16 responses
              3,283 views
              0 likes
              Last Post Leafcutter  
              Working...
              X