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 a dot every 60 seconds

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

    Draw a dot every 60 seconds

    Hey guys,

    I want to make a simple indicator that just draws a dot every 60 seconds, I use P&F charts and as they aren't time-based, I want to draw a dot on the chart every 60 seconds, maybe even some data like how much it has moved + or - in since the last dot.

    Can someone help me?

    Cheers!

    #2
    Hello Jumper,

    Thank you for your post.

    You can check the time stamp of the bar and compare it to the previous, although this may not always produce a dot exactly on 60 seconds. You could alternatively use DateTime.Now which would pull the system time, but this would also only work on the bar update.

    An example would be:
    Code:
    			if(prevTime != null && Time[0] >= prevTime.AddSeconds(60))
    			{
    				// Do something
    			}
    			prevTime = Time[0];
    Please let me know if you have any questions.

    Comment


      #3
      Thanks for the help, so you're saying that it's not going to display my dot exactly on the 60 second mark but on the bar that it occurred in when it finishes printing?

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello Jumper,


        An example would be:
        Code:
        			if(prevTime != null && Time[0] >= prevTime.AddSeconds(60))
        			{
        				// Do something
        			}
        			prevTime = Time[0];
        Please let me know if you have any questions.
        It's saying there is an error, "the name prevTime does not exist in the current context" ? I copied that code into the OnBarUpdate section, that's correct yes? Now it should just be that code then Dot0.Set where you have "Do Something" ?

        Comment


          #5
          Originally posted by Jumper View Post
          It's saying there is an error, "the name prevTime does not exist in the current context" ? I copied that code into the OnBarUpdate section, that's correct yes? Now it should just be that code then Dot0.Set where you have "Do Something" ?
          That is telling you to declare prevTime. In this particular case, as it is to survive the update process, you will need to declare it as a class variable.

          Comment


            #6
            Hello Jumper,

            Thank you for your response.

            Koganam is correct, the prevTime would need to be defined as a variable in your code.

            Due to the OnBarUpdate() method only being called when a tick is received or bar is closed the code we process in this method only occurs on each tick or bar close.

            Comment


              #7
              Ok so it needs to be "public class prevTime()" under the variables section? With what in the body of the class?

              Thanks for the replies btw

              Comment


                #8
                Jumper,

                In your variables section you would need to use a DateTime identifier

                private DateTime prevTime;
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Ok thanks Cal. Got it to compile, but it seems incorrect, I'm getting dots everywhere, doesn't seem to be every 60 seconds. This is what I have:

                  namespace NinjaTrader.Indicator
                  {
                  /// <summary>
                  /// Displays a dot every 60 seconds
                  /// </summary>
                  [Description("Displays a dot every 60 seconds")]
                  public class OneMinuteDot : Indicator
                  {
                  #region Variables
                  // Wizard generated variables
                  private int myDot = 60; // Default setting for MyDot
                  // User defined variables (add any user defined variables below)
                  #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()
                  {

                  Add(new Plot(Color.FromKnownColor(KnownColor.Orchid), PlotStyle.Dot, "Dot0"));
                  Overlay = true;

                  }
                  private DateTime prevTime;

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.

                  if(prevTime != null && Time[0] >= prevTime.AddSeconds(60))
                  {
                  Dot0.Set(Close[0]);
                  }
                  prevTime = Time[0];

                  }

                  #region Properties
                  [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                  [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                  public DataSeries Dot0
                  {
                  get { return Values[0]; }
                  }

                  [Description("Amount of seconds between dot being displayed")]
                  [GridCategory("Parameters")]
                  public int MyDot
                  {
                  get { return myDot; }
                  set { myDot = Math.Max(1, value); }
                  }
                  #endregion
                  }
                  }

                  Comment


                    #10
                    Hello Jumper,

                    Thank you for your response.

                    private DateTime prevTime; needs to be listed in the variables:
                    Code:
                    region Variables
                    // Wizard generated variables
                    private int myDot = 60; // Default setting for MyDot
                    [B]private DateTime prevTime;[/B]
                    // User defined variables (add any user defined variables below)
                    #endregion
                    After making this correction if you still see dots everywhere please send me a screenshot of your chart and ensure I can see the settings for the Point and Figure period type.

                    Comment


                      #11
                      Here are the screenshots of what you are after, there seems to be dots at the wrong times, like more than 60 seconds apart, also is there a way to make them bigger? They are tiny!
                      Attached Files

                      Comment


                        #12
                        Hello Jumper,

                        Thank you for your response.

                        This is my mistake as the prevTime should only be set after a dot is drawn:
                        Code:
                        			if(Time[0] >= prevTime.AddSeconds(60))
                        			{
                        				Dot0.Set(Close[0]);
                        				prevTime = Time[0];
                        			}
                        For the width of the dot you can use the following code in the Initialize() method (F.Y.I. the 20 width is going to be huge on chart, so you will likely want to change this to the desired width):
                        Code:
                                protected override void Initialize()
                                {
                        			Pen myPen = new Pen(Color.FromKnownColor(KnownColor.Orchid), 20);
                        			Add(new Plot(myPen, PlotStyle.Dot, "Dot0"));
                        			Overlay	= true;
                                }
                        Please let me know if you have any questions.

                        Comment


                          #13
                          Excellent thank you, working perfectly now and have set it up so the time in seconds is adjustable :-)

                          Now onto my next project, I want to create a bar histogram(like volume) that shows how long the current column(P&F) took to form? So like a BarTime, but one that counts how long it took to form, rather than counting down(obviously as P&F isn't time based).

                          How can I get started on that?

                          Thanks Patrick! Very helpful, much appreciated

                          Comment


                            #14
                            Nevermind, managed to find exactly what I mean here http://www.freeindicators.com/ninjat...eed-indicator/

                            Comment


                              #15
                              Ok onto my next project...

                              I want to have a line drawn every XX ticks, above and below the open of every bar....and multiple ones, not just one line above and below, so the bar opens at X okay, so I want a bar drawn automatically on the open of the bar XX ticks(whatever the user sets) above and below that open price, and then the same amount of ticks above that line all the same distance apart.

                              Like so, so it automatically draws the lines above and below X amount of ticks at the open of every bar/candle.

                              How do I do this? I assume there's a drawLine method? It's the how to get it to do it automatically at the open of every bar that I need to figure out.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              9 responses
                              36 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              23 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              9 responses
                              50 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by George21, Today, 10:07 AM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by Stanfillirenfro, Today, 07:23 AM
                              9 responses
                              24 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X