Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator that shows Duration of Volume Bar

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

    Indicator that shows Duration of Volume Bar

    Hello

    I'm using Volume Bars and in order to know their "Duration", ie the time the bar takes from open to close, I developed this code snippet:

    TimeSpan time1 = Time[0] - new DateTime(1970,1,1,0,0,0);
    TimeSpan time2 = Time[2] - new DateTime(1970,1,1,0,0,0);
    int diff=(int)time1.TotalSeconds-(int)time2.TotalSeconds;

    if(diff > X)
    {
    Duration = true;
    }
    else
    {
    Duration = false;
    }

    This works well when integrated into my custom strategy but now I'd like to make a standalone indicator out if it that displays the "Duration" in minutes/seconds in the main chart window (panel 1). I'd very much appreciate it if someone could show me how it's done as I'm struggling with the process.

    Thanks a lot.

    #2
    laocoon, it seems to me like what you seek to do would be using DrawTextFixed to 'print' the current diff on the chart?

    Comment


      #3
      Bertrand, thanks for your reply. This is indeed what I'm trying to do, but I'm having some difficulty with the right syntax. What I've got so far is:

      DrawTextFixed("IndicatorValues", "diff:" + int diff=(int)time1.TotalSeconds-(int)time2.TotalSeconds, TextPosition.TopLeft);

      For some reason I'm getting error messages.

      Thanks

      Comment


        #4
        Best is if you do not do your calcs in the DrawTextFixed() method call but only use the diff variable containing the info you wish to show, the text parameter would be expected string, so you can convert the int diff to a string with diff.ToString()

        Comment


          #5
          Thanks Bertrand, now it works. Is there a specific formatting for minutes and seconds? (I had a look at the tutorial but minutes/seconds weren't mentioned)

          Thanks

          Comment


            #6
            There are some custom string formatting options available laocoon - http://www.ninjatrader.com/support/f...ead.php?t=3823

            Comment


              #7
              I was looking through these and although there's no example with minutes and seconds, I managed to format it the way I wanted.
              One last question: I'm using the whole

              DrawTextFixed(string tag, string text, TextPosition textPosition, Color textColor, Font font, Color outlineColor, Color areaColor, int areaOpacity)

              expression, but I'm having difficulties with the "Font" part. For example, Font.Arial generates an error message. I've looked around on the forum, but there's no example of how to use the Font command correctly. Could you please help me out here?

              Thanks again.
              Last edited by laocoon; 04-04-2011, 10:54 AM.

              Comment


                #8
                laocoon, pleae try

                Code:
                new Font("Arial", 10)
                as parameter for example, would that compile for you then?

                Comment


                  #9
                  Great, it works. Thanks a lot for your help Bertrand. Have a nice evening.

                  Comment


                    #10
                    Hi Laocoon, I've just read this post and this is exactly what I'm looking for. Would you be so kind to share the indicator with me?

                    Originally posted by laocoon View Post
                    Great, it works. Thanks a lot for your help Bertrand. Have a nice evening.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    574 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    333 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
                    553 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