Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time histogram for tic, volume or range charts

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

    Time histogram for tic, volume or range charts

    I was hoping someone could transfer this eSignal code to Ninja.
    It appears simple.
    It looks like a volume histogram on a time chart but shows a histogram of the time it takes for a bar to complete. Zero to 60 seconds is one color, 60 to 120 seconds is another color, 120 to 180 seconds is yet another color and so on.
    The code could be edited to any time intervals you wanted to use based on the size of charts you use.
    Its a nice visual indicator to have when using tic, volume or range bars

    Thanks

    /************************************************** *******
    Opstock © September 2005
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/
    function preMain() {
    setPriceStudy(false);
    setStudyTitle("Time Histogram for T&V charts")
    setShowCursorLabel(true);
    setDefaultBarFgColor(Color.magenta,0);
    setDefaultBarThickness(5,0);
    setPlotType(PLOTTYPE_HISTOGRAM);
    setStudyMax(300);
    //addBand(120, PS_SOLID, 1, Color.aqua);
    }
    function main() {
    var TimeDiff = rawtime(0)-rawtime(-1);

    if(TimeDiff > 0 && TimeDiff <= 60) {
    setBar(Bar.FgColor, -1, Color.green);
    }
    if(TimeDiff > 60 && TimeDiff <= 120) {
    setBar(Bar.FgColor, -1, Color.lime);
    }
    if(TimeDiff > 120 && TimeDiff <= 180) {
    setBar(Bar.FgColor, -1, Color.yellow);
    }
    if(TimeDiff > 180 && TimeDiff <= 240) {
    setBar(Bar.FgColor, -1, Color.RGB(255,128,0));
    }
    if(TimeDiff > 240 && TimeDiff <= 300) {
    setBar(Bar.FgColor, -1, Color.red);
    }

    //return TimeDiff;

    setBar(Bar.Value, -1, TimeDiff);
    return null;

    }
    Attached Files

    #2
    If you'd find nobody from the community contributing you still could contact any of the certified NinjaScript consultants: http://www.ninjatrader.com/webnew/pa...injaScript.htm

    Comment


      #3
      Here you go!

      I noticed that particularly on weekends you may get a bar that dwarfs the other bars in the histogram. If that happens set the color to Transparent which not only hides the bar but also resets the scale.

      To import:

      - Download the file contained in this thread to your desktop
      - From the Control Center window select the menu File > Utilities > Import NinjaScript
      - Select the downloaded file
      Attached Files

      Comment


        #4
        Thanks Gumphrie....I appreciate your time...your the best.

        dwalls

        Comment


          #5
          Is anyone else having a problem with this indicator not being ploted in the new (v. 8) beta (no errors are reported in the log and the indicator worked perfectly before i updated form v. 6 to v. 8)?

          Also many thanks to Gumphrie for coding this useful indicator.
          Last edited by samiam30; 01-26-2008, 02:50 PM.

          Comment


            #6
            Time Histogram Alert Sound

            Hello,
            I'm now trying to add an Alert Sound to this Time Histogram.
            I would like an Alert Sound if the time does not exceed boundary1.
            Example: If boundary1 is set to 60 and the time histogram bar closes at 52 (or any number less than 60) play an Alert Sound.
            I tried this but not compiling:

            if ((TimeHistogram(Close,boundary1)[0])< boundary1[0]){
            PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\pop.wav");
            }

            error messages:
            Indicator\TimeHistogramAlertTest.cs No overload for method 'TimeHistogram' takes '2' arguments CS1501 - click for info

            Indicator\TimeHistogramAlertTest.cs Cannot apply indexing with [] to an expression of type 'int' CS0021 - click for info

            Any ideas?

            Thanks

            Comment


              #7
              Hi dwalls,

              Thanks for your post.

              The 'Time Histogram' takes 5 boundary inputs and has no input series one. Please take a look at this snippet below and modify your code accordingly;

              Code:
              [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] myBoundary = [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000];[/COLOR]
              [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((TimeHistogram(boundary1, boundary2, boundary3, boundary4, boundary5)[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < myBoundary))
              PlaySound([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]@"C:\Program Files\NinjaTrader 6.5\sounds\pop.wav"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
              [/SIZE][/FONT][/SIZE][/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE]
              Of course you will need to define the myBoundary, boundary1, boundary2, boundary3, boundary4, boundary5 variables in the Variables() section of your code.
              Last edited by NinjaTrader_Bertrand; 11-12-2008, 04:51 PM.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thanks for your response.
                It wound let me compile when using the "<" in the code. It seems to make sense to use it but it wont compile.
                if ((TimeHistogram(boundary1, boundary2, boundary3, boundary4, boundary5) < myBoundary))

                error message:
                Indicator\TimeHistogramAlertTest.cs Operator '<' cannot be applied to operands of type 'NinjaTrader.Indicator.TimeHistogram' and 'int' CS0019 - click for info

                I usually have to use the Rising/Falling or CrossBelow/CrossAbove too get these things to work. It never lets me use the "<" or ">".

                Any help would be great.

                Thanks

                PS. I have the myBoundary, boundary1, boundary2, boundary3, boundary4, boundary5 variables (each as private int) in the Variables() section of your code and also as Parameters in the Properties Section.

                Comment


                  #9
                  sorry...should read...It wouldn't let me compile when using the "<" in the code.

                  Comment


                    #10
                    Hi dwalls,

                    Unfortunately my previous snippet was incorrect, please try this -

                    Code:
                    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] myBoundary = [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]60[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2];
                    [/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] ((TimeHistogram(boundary1, boundary2, boundary3, boundary4, boundary5)[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]] < myBoundary))
                    PlaySound([/SIZE][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]@"C:\Program Files\NinjaTrader 6.5\sounds\pop.wav"[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]);[/SIZE][/SIZE]
                    [SIZE=2][SIZE=2][/SIZE][/SIZE]
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Hi NinjaTrader Bertrand,
                      Thanks for your help on this.
                      I got it to compile but the sound alert wont play.
                      I must have something wrong in the "Initialize" or with the "double".
                      I have the "double" in "Intialized "and in"On Bar Update". I dont know if thats right.
                      Could you please take a look and see if theres anything wrong and why the alert sound wont play?

                      Thanks
                      Attached Files

                      Comment


                        #12
                        Hi dwalls,

                        Thanks for your post.

                        Please use this code snipped in your code -

                        Code:
                        [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (closeBelowmyBoundaryAlertSound)[/SIZE]
                        [SIZE=2]{[/SIZE]
                        [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] (timeGap < myBoundary)[/SIZE]
                        [SIZE=2]{ [/SIZE]
                        [SIZE=2]PlaySound([/SIZE][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav"[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]);[/SIZE]
                        [SIZE=2]}[/SIZE]
                        [SIZE=2]} [/SIZE]
                        [/SIZE]
                        1. You can use timeGap directly in your code, there's no need to call the complete TimeHistogram as a function for you.

                        2. Make sure you point the PlaySound() to a valid .wav file, I changed it to the Alert4.wav provided by us and it works fine.


                        Last edited by NinjaTrader_Bertrand; 11-13-2008, 10:17 AM.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Great.
                          I got it to work now.
                          Thanks for your help.

                          Comment


                            #14
                            You are welcome - great it works now!!
                            BertrandNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by TheMarlin801, 10-13-2020, 01:40 AM
                            21 responses
                            3,915 views
                            0 likes
                            Last Post Bidder
                            by Bidder
                             
                            Started by timmbbo, 07-05-2023, 10:21 PM
                            3 responses
                            151 views
                            0 likes
                            Last Post grayfrog  
                            Started by Lumbeezl, 01-11-2022, 06:50 PM
                            30 responses
                            808 views
                            1 like
                            Last Post grayfrog  
                            Started by xiinteractive, 04-09-2024, 08:08 AM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by Johnny Santiago, 10-11-2019, 09:21 AM
                            95 responses
                            6,194 views
                            0 likes
                            Last Post xiinteractive  
                            Working...
                            X